How to use palettegen=stats_mode=single plus paletteuse=new and paletteuse=dither together?

Viewed 29

I've made a short script to convert all .webm files in a directory into .gif files...

forfiles /s /m *.webm /c "cmd /c ffmpeg -y -i "@FILE" -lavfi palettegen=stats_mode=single[pal],[0:v][pal]paletteuse=new=1 -y "GIF_@FNAME".gif"

I've tried to add "paletteuse=dither=bayer:bayer_scale=3" in several ways like...

...[0:v][pal]paletteuse=new=1,[1:v][pal]paletteuse=dither=bayer...

but I can't seem to figure it out.

I do have this other script which works with the dithering but the color range is less than I would like it to be...

forfiles /s /m *.webm /c "cmd /c ffmpeg -y -i "@FILE" -vf palettegen palette.png && ffmpeg -i "@FILE" -i palette.png -filter_complex paletteuse=dither=bayer:bayer_scale=3 -r 60 "GIF_@FNAME".gif"

Any help is appreciated

1 Answers

Try:

ffmpeg -i palette.png -i vid1.webm -i vid2.webm -filter_complex \
  [0:v]palettegen=stats_mode=single,split[pal1][pal2]; \
  [1:v][pal1]paletteuse=new=1; \
  [2:v][pal2]paletteuse=dither=bayer \
  ...

The key in constructing FFmpeg filtergraphs is to keep track of all the labels and remembering you can only use a label once between one pair of output and input pads. If you need it multiple times, use split (or asplit for audio streams) to multiply the source stream. Finally, remember the difference between , (series connection, chaining) and ; (parallel chains). Makes a huge difference in FFmpeg filtergraphs.

The exception to the splitting rule is if you're using the input streams directly. So if you want to compare the effect of different palette application to one video, you'd do:

ffmpeg -i palette.png -i vid.webm -filter_complex \
  [0:v]palettegen=stats_mode=single,split[pal1][pal2]; \
  [1:v][pal1]paletteuse=new=1; \
  [1:v][pal2]paletteuse=dither=bayer \
  ...

Note that you still need to split the output of palettegen but no need to split 1:v input stream.

Related