在使用 ffmpeg 旋转之前,我必须检查视频是横向还是纵向。
请帮我。
最佳答案
Getting video dimension from ffmpeg -i
例如:
$output = shell_exec("ffmpeg -i $myvideo");
$out_arr = explode("\n", $output);
foreach($out_arr as $line) {
if( preg_match('/^Stream.*Video:/', trim($line)) ) {
// match line: Stream #0.0(und): Video: h264 (High), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 597 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc
$line_arr = explode(',', $line);
// get field: 640x360 [PAR 1:1 DAR 16:9]
$target_arr = explode(' ', $line_arr[2]);
// get parts: 640x360
$dims = explode('x', $target_arr[0]);
$res_x = $dims[0];
$res_y = $dims[1];
}
}
if( !( isset($res_x) && isset($res_y) ) ) {
die('Could not get dimensions');
} else {
$orientation = ($res_x < $res_y) ? 'Portrait' : 'Landscape';
printf('Resolution: %s x %s\nOrientation: %s\n', $res_x, $res_y, $oreintation);
不过,我不知道您为什么要旋转视频的拍摄方式。旋转后,您最终会看到横向视频。
关于php - 如何使用ffmpeg php检查视频是横向还是纵向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15298004/