I want to create an animated gif in a QT project. When I scale the a QImage to AV_PIX_FMT_RGB8 directly the output looks awfull with flickering artifacts and when I scale to AV_PIX_FMT_YUV420P in between the output is dithered witch does not look much better.
I found out that ffmpeg is able to produce a palette file using a filter called palettegen and then convert a movie to gif using this palette.
Is there any sample c++ file out which I could use for my project or does anybody have a clue who to use these filters in code?
The filter can be describe like below
You can do some
fps
orscale
customization with the filter above.Then we should apply this filter graph in ffmpeg.
One important note is, as the filter
palettegen
need the entire stream, we need to add the whole stream to the buffer source, and a end of stream to buffer source, then we can get frame from buffer sink and muxing to the output gif file.Here is a completed example, change the micro definition in your test and be sure to use the latest version of ffmpeg.
video2gif.cpp