ffmpeg - 将特定(看似有效)GIF 转换为 mp4 时图像高度无效

标签 ffmpeg

我在互联网上遇到了一个 ffmpeg 似乎不喜欢的奇怪 GIF 文件。尝试运行以下命令:

curl http://images6.fanpop.com/image/photos/34300000/Klaus-The-Originals-klaus-34349255-120-113.gif > input.gif
ffmpeg -y -i input.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4

我使用 ffmpeg 版本 3.4.6 和 4.1.3 得到以下输出:
ffmpeg version 4.1.3-0ubuntu1 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8 (Ubuntu 8.3.0-6ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --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-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, gif, from 'a.gif':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: gif, bgra, 120x113, 5 fps, 5 tbr, 100 tbn, 100 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (gif (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x5613f5420c80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x5613f5420c80] profile High, level 1.0
[libx264 @ 0x5613f5420c80] 264 - core 155 r2917 0a84d98 - 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=5 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 'o.mp4':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 120x112, q=-1--1, 5 fps, 10240 tbn, 5 tbc
    Metadata:
      encoder         : Lavc58.35.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[gif @ 0x5613f540edc0] Invalid image height.
Error while decoding stream #0:0: Invalid data found when processing input
[mp4 @ 0x5613f541f380] Starting second pass: moving the moov atom to the beginning of the file
frame=    1 fps=0.0 q=23.0 Lsize=       3kB time=00:00:00.00 bitrate=253795.9kbits/s speed=0.0245x    
video:2kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 34.588745%
[libx264 @ 0x5613f5420c80] frame I:1     Avg QP:21.16  size:  1622
[libx264 @ 0x5613f5420c80] mb I  I16..4: 14.3% 42.9% 42.9%
[libx264 @ 0x5613f5420c80] 8x8 transform intra:42.9%
[libx264 @ 0x5613f5420c80] coded y,uvDC,uvAC intra: 67.9% 41.1% 33.9%
[libx264 @ 0x5613f5420c80] i16 v,h,dc,p: 25% 38% 25% 12%
[libx264 @ 0x5613f5420c80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  8% 58% 18%  2%  3%  3%  1%  4%  2%
[libx264 @ 0x5613f5420c80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 29% 15%  7%  7%  6%  5%  4%  3%
[libx264 @ 0x5613f5420c80] i8c dc,h,v,p: 77%  5% 16%  2%
[libx264 @ 0x5613f5420c80] kb/s:64.88
Conversion failed!

我是 ffmpeg 的新手,但据我了解,-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"缩放图像,使其高度和宽度为偶数(mp4 文件格式需要),这样应该可以防止发生这种错误?

这看起来与 this issue 非常相似在 trac.ffmpeg.org 上,显然已修复。

最佳答案

事实证明,即使它在不久前被修复,修复也只出现在版本 4.2 中。 .有几个选项可以安装更新的版本:使用 PPA,下载 ffmpeg ,或编译它。

购电协议(protocol)

在 Ubuntu 上安装 4.2 版 19.04 ,我关注了these steps :

sudo add-apt-repository ppa:savoury1/ffmpeg4
sudo add-apt-repository ppa:savoury1/graphics
sudo add-apt-repository ppa:savoury1/multimedia
sudo apt-get update
sudo apt-get install ffmpeg

现在它可以很好地处理 GIF。对于 Ubuntu 18.04 , this为我工作:
sudo add-apt-repository ppa:jonathonf/ffmpeg-4
sudo apt-get update
sudo apt-get install ffmpeg

下载一个编译好的ffmpeg

或者,您可以 download ffmpeg 已经编译好了。放入~/bin/usr/local/bin如果你想要它在你的PATH (more info on installation)。

编译 ffmpeg

或者您可以按照 compile ffmpeg on Ubuntu 的分步指南进行操作。 .

关于ffmpeg - 将特定(看似有效)GIF 转换为 mp4 时图像高度无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60033048/

相关文章:

c# - 如何设置 ffmpeg 管道输出?

json - 有没有办法用ffmpeg按章节批量拆分文件,然后在windows中用mkvmerge重新组装?

video - mp3 音频 + background.jpg = ffmpeg 中的 result.mp4

c#和ffpmeg命令行问题

java - 如何连接从 Java 中的 Kinesis Video Stream 获取的剪辑

FFmpeg drawtext的字体文件无法加载

python - 如何使用 FFmpeg 将 RTMP 流转换为视频文件?

ffmpeg - 使用 ffmpeg 加入多个 flv

android - ffmpeg 覆盖问题与旋转

linux - FFmpeg 自动同步音视频