使用ffmpeg版本2.8

时间:2016-01-21 11:26:14

标签: ffmpeg

我曾经在ffmpeg 2.2工作到现在,并且正在检测从Android / iPhone手机上传的视频的旋转角度,并旋转生成的视频,使其在正确的角度上完美运行。

但是因为我已经将ffmpeg更新到2.8版本,所以我遇到了这个轮换问题。我的查询不会像之前那样轮播视频。

这里是我正在使用的命令:

检查旋转角度:

ffprobe -of json -show_streams {$input} | grep rotate

下面是我的最终命令,用于将视频转换为mp4

"ffmpeg -i {$input} -strict -2 -vcodec libx264 -preset slow -vb 500k -maxrate 500k -bufsize 1000k -vf 'scale=-1:480 ".fix_video_orientation($input)."' -threads 0 -ab 64k -s {$resolution}  -movflags faststart -metadata:s:v:0 rotate=0 {$output}";

" fix_video_orientation"功能如下。它可以检测初始视频的旋转角度,并输出旋转最终视频的最佳选项。

function fix_video_orientation($input){

$return= ", transpose=1 ";

$dd= exec("ffprobe -of json -show_streams  {$input}   | grep rotate");

if(!empty($dd)){

$dd=explode(":",$dd);
$rotate=str_replace(",","",str_replace('"',"",$dd[1]));

if($rotate=="90")return $return;

else if ($rotate=="180") return ", transpose=2,transpose=2 ";

else if($rotate == "270") return ", transpose=2 ";
}

目前上面的脚本正在支持" flv"," avi"," mp4"," mkv"," mpg&# 34;," WMV"" ASF"" WEBM"" MOV"" 3GP"&# 34; 3GPP"扩展,脚本也支持生成的.mp4文件,以便在所有浏览器和设备上播放。

现在ffprobe命令没有返回旋转角度,因此如果从iphone上传的肖像视频在网站上显示为横向。

ffprobe命令的输出控制台:

ffprobe version N-77455-g4707497 Copyright (c) 2007-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
libavutil 55. 11.100 / 55. 11.100
libavcodec 57. 20.100 / 57. 20.100
libavformat 57. 20.100 / 57. 20.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 21.101 / 6. 21.101
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/standard/PORTRAIT.m4v':
Metadata:
major_brand : qt

minor_version : 0
compatible_brands: qt

creation_time : 2016-02-03 05:25:18
com.apple.quicktime.make: Apple
com.apple.quicktime.model: iPhone 4S
com.apple.quicktime.software: 9.2.1
com.apple.quicktime.creationdate: 2016-02-03T10:52:11+0530
Duration: 00:00:03.34, start: 0.000000, bitrate: 7910 kb/s
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default)
Metadata:
creation_time : 2016-02-03 05:25:18
handler_name : Core Media Data Handler
Stream #0:1(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x1280 [SAR 1:1 DAR 9:16], 7832 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 50 tbc (default)
Metadata:
creation_time : 2016-02-03 05:25:18
handler_name : Core Media Data Handler
encoder : H.264
Stream #0:2(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2016-02-03 05:25:18
handler_name : Core Media Data Handler
Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
Metadata:
creation_time : 2016-02-03 05:25:18
handler_name : Core Media Data Handler
Unsupported codec with id 0 for input stream 2
Unsupported codec with id 0 for input stream 3

如果使用最新版本的ffmpeg(2.8)自动旋转视频,请您建议我在最终命令中添加或删除哪个选项。

1 个答案:

答案 0 :(得分:0)

尝试在superuser.com上询问。

ffmpeg -i in.mp4 -c copy -metadata:s:v:0 rotate=0 -an out.mp4

来源: https://superuser.com/questions/1092951/how-to-delete-a-single-metadata-item-from-an-mp4-file