将 gif 转换为 mp4 时,FFMpeg 因 LZW 解码失败/块标签无效而失败

将 gif 转换为 mp4 时,FFMpeg 因 LZW 解码失败/块标签无效而失败

我在用着FFmpeg将 gif 转换为 mp4 文件。在某些 gif 文件上我遇到了错误invalid block label。该程序似乎仍会输出一个正常的 mp4 文件,但我宁愿它一开始就不遇到错误。我发现我在此主题

user@mediaserver:/temp$ ffmpeg -i /temp/input.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" /temp/output.mp4
ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, gif, from '/temp/input.gif':
  Metadata:
    comment         : Created with ezgif.com video to GIF converter
  Duration: 00:00:01.28, start: 0.000000, bitrate: 207257 kb/s
  Stream #0:0: Video: gif, bgra, 600x1067 [SAR 64:64 DAR 600:1067], 25 fps, 25 tbr, 100 tbn, 100 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (gif (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x559776c48980] using SAR=1066/1067
[libx264 @ 0x559776c48980] using cpu capabilities: MMX2 SSE2Slow
[libx264 @ 0x559776c48980] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x559776c48980] 264 - core 163 r3060 5db6aa6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - 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=9 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 '/temp/output.mp4':
  Metadata:
    comment         : Created with ezgif.com video to GIF converter
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, progressive), 600x1066 [SAR 1066:1067 DAR 600:1067], q=2-31, 25 fps, 12800 tbn
    Metadata:
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[gif @ 0x559776c38f00] LZW decode failedB time=00:00:00.00 bitrate=N/A speed=   0x
[gif @ 0x559776c35b00] invalid block label
[mp4 @ 0x559776c47580] Starting second pass: moving the moov atom to the beginning of the file
frame=   32 fps=0.0 q=-1.0 Lsize=     370kB time=00:00:01.16 bitrate=2614.8kbits/s speed=1.38x
video:369kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.351198%
[libx264 @ 0x559776c48980] frame I:1     Avg QP:24.32  size: 38869
[libx264 @ 0x559776c48980] frame P:8     Avg QP:24.95  size: 17974
[libx264 @ 0x559776c48980] frame B:23    Avg QP:26.28  size:  8456
[libx264 @ 0x559776c48980] consecutive B-frames:  3.1%  0.0%  9.4% 87.5%
[libx264 @ 0x559776c48980] mb I  I16..4: 22.7% 63.6% 13.7%
[libx264 @ 0x559776c48980] mb P  I16..4:  4.6% 21.3%  1.6%  P16..4: 36.5% 12.6%  8.4%  0.0%  0.0%    skip:15.0%
[libx264 @ 0x559776c48980] mb B  I16..4:  0.5%  3.6%  0.1%  B16..8: 43.6%  6.9%  2.0%  direct: 3.6%  skip:39.7%  L0:46.6% L1:50.7% BI: 2.7%
[libx264 @ 0x559776c48980] 8x8 transform intra:76.0% inter:81.8%
[libx264 @ 0x559776c48980] coded y,uvDC,uvAC intra: 60.4% 39.6% 6.8% inter: 18.2% 10.9% 0.2%
[libx264 @ 0x559776c48980] i16 v,h,dc,p:  4% 16%  5% 75%
[libx264 @ 0x559776c48980] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 17% 31%  6%  8%  7%  9%  5%  5%
[libx264 @ 0x559776c48980] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 21% 21%  5%  8%  7%  9%  5%  5%
[libx264 @ 0x559776c48980] i8c dc,h,v,p: 61% 23% 12%  4%
[libx264 @ 0x559776c48980] Weighted P-Frames: Y:12.5% UV:0.0%
[libx264 @ 0x559776c48980] ref P L0: 54.5% 10.5% 21.0% 12.8%  1.2%
[libx264 @ 0x559776c48980] ref B L0: 85.2% 11.4%  3.5%
[libx264 @ 0x559776c48980] ref B L1: 94.8%  5.2%
[libx264 @ 0x559776c48980] kb/s:2357.26

无法将其转换为 gif,这很合理,因为日志中存在 LZW 解码失败错误。如果有人能告诉我如何修复此问题,我将不胜感激。

相关内容