I have to check the video is landscape or portrait before rotate using ffmpge . please help me.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
using ffmpeg we cant check the video is taken landscape mode or portrite mode in iphone.
we need to install mediainfo or exiftool
if we install exiftool use the below commands
exec('exiftool path/to/filename/ | grep Rotation');
from this we can get the rotation of the videos
if rotation is 90° the videos taken in portraite mode in iphone
if rotation is 0° the videos taken in landscape mode in iphone
回答2:
Getting video dimension from ffmpeg -i
- Get info.
- Extract dimensions.
- If x < y, then portrait. Else landscape.
eg:
$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);
I don't know why you'd want to rotate the video from how it was shot, though. You're going to end up with sideways videos after rotating more likely than not.