Ffmpeg 转换后的视频(超过 30 秒)无法在 chrome 中播放

Ffmpeg converted videos (longer than 30s) not playing in chrome

正如标题所说,我在处理 30 多岁以上的转换视频时遇到问题。它们不在 chrome 中播放,但在所有其他浏览器中都可以使用。问题是,如果视频少于 30 秒,它在 chrome 中也能正常播放。

输入文件是 mpeg4 编码的,我正在尝试使用 h264 编解码器对其进行转换。转换是在 linux 服务器上借助 drupal 模块完成的,该模块会自动转换上传的视频。

这是命令和输出:

/opt/ffmpeg/ffmpeg -i '/var/www/html/website/videos/original/2016-02-02-16-52-44-758_1.mp4' -strict experimental -vcodec 'libx264' -pix_fmt 'yuv420p' -vprofile 'baseline' -an -pass '1' -passlogfile '/tmp/1454496233-56b1d9e99deb8-multipass'  -y /tmp/1454496233-56b1d9e99dd6f.mp4
ffmpeg version N-61041-g52a2138 Copyright (c) 2000-2014 the FFmpeg developers
  built on Mar  2 2014 05:45:04 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/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. 66.100 / 52. 66.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  2.100 /  4.  2.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 18.100 /  0. 18.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/html/website/videos/original/2016-02-02-16-52-44-758_1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf56.40.101
  Duration: 00:00:54.42, start: 0.000000, bitrate: 840 kb/s
    Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 839 kb/s, 24 fps, 24 tbr, 12288 tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
[libx264 @ 0x38799c0] using SAR=1/1
[libx264 @ 0x38799c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
[libx264 @ 0x38799c0] profile Constrained Baseline, level 3.1
[libx264 @ 0x38799c0] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=1:0:0 analyse=0x1:0 me=dia subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=24 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 '/tmp/1454496233-56b1d9e99dd6f.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf55.33.100
    Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, pass 1, 12288 tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 -> libx264)
Press [q] to stop, [?] for help
frame=  129 fps=0.0 q=28.0 size=     298kB time=00:00:03.41 bitrate= 715.2kbits/s    
frame=  268 fps=267 q=28.0 size=     784kB time=00:00:09.20 bitrate= 697.3kbits/s    
frame=  409 fps=271 q=28.0 size=    1313kB time=00:00:15.08 bitrate= 712.9kbits/s    
frame=  547 fps=272 q=28.0 size=    1744kB time=00:00:20.83 bitrate= 685.8kbits/s    
frame=  687 fps=274 q=28.0 size=    2275kB time=00:00:26.66 bitrate= 699.0kbits/s    
frame=  827 fps=275 q=28.0 size=    2754kB time=00:00:32.50 bitrate= 694.1kbits/s    
frame=  967 fps=275 q=28.0 size=    3273kB time=00:00:38.33 bitrate= 699.4kbits/s    
frame= 1106 fps=275 q=28.0 size=    3826kB time=00:00:44.12 bitrate= 710.2kbits/s    
frame= 1245 fps=276 q=28.0 size=    4366kB time=00:00:49.91 bitrate= 716.6kbits/s    
frame= 1306 fps=268 q=-1.0 Lsize=    4762kB time=00:00:54.41 bitrate= 716.8kbits/s
video:4756kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead 0.125035%
[libx264 @ 0x38799c0] frame I:6     Avg QP:17.10  size: 43459
[libx264 @ 0x38799c0] frame P:1300  Avg QP:20.34  size:  3545
[libx264 @ 0x38799c0] mb I  I16..4: 31.1%  0.0% 68.9%
[libx264 @ 0x38799c0] mb P  I16..4:  3.7%  0.0%  0.0%  P16..4: 14.8%  0.0%  0.0%  0.0%  0.0%    skip:81.5%
[libx264 @ 0x38799c0] coded y,uvDC,uvAC intra: 29.2% 62.3% 14.8% inter: 3.4% 5.8% 0.4%
[libx264 @ 0x38799c0] i16 v,h,dc,p: 58% 22% 17%  2%
[libx264 @ 0x38799c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 59% 24%  8%  1%  1%  1%  2%  1%  2%
[libx264 @ 0x38799c0] i8c dc,h,v,p: 36% 14% 47%  3%
[libx264 @ 0x38799c0] kb/s:715.83

我也试过最新版本的ffmpeg,但我遇到了同样的问题。 有人知道为什么会这样吗?

请注意,这是通过 two-pass 编码生成的日志(这是从 drupal 获取日志的唯一方法)。如果我在 ffmpeg 命令中指定比特率,two-pass 编码就可以工作,但正如我所说,它不适用于 chrome 但适用于所有其他浏览器。

解决方案是在 drupal 的 UI.

中添加 qt-faststart 作为辅助程序

转到 Configuration>Media>Video,展开 Helper Programs 并将 qt-faststart 的路径放在那里。它应该在您的 ffmpeg 二进制文件夹中。