Video color correction using ffmpeg, GIMP, ImageMagick

Excerpt from Openshot Users Forum

Yes you will and up with 1000’s of temp jpg files but it’s not as bad as it sounds. Computer does all the work while you are out doing something else. Below are two bash scripts for you to test, you must have ffmpeg and imagemagick, which you probably do.

Save below as with Gedit and make executable. If your not using MOV files edit to the correct file type. JPG’s will be named temp-000001.jpg and so on. Place file in same directory as MOV file and click on it. (make this file executable)
ffmpeg -i temp-%06d.jpg

Select any JPG and open in GIMP to get the LEVEL values. Example: 13 1.00 250, convert the 13 and 250 to % of 255, which is 5 and 98 and enter in script below. Now place the script below in your folder and click on it after you have entered correct values (make this file executable)

for image_file in *.jpg
convert $image_file -level 5%,98%,1.0 -unsharp 0x2 -quality 90 $image_file

ffmpeg -f image2 -r 24 -i temp-%06d.jpg -s 1920x1080 -y -an -r 24

rm *.jpg

The script above will color correct, combine jpgs back to MOV, delete all jpg’s. Remeber you don’t have to use MOV, check with ffmpeg for other video formats, there is also other options for JPG quality, bit rates, etc. So you will have to modify the scripts to suit your needs if you go this route.

About janpenguin

Email: k2.mountain [at] gmail [dot] com Every content on the blog is made by Free and Open Source Software in GNU/Linux.
This entry was posted in GNU/Linux and tagged , , , , . Bookmark the permalink.

1 Response to Video color correction using ffmpeg, GIMP, ImageMagick

  1. Matt says:

    Thank you for reposting this. It is very helpful insight for other adjustments I need to do.

    I wanted to update others, however, that it appears ffmpeg can now do this same adjustment with its current set of filters and no need to explode to JPEGs. The above would now be this single step:

    ffmpeg -i -vf "colorlevels=rimin=13/255:gimin=13/255:bimin=13/255:rimax=250/255:gimax=250/255:bimax=250/255, eq=gamma=1.00" -y

    To understand levels and how to get the top, bottom, and gamma values in GIMP and other image editors, I found this brief intro helpful:

    Save a frame from the film, open it in an editor, open the levels window and hit auto and/or adjust the levels manually. If the frame has sloppy borders, crop them off first or compensate in the levels window. You can level RGB separately (including gamma with different eq settings) in ffmpeg but you probably don’t want to do that as it will shift the colors a bit.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s