How can the orientation of a video be determined in PHP before creating a thumbnail?

To determine the orientation of a video in PHP before creating a thumbnail, you can use FFmpeg to extract the orientation information from the video file. FFmpeg is a powerful multimedia framework that can be used to analyze video files and extract metadata. By running FFmpeg commands in PHP, you can retrieve the orientation information and then use it to create the thumbnail accordingly.

<?php
// Run FFmpeg command to extract orientation information from video file
$videoFile = 'path/to/video.mp4';
$ffmpegCommand = "ffmpeg -i $videoFile -vf \"showinfo\" -f null - 2>&1";
exec($ffmpegCommand, $output);

// Parse the output to find the orientation information
$orientation = '';
foreach ($output as $line) {
    if (strpos($line, 'rotate') !== false) {
        $orientation = trim(str_replace('rotate', '', $line));
        break;
    }
}

// Use the orientation information to create the thumbnail accordingly
if ($orientation == '90' || $orientation == '270') {
    // Rotate thumbnail for vertical orientation
    // Add code to rotate thumbnail here
}

// Create thumbnail using GD or Imagick
// Add code to create thumbnail here
?>