转换H.264 AVI容器有关ffmpeg的MP4(convert h.264 avi contai

2019-08-19 02:17发布

我想我的H.264 AVI容器转换成MP4容器的ffmpeg。 我发现这工作:

./ffmpeg -i myfile.avi -vcodec copy myfile.mp4
ffmpeg version N-51169-gcedf276 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 21 2013 05:12:00 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/32bit --arch=x86_32 --extra-cflags='-m32 -I/root/ffmpeg-static/32bit/include -static' --extra-ldflags='-m32 -L/root/ffmpeg-static/32bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
  libavutil      52. 22.100 / 52. 22.100
  libavcodec     55.  1.100 / 55.  1.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 48.100 /  3. 48.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[avi @ 0x9fff660] non-interleaved AVI
Guessed Channel Layout for  Input Stream #0.1 : mono
Input #0, avi, from 'myfile.avi':
  Metadata:
    encoder         : Lavf52.64.2
  Duration: 00:00:10.40, start: 0.000000, bitrate: 409 kb/s
    Stream #0:0: Video: h264 (Baseline) (H264 / 0x34363248), yuvj420p, 640x480, 10 fps, 10 tbr, 10 tbn, 30 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
Output #0, mp4, to 'myfile.mp4':
  Metadata:
    encoder         : Lavf55.0.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 640x480, q=2-31, 10 fps, 10240 tbn, 10 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 8000 Hz, mono, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (pcm_s16le -> libvo_aacenc)
Press [q] to stop, [?] for help
[mp4 @ 0xa006ea0] pts has no value
    Last message repeated 100 times
frame=  101 fps=0.0 q=-1.0 Lsize=     350kB time=00:00:11.06 bitrate= 259.3kbits/s
video:332kB audio:15kB subtitle:0 global headers:0kB muxing overhead 0.926809%

这将生成一个文件,我可以用HTML5视频播放器中播放,但对于传统浏览器我想使用Flash播放器(的Flowplayer)。 该文件不具有的Flowplayer玩,其实它会导致它崩溃。

但是,如果我使用:

./ffmpeg -i myfile.avi myfile2.mp4
ffmpeg version N-51169-gcedf276 Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 21 2013 05:12:00 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/32bit --arch=x86_32 --extra-cflags='-m32 -I/root/ffmpeg-static/32bit/include -static' --extra-ldflags='-m32 -L/root/ffmpeg-static/32bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
  libavutil      52. 22.100 / 52. 22.100
  libavcodec     55.  1.100 / 55.  1.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    55.  0.100 / 55.  0.100
  libavfilter     3. 48.100 /  3. 48.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[avi @ 0x9b02660] non-interleaved AVI
Guessed Channel Layout for  Input Stream #0.1 : mono
Input #0, avi, from 'myfile.avi':
  Metadata:
    encoder         : Lavf52.64.2
  Duration: 00:00:10.40, start: 0.000000, bitrate: 409 kb/s
    Stream #0:0: Video: h264 (Baseline) (H264 / 0x34363248), yuvj420p, 640x480, 10 fps, 10 tbr, 10 tbn, 30 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
No pixel format specified, yuvj420p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x9b065a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64
[libx264 @ 0x9b065a0] profile High, level 2.2
[libx264 @ 0x9b065a0] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'myfile2.mp4':
  Metadata:
    encoder         : Lavf55.0.100
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 640x480, q=-1--1, 10240 tbn, 10 tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 8000 Hz, mono, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> libx264)
  Stream #0:1 -> #0:1 (pcm_s16le -> libvo_aacenc)
Press [q] to stop, [?] for help
frame=   47 fps=0.0 q=25.0 size=      21kB time=00:00:04.40 bitrate=  39.9kbits/s dup=3 dropframe=   59 fps= 56 q=25.0 size=      56kB time=00:00:05.68 bitrate=  80.2kbits/s dup=3 dropframe=   71 fps= 45 q=25.0 size=      89kB time=00:00:06.84 bitrate= 106.9kbits/s dup=3 dropframe=   83 fps= 40 q=25.0 size=     124kB time=00:00:08.12 bitrate= 124.9kbits/s dup=3 dropframe=   94 fps= 36 q=25.0 size=     157kB time=00:00:09.14 bitrate= 140.4kbits/s dup=4 dropframe=  105 fps= 23 q=25.0 Lsize=     309kB time=00:00:11.06 bitrate= 228.8kbits/s dup=4 drop=0
video:291kB audio:15kB subtitle:0 global headers:0kB muxing overhead 1.108651%
[libx264 @ 0x9b065a0] frame I:1     Avg QP:17.65  size: 12772
[libx264 @ 0x9b065a0] frame P:94    Avg QP:19.46  size:  2868
[libx264 @ 0x9b065a0] frame B:10    Avg QP:21.58  size:  1464
[libx264 @ 0x9b065a0] consecutive B-frames: 82.9% 13.3%  0.0%  3.8%
[libx264 @ 0x9b065a0] mb I  I16..4: 16.6% 66.3% 17.1%
[libx264 @ 0x9b065a0] mb P  I16..4:  4.2%  6.3%  0.5%  P16..4: 27.0%  9.5%  5.1%  0.0%  0.0%    skip:47.4%
[libx264 @ 0x9b065a0] mb B  I16..4:  0.8%  1.0%  0.0%  B16..8: 39.1%  4.6%  0.5%  direct: 2.4%  skip:51.7%  L0:39.8% L1:56.4% BI: 3.9%
[libx264 @ 0x9b065a0] 8x8 transform intra:58.0% inter:74.7%
[libx264 @ 0x9b065a0] coded y,uvDC,uvAC intra: 47.3% 0.0% 0.0% inter: 16.6% 0.0% 0.0%
[libx264 @ 0x9b065a0] i16 v,h,dc,p: 29% 19% 10% 42%
[libx264 @ 0x9b065a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 21% 29%  2%  3%  4%  4%  3%  3%
[libx264 @ 0x9b065a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 39% 28% 18%  2%  3%  3%  3%  2%  2%
[libx264 @ 0x9b065a0] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 0x9b065a0] Weighted P-Frames: Y:5.3% UV:0.0%
[libx264 @ 0x9b065a0] ref P L0: 67.9% 12.0% 12.6%  6.8%  0.6%
[libx264 @ 0x9b065a0] ref B L0: 76.9% 23.1%
[libx264 @ 0x9b065a0] ref B L1: 99.7%  0.3%
[libx264 @ 0x9b065a0] kb/s:226.31

这个伟大的工程。 但时间是完全不同的不提CPU周期。 第一个命令是在毫秒测量,而第二可能需要相当长的时间(〜5-40secs)。

有另一种方式我可以很快的AVI转换为MP4容器? 理想的情况下通过重新多路复用,而不是再编码。

编辑

我使用这个,现在我觉得这是最快的重新编码。 但我又不想这样做。 我只是想重新混流的代码。

ffmpeg -loglevel quiet -i myfile.avi -vcodec libx264 -profile:v baseline -preset ultrafast myfile.mp4

Answer 1:

我不会做不同的比你已经做了。 我试图REMUX在OS X 10.7的有关ffmpeg-1.2的文件:

ffmpeg --info
ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Apr  8 2013 02:39:03 with Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)

我想你的命令,并明确

ffmpeg -i myfile.avi -vcodec copy -acodec copy out.mp4

但是,我总是得到以下错误:

ffmpeg -i myfile.avi -vcodec copy -acodec copy out.mp4
ffmpeg version 1.2 Copyright (c) 2000-2013 the FFmpeg developers
  built on Apr  8 2013 02:39:03 with Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=cc --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[avi @ 0x7f9ef981ae00] non-interleaved AVI
Guessed Channel Layout for  Input Stream #0.1 : mono
Input #0, avi, from 'myfile.avi':
  Metadata:
    encoder         : Lavf52.64.2
  Duration: 00:00:10.40, start: 0.000000, bitrate: 409 kb/s
    Stream #0:0: Video: h264 (Baseline) (H264 / 0x34363248), yuvj420p, 640x480, 10 fps, 10 tbr, 10 tbn, 30 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
[mp4 @ 0x7f9ef991ac00] Tag [1][0][0][0]/0x00000001 incompatible with output codec id '65536' ([0][0][0][0])
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf52.64.2
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuvj420p, 640x480, q=2-31, 10 fps, 90k tbn, 10 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input

所以我做了错误编号的快速调研,发现了pcm_s16le不兼容MP4。 看到这个关于ffmpeg的跟踪bug报告 。

这可能与两者你的命令的解释不同的结果 - 虽然它的奇怪的是,它并没有屈服在你的情况下,错误(旧的ffmpeg快照?)。

所以我猜这个解决方案可能/是从一开始就提供了不同的音频编解码器或音轨转换成不同的编解码器。 作为一个快速测试我的尝试:

ffmpeg -i myfile.avi -vcodec copy -acodec mp2 out.mp4

输出文件被立即写入磁盘 - 没有任何错误都产生。 不幸的是,我没有验证功能的Flash Player结果的可能性。



文章来源: convert h.264 avi container to mp4 with ffmpeg
标签: ffmpeg