0

Why would FFmpeg create these artifacts like remaining pixels on the edges of the animation where objects have already removed and how to remove these?

Why would it create this magenta/red colored borders and how to remove these?

Why does it choose magenta/red color for semi-transparent pixels?

This is the command:

ffmpeg -pattern_type sequence \
-i "project_1_%05d.png" \
-vf "fps=30,scale=-1:-1:flags=lanczos,palettegen" \
"pallete_1.png" \
&& \
ffmpeg -pattern_type sequence \
-i "project_1_%05d.png" -i "pallete_1.png" \
-filter_complex "fps=30,scale=-1:-1:flags=bicubic[x];[x][1:v]paletteuse" \
"animation_bicubic_1.gif"

FFmpeg version:

ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200523
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100

The first PNG frame of a sequence I created:

The result(palette) from the first command:

The result(animation) from the second command which previews 2 issues:


As requested in the comment section by Tetsujin, appended more variants with different effects:

The first PNG frame of a version without the glow effect:

A version without the glow effect in a PNG sequence(only artifacts exist):

A version without the transparency in the PNG sequence(no issues):

Indeed, it seems the transparency processing adds artifacts and magenta/red borders to the result.

Artfaith
  • 303
  • 4
  • 13
  • Which ffmpeg version? – Gyan Mar 27 '21 at 10:37
  • @Gyan modified appending the information – Artfaith Mar 27 '21 at 11:13
  • Not a solution, but you can simplify your commands into a single command: `ffmpeg -framerate 30 -i "project_1_%05d.png" -filter_complex "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif`. The scale is doing nothing so I removed it, and no need for fps filter in this case (fps filter is used in the [other answers](https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality/556031#556031) to reduce frame rate of videos for GIF). – llogan Mar 27 '21 at 17:44
  • Thank you, but why does it result in 30 frames less? So, the first command creates `180` frames which is `6010ms` in total(duration) and the one you mentioned creates `150` frames - `5010ms` in total. The reason I used `-r 30` is to have the animation smoother(60 fps makes it laggy, though). It seems like both`-r 30` and `-framerate 30` produce equal results(same size, same duration), but the inner fps differs, I suppose. For the first option it shows `25 FPS`, for the second - `30 FPS` or `25 fps, 25 tbr, 25 tbn, 25 tbc` vs `30 fps, 30 tbr, 30 tbn, 30 tbc`. – Artfaith Mar 27 '21 at 20:03
  • The GIF file format does not support alpha transparency. You need to design your animation around this. But maybe it doesn’t have to be a GIF? You can for example also animate PNG frames using CSS or use a video (with alpha transparency). – Daniel B Mar 29 '21 at 08:06
  • I thought of APNG, though. GIF and its lack of the transparency support is known, but why exactly magenta/red color is chosen by FFmpeg for semi-stransparent pixels and is it possible to change this color to white, for example? Slightly modified the question. – Artfaith Mar 29 '21 at 08:55
  • 1
    @F8ER 1) I get the same number of output frames. You mentioned `-r 30`, but I don't see it in your commands, so I assume your commands have changed. Need your commands and complete logs to see what's happening. Note that unless you tell it otherwise ffmpeg uses a default frame rate of 25 for image inputs. 2) I don't have your input image sequence so I can't duplicate the magenta/red artifact issue. – llogan Mar 29 '21 at 19:21

1 Answers1

3

Try recreating it using images without transparency.
gifs handle transparency badly. Any pixel can either be fully visible or fully transparent, so your nice little fades at the edges of each star get destroyed. This is quite possibly causing the other artefacting too.

This…
enter image description here

becomes this…
enter image description here

Tetsujin
  • 47,296
  • 8
  • 108
  • 135
  • I see that, but is it possible to tell it to use another color instead of this magenta/red? – Artfaith Mar 27 '21 at 09:47
  • Did you try it yet without the transparency? – Tetsujin Mar 27 '21 at 09:53
  • Added more information. Although, it's still interesting how to tell FFmpeg to use another color( or even do not use any) instead of magenta/red and **why does it add these artifacts**... – Artfaith Mar 27 '21 at 11:27
  • I'm not sure what else I can say. gifs handle transparency very badly, they make a poor guess at what to do with faded edges. Avoid it by not using transparency, or by having hard edges. – Tetsujin Mar 27 '21 at 11:33
  • All in all, is it possible to have a transparency, but without these artifacts(left pixels)? ^^ – Artfaith Mar 28 '21 at 06:19
  • As I already said, yes, but only if you have hard edges. A pixel is 'on' or 'off' so you have to design it that way if you want transparency. – Tetsujin Mar 28 '21 at 11:12
  • Doesn't a frame without the glow effect count as a hard-edged one? The question now includes a frame without the effect. – Artfaith Mar 29 '21 at 04:50
  • I'm really not sure how many different ways I can explain this. A pixel is on or off, any alpha edges will become hard edges. This is not a hard edge, some pixels have partial transparency. These will be switched on or off - https://i.stack.imgur.com/quIhi.png – Tetsujin Mar 29 '21 at 06:37
  • It's already understood and then it was out of the question. Appreciate it ^^ What's actually interesting is the artifacts(left pixels from objects which already have moved/removed) - i.imgur.com/MJ8GTn8.png. – Artfaith Mar 29 '21 at 19:19