Using ffmpeg to Stretch the Contrast of a Video

5

I'm trying to implement what was suggested here: ffmpeg: adaptively stretch contrast

The method I thought of is:

  1. Separate the L, U and V channels.
  2. Apply histeq to the L channel.
  3. Recombine the channels.

I'm new to ffmpeg, so I've been able to do 1 and 2, but not sure how to implement #3. What I have so far is:

ffmpeg -i in.mkv -vf extractplanes=y,histeq=strength=0.3:intensity=1 out.mkv

Which extracts the L channel and autocontrasts it, but I'm not sure how to recombine it with the U and V channels. Maybe use mergeplanes?

Pickles

Posted 2015-01-02T20:58:26.123

Reputation: 53

Answers

2

Use this:

ffmpeg -y -i in.mkv -filter_complex "extractplanes=y+u+v[y][u][v];   \
[y]histeq=strength=0.3:intensity=1[lumaeq];   \
[lumaeq][u][v]mergeplanes=0x001020:yuv420p[out]" -map "[out]" out.mkv  

The extractplanes filter needs to extract each channel (y+u+v[y][u][v]), which can later be combined with mergeplanes.

Note that I stated format of the output explicitly to be yuv420p, because my input material is of the same format.
Note that I used your strengths and values for the histeq filter, which made my "normal" footage completely unusable. That is not to say that it will not work on badly shot footage. But even a value of histeq=strength=0.1:intensity=0.5 was right at the edge of usability. This is because histeq is a global filter and applying to one channel is not optimal process. In any case you can use the curves filter to individually target channels as well.

But the principle of splitting and merging is as above.

Rajib

Posted 2015-01-02T20:58:26.123

Reputation: 2 406