安装ffmpeg
apt install ffmpeg -y
gif转mp4
ffmpeg -f gif -i ldh.gif ldh.mp4

故障:生成没报错,但mp4无法播放,体积也不正常

尝试编译安装最新版
sudo apt install -y yasm
axel -n 100 https://ffmpeg.org/releases/ffmpeg-6.0.1.tar.xz
tar -xf ffmpeg-6.0.1.tar.xz
cd ffmpeg-6.0.1/
./configure --prefix=/usr/local/
make -j16
sudo make install
新版本再转换一次
/usr/local/bin/ffmpeg -f gif -i ldh.gif ldh.mp4

文件体积变大了,但是windows下直接不识别,无法播放(之前不报错,但是没有播放出内容)

成功的版本(小gif还是失败)
采用新版本ffmpeg,且指定比特率为1mbps
/usr/local/bin/ffmpeg -i 2.gif -b:v 1M 2.new.mp4
成功识别

但是小gif失败了,仍然无法识别(感觉,gif尺寸太小了)


尝试放大gif尺寸(成功)
/usr/local/bin/ffmpeg -i ldh.gif**-b:v 1M -vf scale=640:-1** ldh.mp4
设置宽640,高度自动


成功转换gif总结
-
升级ffmpeg 到 6.0.1
-
设置比特率1M
-
对于小的gif,放大目标尺寸到宽度640
mp4转gif
这个指令比较简单,不用加其他参数,但是生成出来的gif尺寸巨大!
/usr/local/bin/ffmpeg -i ldh.mp4 ldh.new.gif

而且播放比较卡!
降低帧率
/usr/local/bin/ffmpeg -i ldh.mp4 -r 15 ldh.new.gif

继续压缩到最初的150x113 6.33fps

比原始的还小些。
原始的gif
新的同fps、体积gif
参考
Converting GIF to MP4 with FFmpeg: A Comprehensive Guide - FFmpeg API (ffmpeg-api.com)