截取视频指定帧为图片,php ffmpeg扩展已经完美实现:
$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);
/usr/local/ffmpeg/bin/ffprobe test.mp4 -show_streams | grep rotate
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;
}
$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);
/usr/local/ffmpeg/bin/ffmpeg -i input.mp4 -vf 'transpose=3' -metadata:s:v:0 rotate=0 -codec:v libx264 -strict -2 -y output.mp4