Search code examples
bashffmpegjpegsequenceanimated-gif

How to use palettegen and paletteuse filters with FFmpeg for image sequences?


I have converted a short video to gif with the help of the following script:

#!/bin/sh

palette="/tmp/palette.png"

filters="fps=15,scale=320:-1:flags=lanczos"

ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2

However when I convert an image sequence, I get error message: "Filter paletteuse has a unconnected output"

#!/bin/sh

palette="/tmp/palette.png"

filters="fps=25"

ffmpeg -v warning -f image2 -i %04d.jpg -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -f image2 -i %04d.jpg -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2

How can I make palettegen and paletteuse work with the image sequences too?


Solution

  • palettegen and paletteuse work fine with image sequence inputs.

    The problem is with your positional parameter. You're using $2, but there is only one argument passed from your command to your script. Change the $2 to $1.