I've noticed that exporting a gif seems to convert the image to an mp4, and THEN to a gif. This is probably the cause of the image artifacts. I'm not sure if it's possible to export images directly to a gif with FFMPEG. If not, perhaps we could use MagickWand, GIFLIB, or something else for gif export.
Duplicate of #681. This is (among other things) exactly the reason why I started rewriting the movie exporter from scratch: Improving the output quality by removing redundant passes. Once it is done the raw image material will go directly through FFmpeg into the movie files (GIF files etc.).
BTW, workaround for now is obviously exporting the animation as image sequence (possibly in PNG for lossless quality), then convert to GIF using some external tool that does it properly.
Will do a workaround to get better gif export before the api based exporter is ready.
We can try to get rid of the mp4 step and convert an image sequence to gif directly, it will be better.
Getting rid of the mp4 set is good first step for both for quality and speed. However another cause of this issue is on this line:
strCmd1 += " -vf scale=320:-1:flags=lanczos,palettegen";
You should get rid of the scaling. It was only being scaled where you copied this code from because the output was also being scaled. Lanczos scaling will introduce new colors which I think is to blame for the blurring effect. This is especially noticeable with images smaller than 320 px wide because they are actually upscaled (even worse).
If it can help, there is a very good tutorial on how to produce top quality animated gif files with ffmpeg here : http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
I think I've found a way to convert an img sequence to gif without an intermediate mp4.
Most helpful comment
If it can help, there is a very good tutorial on how to produce top quality animated gif files with ffmpeg here : http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html