This article is mainly for everyone in detail about the PHP interception video designated frame as a picture of the relevant information, the need for friends can refer to the next
Capture Video The specified frame is a picture, the PHP ffmpeg extension has been perfectly implemented:
$movie = new Ffmpeg_movie ($video _filepath), $ff _frame = $movie->getframe (1); $GD _image = $ff _frame->togdimage (); $ Img= "./test.jpg"; imagejpeg ($gd _image, $img); Imagedestroy ($gd _image);
However, the problem is that the video taken by the smartphone will be rotated because of the direction of the shooting, and with meta information rotate, when you capture a frame picture relative to the video, if there is a video of rotate information, the frame is rotated, so you need to rotate the captured image accordingly.
The PHP ffmpeg extension does not know rotation information (php ffmpeg extension documentation), but it can be obtained from the FFmpeg command line:
/usr/local/ffmpeg/bin/ffprobe test.mp4-show_streams | grep rotate in a simple package of PHP as follows:
function get_video_orientation ($video _path) { $cmd = "/usr/local/ffmpeg/bin/ffprobe". $video _path. "-show_streams 2>/dev/null"; $result = Shell_exec ($cmd); $orientation = 0; if (Strpos ($result, ' tag:rotate ')!== FALSE) { $result = explode ("\ n", $result); foreach ($result as $line) { if (Strpos ($line, ' tag:rotate ')!== FALSE) { $stream _info = explode ("=", $line); $orientation = $stream _info[1];}} } return $orientation;}
Use the Imagerotate () function to rotate:
$movie = new Ffmpeg_movie ($video _filepath), $frame = $movie->getframe (1); $gd = $frame->togdimage (); if ($ Orientation = $this->get_video_orientation ($video _filepath)) { $GD = imagerotate ($GD, 360-$orientation, 0);} $img = "./test.jpg"; imagejpeg ($GD, $img); Imagedestroy ($gd _image);
Finally, there's a problem, not all players and browsers can recognize the orientation and automatically rotate, if you want to rotate the video, can be resolved by FFmpeg command:
/usr/local/ffmpeg/bin/ffmpeg-i input.mp4-vf ' transpose=3 '-metadata:s:v:0 rotate=0
Summary: The above is the entire content of this article, I hope to be able to help you learn.