从 avi 到 mp4 的 FFMpeg 转换对于 safari 和 IE 浏览器的视频不成功

FFMpeg conversions from avi to mp4 does not succeed with video for safari and IE browsers

下面的 ffmpeg 命令确实成功地为 chrome 浏览器将 avi 文件转换为 mp4 文件,但是对于诸如 safari 和 IE(我还没有用其他浏览器测试过。)我看不到视频,只能听到音频 这仅仅意味着 safari 和 IE 浏览器不接受将视频从 avi 文件转换为 mp4 文件。

for i in /xxxxxx/xxxxxxx/xxxxxxx/*.avi; do ffmpeg -i "$i" -pix_fmt yuvj422p "/xxxxxx/xxxxxxx/xxxxxxx/$(basename "$i" .avi).mp4"; done    

顺便说一下,当我尝试使用相同的 ffmpeg 命令从 flv 文件转换为 mp4 时,视频和音频都已成功转换为 chrome、safari 和 IE。(我还没有与其他人一起测试过。 )

avi文件是我用相机拍的,flv文件是我从网上下载的。

谁能帮帮我?

下面的日志文件是ffmpeg命令从avi转mp4的。(avi文件是我用相机拍的)

[root@server-xxxxxxx-x ~]# for i in /xxxxxx/xxxxxxx/xxxxxxx/09190100_5ba1211c6905e.avi;  do ffmpeg -i "$i" -pix_fmt yuvj422p "/xxxxxx/xxxxxxx/xxxxxxx/$(basename "$i" .avi).mp4"; done
ffmpeg version N-46948-g776cdd1dc8-static https://johnvansickle.com/ffmpeg/  Copyright  (c) 2000-2018 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --  disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 -- enable-libxml2 --enable-libxvid --enable-libzimg
  libavutil      56. 19.101 / 56. 19.101
  libavcodec     58. 30.100 / 58. 30.100
  libavformat    58. 18.100 / 58. 18.100
  libavdevice    58.  4.103 / 58.  4.103
  libavfilter     7. 31.100 /  7. 31.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
  Guessed Channel Layout for Input Stream #0.1 : mono
  Input #0, avi, from '/xxxxxx/xxxxxxx/xxxxxxx/09190100_5ba1211c6905e.avi':
   Metadata:
    creation_time   : 2018-09-14 00:18:07
    encoder         : CanonMVI06
    Duration: 00:00:04.20, start: 0.000000, bitrate: 12999 kb/s
     Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p(pc,   bt470bg/unknown/unknown), 640x480, 12384 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
      Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
  Stream mapping:
   Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
   Stream #0:1 -> #0:1 (pcm_s16le (native) -> aac (native))
  Press [q] to stop, [?] for help
  [libx264 @ 0x66f7c40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2   AVX2
  [libx264 @ 0x66f7c40] profile High 4:2:2, level 3.0, 4:2:2, 8-bit
  [libx264 @ 0x66f7c40] 264 - core 157 r2932 303c484 - H.264/MPEG-4 AVC codec - Copyleft     2003-2018 - 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=3    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=25 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 '/xxxxxx/xxxxxxx/xxxxxxx/09190100_5ba1211c6905e.mp4':
   Metadata:
     encoder         : Lavf58.18.100
     Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuvj422p(pc), 640x480, q=-1- -1, 30 fps, 1000k tbn, 30 tbc
     Metadata:
       encoder         : Lavc58.30.100 libx264
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
      Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s
      Metadata:
        encoder         : Lavc58.30.100 aac
  frame=  126 fps= 42 q=-1.0 Lsize=     243kB time=00:00:04.20 bitrate= 474.3kbits/s    speed= 1.4x
video:203kB audio:35kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead:    2.440238%
[libx264 @ 0x66f7c40] frame I:1     Avg QP:24.22  size: 16730
[libx264 @ 0x66f7c40] frame P:32    Avg QP:24.48  size:  4020
[libx264 @ 0x66f7c40] frame B:93    Avg QP:25.83  size:   662
[libx264 @ 0x66f7c40] consecutive B-frames:  1.6%  0.0%  0.0% 98.4%
[libx264 @ 0x66f7c40] mb I  I16..4: 11.2% 86.4%  2.4%
[libx264 @ 0x66f7c40] mb P  I16..4:  1.0%  0.8%  0.0%  P16..4: 54.9%  7.1%  6.3%  0.0%     0.0%    skip:29.8%
[libx264 @ 0x66f7c40] mb B  I16..4:  0.1%  0.1%  0.0%  B16..8: 26.0%  0.2%  0.0%  direct:     1.1%  skip:72.5%  L0:47.1% L1:52.0% BI: 1.0%
[libx264 @ 0x66f7c40] 8x8 transform intra:68.3% inter:88.6%
[libx264 @ 0x66f7c40] coded y,uvDC,uvAC intra: 51.1% 78.4% 10.4% inter: 4.8% 24.4% 0.1%
[libx264 @ 0x66f7c40] i16 v,h,dc,p: 17% 26%  5% 52%
[libx264 @ 0x66f7c40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 32% 22%  3%  4%  2%  6%  5%  5%
[libx264 @ 0x66f7c40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 31% 25% 12%  1% 12%  3% 10%  4%  2%
[libx264 @ 0x66f7c40] i8c dc,h,v,p: 48% 23% 25%  4%
[libx264 @ 0x66f7c40] Weighted P-Frames: Y:3.1% UV:3.1%
[libx264 @ 0x66f7c40] ref P L0: 45.3%  9.1% 32.9% 12.4%  0.3%
[libx264 @ 0x66f7c40] ref B L0: 74.7% 20.7%  4.7%
[libx264 @ 0x66f7c40] ref B L1: 88.4% 11.6%
[libx264 @ 0x66f7c40] kb/s:394.12

-pix_fmt yuvj422p 更改为 -pix_fmt yuv420p,这是唯一广泛支持的像素格式。

与问题中的问题无关,但还要添加 -movflags +faststart,因为看起来您提供的视频是渐进式下载。

使用这个,希望它会起作用。

   $cmd = ' -i '.$inputFile.' -c:v libx264 -crf 19 '.$outputFile;
   exec('ffmpeg '.$cmd, $out, $ret);