Convert .avi to .gif with ffmpeg with good quality AND subtitles

╄→尐↘猪︶ㄣ 提交于 2020-01-02 12:16:22

问题


I want to use ffmpeg to convert .avi to .gif with good quality and subtitles.

Now, I use this script to convert from .avi to .gif with good quality:

ffmpeg -v warning -ss 10:00 -t 5 -i input.avi -vf "fps=15,scale=420:-1:flags=lanczos,palettegen" -y palette.png
ffmpeg -v warning -ss 10:00 -t 5 -i input.avi -i palette.png -lavfi "fps=15,scale=420:-1:flags=lanczos [x]; [x][1:v] paletteuse" -y output.gif

I generate a palette and then using it to output the gif.

Then I am using this script to add subtitles to gif:

ffmpeg -v warning -i output.gif -vf "ass=subtitles.ass" -y outputWithSubs.gif

All that works just fine. The problem is that the first script gives me good quality without subtitles and the second gives me subtitles without good quality.

When I am trying to combine them with this script:

ffmpeg -v warning -ss 10:00 -t 5 -i input.avi -vf "fps=15,scale=420:-1:flags=lanczos,palettegen" -y palette.png
ffmpeg -v warning -ss 10:00 -t 5 -i input.avi -i palette.png -vf "ass=subtitles.ass" -lavfi "fps=15,scale=420:-1:flags=lanczos [x]; [x][1:v] paletteuse" -y output.gif

I am getting this error:

Filtergraph 'ass=subtitles.ass' was specified through the -vf/-af/-filter option for output stream 0:0, which is fed from a complex filtergraph. -vf/-af/-filter and -filter_complex cannot be used together for the same stream.

Is there any way that I could combine good quality and subtitles at the same time?


回答1:


Use -filter_complex, not -vf, and do all of your filtering in one filtergraph.

ffmpeg -y -ss 10:00 -t 5 -i input.avi -filter_complex "fps=15,scale=420:-1:flags=lanczos,ass=subtitles.ass,palettegen" palette.png

ffmpeg -y -ss 10:00 -t 5 -i input.avi -i palette.png -filter_complex "fps=15,scale=420:-1:flags=lanczos,ass=subtitles.ass[x];[x][1:v]paletteuse" output.gif


来源:https://stackoverflow.com/questions/34027422/convert-avi-to-gif-with-ffmpeg-with-good-quality-and-subtitles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!