ffmpeg - ffmpeg 使用调色板将 mp4 转换为 gif 会导致视频被截断
问题描述
我想用 ffmpeg ( ffmpeg version 2.8.15-0ubuntu0.16.04.1
) 使用调色板从我的 mp4 电影中生成一个 gif。如果我不使用调色板,一切正常:
$ ffmpeg -i in.mp4 -filter_complex "scale=160:-1" out.gif
...
frame= 2003 fps=251 q=-0.0 Lsize= 21172kB time=00:01:20.12 bitrate=2164.7kbits/s
video:21155kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.077667%
但是使用这样的调色板会导致Buffer queue overflow, dropping
消息和截断的视频
$ ffmpeg -i in.mp4 -filter_complex "[0:v] scale=160:-1, split [a][b];[a] palettegen [p];[b][p] paletteuse" out.gif
....
[Parsed_paletteuse_3 @ 0xc56de0] [framesync @ 0xd1af08] Buffer queue overflow, dropping.
Last message repeated 36 times
[Parsed_paletteuse_3 @ 0xc56de0] [framesync @ 0xd1af08] Buffer queue overflow, dropping.
Last message repeated 106 times
...
[Parsed_palettegen_2 @ 0xc56d40] 255(+1) colors generated out of 1347441 colors; ratio=0.000189
frame= 65 fps=5.4 q=-0.0 Lsize= 1036kB time=00:01:20.12 bitrate= 105.9kbits/s
video:1035kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.124664%
解决方案
同时,我想出了如何规避这种行为。我只需要在用于转换的流中包含一个 fifo,以便它等到生成调色板:
$ ffmpeg -i in.mp4 -filter_complex "[0:v] scale=160:-1 [r];[r] split [a][b];[b]fifo[bb]; [a] palettegen [p];[bb][p] paletteuse" out.gif
...
frame= 2003 fps=7.8 q=-0.0 Lsize= 804608kB time=00:01:20.12 bitrate=82268.4kbits/s
video:804591kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.002042%
推荐阅读
- arrays - Bulls and cows - c语言 - 比较数组
- apache-camel - Camel 事务处理的 JMS 组件不适用于聚合器
- ios - 在 UITextView 中点击 URL 时 iOS 应用程序崩溃
- session - 如何在 MobaXterm 中全局启用会话日志记录?
- jsp - 影响应用程序内部流程的 beforeunload 事件
- oracle - 无法创建包含枚举字段的表(Oracle 11g)
- c++ - BOOST_BUILD_PATH 目录
- java - 使用休眠搜索在 json 字段中搜索
- amazon-web-services - ECS 上下文中的 Docker 撰写作业无法获取 AWS 机密以从 DockerHub 检索图像
- python - 自定义挂钩的 Airflow 2.0.1/Python 3.7.9 ModuleNotFoundError