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 mov-jpg.sh 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.

mov-jpg.sh (make this file executable)
CODE: SELECT ALL
#!/bin/bash
ffmpeg -i video.mov 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

jpg-mov.sh (make this file executable)
CODE: SELECT ALL
#!/bin/bash

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

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

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: janpenguin [at] riseup [dot] net 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.

One 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 video.mov -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 out.mov

    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:

    http://www.howtogeek.com/howto/44826/learn-to-adjust-contrast-like-a-pro-in-photoshop-gimp-and-paint.net/

    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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s