Alex Balgavy

Just some stuff about me.

Here's my dotfiles repository.

Check out my blog.

My keys: PGP, SSH

My crypto wallets (BTC, XMR)

ffmpeg how to generate a color palette from a video and apply it to another

Written by John Riselvato - original link

Ever look at a video with an amazing color grading and wish you could copy it? Getting that look can be accomplished using the palettegen filter. palettegen generates a single palette for an entire video stream and saves it as an image file.

Figure 64.0: color palette for input.mp4 (enlarged){width=“106” height=“106”}

 In this example, a color palette of 256 pixels is generated, as seen in figure 64.0:

$ ffmpeg -i input.mp4 -vf "palettegen" palette.png

a 256 pixel palette.png was generated from input.mp4. In this example, the same palette.png is applied to input2.mp4 giving it the same color palette input.mp4 had.

Figure 65.0: the input.mp4 color palette applied to input2.mp4

The difference is subtle yet very aesthetically pleasing. The new palette applies faded blue color where green was once seen, as seen in figure 65.0:

$ ffmpeg -i input2.mp4 -i palette.png -filter_complex "paletteuse" -c:v libx264 -pix_fmt yuv420p output.mp4

Variables:

paletteuse
    Indicates the palette use filter name

dither
    Indicates the selected dithering mode (default is sierra2_4a)

    bayer
        Ordered 8x8 bayer dithering

    heckbert
        Paul Heckbert's simple error diffusion

    floyd_steinberg
        Floyd and Steingberg dithering

    sierra2
        Frankie Sierra dithering v2

    sierra2_4a
        Frankie Sierra dithering v2 "Lite"

For more information on the advanced parameters available for paletteuse, visit: https://ffmpeg.org/ffmpeg-filters.html#paletteuse