Php specifies a frame for video capturing as an image ,. Php specifies a video frame as an image and a video frame as an image. the phpffmpeg extension has been perfectly implemented: $ movienewffmpeg_movie ($ video_filePath ); $ ff_frame $ movie-getFrame (1. specify the video captured by php as an image,
Specify a frame as an image for video capturing. 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 with the meta information rotate due to different shooting directions. when you intercept a frame image from a video, if a video with rotate information is rotated, the frame must be rotated accordingly.
The php ffmpeg extension does not know the rotation information (php ffmpeg extension document), but can be obtained through the ffmpeg command line:
/Usr/local/ffmpeg/bin/ffprobe test.mp4-show_streams | grep rotate
Php is encapsulated 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 is another annoyance. not all players and browsers can recognize orientation and automatically rotate video. if you want to rotate the video, you can use the ffmpeg command to solve the problem:
/Usr/local/ffmpeg/bin/ffmpeg-I input.mp4-vf 'transpose = 3'-metadata: s: v: 0 rotate = 0
The above is all the content of this article. I hope it will help you learn php programming.
Specifies the frame to be captured as an image. php ffmpeg extension has been perfectly implemented: $ movie = new ffmpeg_movie ($ video_filePath); $ ff_frame = $ movie-getFrame (1...