When creating a thumbnail from a video, first we have to check orientation of that video. For checking the orientation we need to install mediainfo package on our server. After installing mediainfo package we can check the orientation using this command:
$check_orientation = shell_exec("mediainfo $uploadfile | grep Rotation");
// In $uploadfile pass the location of video with video name.
print_r($check_orientation);
If $check_orientation is not null it will give following value depending on video's orientation:
Rotation : 90
Rotation : 180
Rotation : 270
If $check_orientation is null then orientation of video is correct. Depending on the rotation we can rotate our thumbnail which we will create from video using this command:
shell_exec("ffmpeg -i ".$uploadfile." -ss 00:00:1.999 -s 260x195 -f image2 -vframes 1 ".$dirPath_videoThumb.$only_name.".png &"); // Command for creating the thumbnail from video
shell_exec("mogrify -rotate 90 $videoThumbname"); //command for rotating the thumbnail without creating the copy.
shell_exec("mogrify -rotate 180 $videoThumbname");
shell_exec("mogrify -rotate 270 $videoThumbname");
Use these command depending on the output of $check_orientation. We can make cases using switch case for checking and then rotating the image accordingly.
0 Comment(s)