Skip to content

(FFmpeg) How to Generate a Color Palette From a Video and apply it to another?

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)

 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 


	Indicates the palette use filter name

	Indicates the selected dithering mode (default is sierra2_4a)

		Ordered 8x8 bayer dithering
		Paul Heckbert's simple error diffusion

		Floyd and Steingberg dithering

		Frankie Sierra dithering v2

		Frankie Sierra dithering v2 "Lite"

For more information on the advanced parameters available for paletteuse, visit:

Love FFmpeg? Grab a copy of FFmpeg For Beginners on Kindle or Paperback to learn over 120 ways to master FFmpeg!

buy now on amazon