![如何使用 ffmpeg 将视频转换为带有文本叠加的 GIF](https://linux22.com/image/1543021/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20ffmpeg%20%E5%B0%86%E8%A7%86%E9%A2%91%E8%BD%AC%E6%8D%A2%E4%B8%BA%E5%B8%A6%E6%9C%89%E6%96%87%E6%9C%AC%E5%8F%A0%E5%8A%A0%E7%9A%84%20GIF.png)
我目前正在尝试修改此命令,它使用分裂使用 ffmpeg 命令制作 gif
ffmpeg -y -ss 30 -t 3 -i input.flv -filter_complex "fps=10,scale=320:-1:flags=lanczos[x];[x]split[x1][x2];[x1]palettegen[p];[x2][p]paletteuse" output.gif
这工作正常,问题是当我尝试使用golden ratio
ffmpeg -y -ss 30 -t 3 -i "input.mp4" -filter_complex "fps=10,scale=320:-1:flags=lanczos[x],drawtext=box=1:[email protected]:boxborderw=5:fontfile=font3.ttf:text='Stackoverflow':fontsize=24:fontcolor=white:x=(w-tw)/2:y=(h/PHI)+th[x];[x]split[x1][x2];[x1]palettegen[p];[x2][p]paletteuse" output.gif
现在我不确定是否需要在调色板中添加另一个变量?我正尝试一次性运行此操作
错误说
ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2016-01-21 04:12:34
Duration: 00:04:24.38, start: 0.000000, bitrate: 730 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], 632 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s (default)
Metadata:
creation_time : 2016-01-21 04:12:35
handler_name : IsoMedia File Produced by Google, 5-11-2011
Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_drawtext_2
答案1
按照前几个过滤器的顺序应用 drawtext。
ffmpeg -y -ss 30 -t 3 -i "input.mp4"
-filter_complex "fps=10,scale=320:-1:flags=lanczos,
drawtext=box=1:[email protected]:boxborderw=5:fontfile=font3.ttf:text='Stackoverflow':fontsize=24:fontcolor=white:x=(w-tw)/2:y=(h/PHI)+th,
split[x1][x2];[x1]palettegen[p];[x2][p]paletteuse" output.gif
答案2
为了以防万一,这个不错的工具提供了相同的功能以及一些额外的功能,并且还具有用户友好的 GUI:
https://github.com/lettier/gifcurry
在 Ubuntu 上安装很简单:
wget https://github.com/lettier/gifcurry/releases/download/6.0.0.0/gifcurry-6.0.0.0-x86_64.AppImag
chmod u+x gifcurry-6.0.0.0-x86_64.AppImage
./gifcurry-6.0.0.0-x86_64.AppImage
享受。