[FFmpeg-user] How to correct dark video with bright background

Michael Koch astroelectronic at t-online.de
Sat Mar 9 22:00:42 EET 2019


Am 09.03.2019 um 19:14 schrieb Gerardo Ballabio:
> Hello all,
> I have a video that was filmed under bad lighting conditions, the
> background is too bright and people in the foreground are dark. I'm
> trying to use ffmpeg to correct it. Please kindly help me.

For video processing like this you best use the haldclut filter, which 
is a 3D color-look-up-table.The workflow is as follows.

Step 1:
Extract one frame from your video and add a color-look-up-table to it. 
-ss 0.5 is the time where the frame is extracted from the video.
ffmpeg -ss 0.5 -i video1.mts -f lavfi -i haldclutsrc=8 -filter_complex 
"[1]format=pix_fmts=rgb24[a];[a][0]xstack=inputs=2:layout=0_0|w0_0" 
-frames 1 -y image_with_clut.png

Step 2:
Open the image_with_clut.png with a image processing program of your 
choice, for example IrfanView or Gimp. Edit brightness, contrast, gamma, 
saturation and hue. You can also adjust the curves. In your example, 
especially a high gamma value is required, and a little bit more 
saturation. Then save the image using the same filename.
Of course, all modifications must be applied to the whole image 
consisting of the video frame and the clut. Filters like noise 
reduction, sharpening or sofening are not allowed.

Step 3:
Cut away the video frame, so that only the 512x512 clut remains:
ffmpeg -i image_with_clut.png -vf crop=512:512:0:0 -y clut.png

Step 4:
Apply the clut to your video with the haldclut filter:
ffmpeg -i video1.mts -i clut.png -filter_complex haldclut -y out.mts

Michael


More information about the ffmpeg-user mailing list