How to correct dark video with bright background

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to correct dark video with bright background

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.

Here you can find a snippet:
https://drive.google.com/drive/folders/1aG04znyHdDio7cvgaQlovYTb8bX8NTLL?usp=sharing

video1.mts is the original file. video2.mp4 was created by a friend of
mine using proprietary software on Windows. I've been trying to
reproduce that. video3.mts is the best result I obtained (see below)
but the contrast is still too high and the colors aren't quite right.

I've tried several of ffmpeg's effects but maybe there are some better
ones that I missed?

- "eq=brightness=..." turns black into grey and gives the video a
"foggy" look, no good
- "colorlevels=..." I tried many parameter sets but couldn't do much
better, in the end I concluded that probably linear scaling isn't good
enough and I need nonlinear
- "curves=..." was indeed better but when I stretched the curve beyond
a certain point I obtained distorted colors
- I tried "geq=..." too but it doesn't seem to work, I always get an
error like this, if I'm getting the syntax wrong I couldn't figure out
what is the right one (I'm using Debian stable, ffmpeg version is
3.2.5):

ffmpeg -i video1.mts -vf geq='r=r(X,Y):g=g(X,Y):b=b(X,Y)' video3.mts
[Parsed_geq_0 @ 0x55a01bb0aa60] [Eval @ 0x7ffd3d63afb0] Missing ')' or
too many args in 'r(X'
[AVFilterGraph @ 0x55a01bb09e80] Error initializing filter 'geq' with
args 'r=r(X'
Error opening filters!

These are the commands that I used to produce video3.mts:

ffmpeg -i video1.mts -vf colorlevels=romax=0.8:gomax=1.0:bomax=0.9 -b
12M temp.mts
ffmpeg -i temp.mts -vf curves=r='0/0.05 0.1/0.25 1/0.8':g='0/0.05
0.1/0.25 1/0.8':b='0/0.05 0.1/0.25 1/0.8' -b 12M video3.mts

Thanks
Gerardo
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to correct dark video with bright background

Michael Koch
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
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to correct dark video with bright background

Gerardo Ballabio
Thank you Michael -- but that means I still have to find good values
of brightness, contrast, gamma, saturation and hue to use with Gimp.
When I've done that, then couldn't I just apply the same values in
ffmpeg using the "eq" filter?

Or are you saying that Gimp has effects that ffmpeg doesn't have? If
so, could you please give some advice on that too? I'm afraid I'm not
better at correcting images with Gimp than with ffmpeg.

Gerardo

Il giorno sab 9 mar 2019 alle ore 21:01 Michael Koch
<[hidden email]> ha scritto:

>
> 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
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to correct dark video with bright background

Michael Koch
Am 10.03.2019 um 21:33 schrieb Gerardo Ballabio:
> Thank you Michael -- but that means I still have to find good values
> of brightness, contrast, gamma, saturation and hue to use with Gimp.
> When I've done that, then couldn't I just apply the same values in
> ffmpeg using the "eq" filter?

That won't work because in most cases the values for brightness,
contrast, saturation and so on don't have the same units in different
programs.


> Or are you saying that Gimp has effects that ffmpeg doesn't have?

The main advantage of IrfanView or Gimp is that you immediately see the
result when you change the parameters. Theoretically you can do the same
thing with FFmpeg, but it's very time consuming because you need a lot
of test runs.

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to correct dark video with bright background

Michael Koch
Am 10.03.2019 um 22:05 schrieb Michael Koch:
> Am 10.03.2019 um 21:33 schrieb Gerardo Ballabio:
>> Thank you Michael -- but that means I still have to find good values
>> of brightness, contrast, gamma, saturation and hue to use with Gimp.
>> When I've done that, then couldn't I just apply the same values in
>> ffmpeg using the "eq" filter?
>
> That won't work because in most cases the values for brightness,
> contrast, saturation and so on don't have the same units in different
> programs.

Also you can't be sure that different programs apply the filters in the
same order. Applying brightness before contrast doesn't give the same
result as contrast before brightness. It's an addition and a
multiplication, and it's important what's done first.

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to correct dark video with bright background

Gerardo Ballabio
Ok, thank you Michael. I'll try haldclut then. This means I have to do
some research into Gimp too...

Gerardo




Il giorno dom 10 mar 2019 alle ore 22:20 Michael Koch
<[hidden email]> ha scritto:

>
> Am 10.03.2019 um 22:05 schrieb Michael Koch:
> > Am 10.03.2019 um 21:33 schrieb Gerardo Ballabio:
> >> Thank you Michael -- but that means I still have to find good values
> >> of brightness, contrast, gamma, saturation and hue to use with Gimp.
> >> When I've done that, then couldn't I just apply the same values in
> >> ffmpeg using the "eq" filter?
> >
> > That won't work because in most cases the values for brightness,
> > contrast, saturation and so on don't have the same units in different
> > programs.
>
> Also you can't be sure that different programs apply the filters in the
> same order. Applying brightness before contrast doesn't give the same
> result as contrast before brightness. It's an addition and a
> multiplication, and it's important what's done first.
>
> Michael
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: How to correct dark video with bright background

Michael Koch
Am 11.03.2019 um 09:01 schrieb Gerardo Ballabio:
> Ok, thank you Michael. I'll try haldclut then. This means I have to do
> some research into Gimp too...

For the described workflow you can also use any other graphics program,
if it can read and write uncompressed or lossless compressed images
(like BMP or PNG). It doesn't work with lossy JPG compression.
In your example, begin with a high gamma correction.

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".