How to apply Instagram-like color filters to a video using FFmpeg?

I have a mathematical function related to the Instagram filter which I want to apply to each pixel’s RGB values. Is there any filter or options in FFmpeg which allow me to do this?

1 Like

Yes, you may use external plugins, such as mathematical filters, to alter pixel values using FFmpeg by applying custom filters using the frei0r filter. Nevertheless, it might not be the easiest way to apply intricate mathematical operations to every pixel.

Using the lutrgb filter is another method that enables you to apply a lookup table to the RGB values of each pixel. Your mathematical function can be represented in a text file that you can use as a lookup table.

This is a broad overview of possible uses for the lutrgb filter:

But, make a file called a LUT (Lookup Table) and based on your mathematical function, create a text file that shows the mapping of input RGB values to output RGB values. Every line in the file corresponds to an RGB value.

For example:

# R   G   B   R'  G'  B'
0   0   0   0   0   0
255 0   0   255 0   0
0   255 0   0   255 0
# Add more lines as needed

Any how one can do it so using Fmpeg?

For Ffmpeg you can use the following command:

ffmpeg -i input.mp4 -vf "lutrgb=r=mylut.txt" output.mp4

This will create a lookup table for each pixel in the video. Change the path to your input video to input.mp4, then modify the filter according to the name of your LUT file.

Remember that it can be difficult to create a lookup table file by hand for complex mathematical functions, therefore you might want to use a script to construct the LUT file based on your mathematical function and automate the process.

You might need to look at alternative tools or libraries that offer greater flexibility for pixel-level editing if your mathematical function is more complicated and needs real-time updates. You could even try utilizing a programming language like Python with libraries like OpenCV or PIL.