Convert .avi to .gif with ffmpeg with good quality

2019-05-23 12:26发布

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条回答
Lonely孤独者°
2楼-- · 2019-05-23 12:50

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
查看更多
登录 后发表回答