[FFmpeg-user] clipping samples to broadcast range in an mpeg2video output

Andy Furniss adf.lists at gmail.com
Sun Feb 7 22:57:27 CET 2016


Dave Rice wrote:
>
>
>>> On Feb 7, 2016, at 1:42 PM, Paul B Mahol <onemda at gmail.com>
>>> wrote:
>>>
>>>> On 2/5/16, Paul B Mahol <onemda at gmail.com> wrote: On 2/5/16,
>>>> Dave Rice <dave at dericed.com> wrote: Hi all, I am having trouble
>>>> creating an mpeg2video output that conforms to 16-235 broadcast
>>>> range. I'd like to find a way to have an input which is
>>>> yuv420p but has luma values out of broadcast range but clip to
>>>> broadcast range while encoding to mpeg2.
>>>>
>>>> To demonstrate the issue, I generate a yuv420p file with
>>>> samples in the out of broadcast range via:
>>>>
>>>> ffmpeg -f lavfi -i
>>>> "nullsrc=s=256x256,geq=random(1)/hypot(X-cos(N*0.07)*W/2-W/2\,Y-sin(N*0.09)*H/2-H/2)^2*1000000*sin(N*0.02):128:128"
>>>>
>>>>
-c:v ffv1 -t 10 sample.mkv
>>>>
>>>> I can then clip the samples using clipval in the lut filter and
>>>> see the clipped values in a waveform with:
>>>>
>>>> ffmpeg -i sample.mkv -vf lut=y=clipval:u=clipval:v=clipval -c:v
>>>> ffv1 -f nut - | ffplay - -vf waveform The waveform shows the
>>>> values clipped at 16 and 235.
>>>>
>>>> However I need the output to use mpeg2video. When I change
>>>> lossless ffv1 to mpeg2video with:
>>>>
>>>> ffmpeg -i sample.mkv -vf lut=y=clipval:u=clipval:v=clipval
>>>> -c:v mpeg2video -f nut - | ffplay - -vf waveform
>>>>
>>>> The output shows many sample values above 235. The lossy
>>>> mpeg2video encoding seems to place values above 235 while the
>>>> lossless ffv1 doesn't. Is there a way to encode in mpeg2video
>>>> without having values over 235 in the output?
>>>
>>> Appears to be mpeg2video bug, can others confirm?
>>
>> It appears that having out of range values is OK, its player
>> responsibility to clip values that are out of range.
>
> The players involved are broadcast television servers which do not
> clip the values. The broadcast specification that I'm trying to
> adhere to requires both mpeg2 encoding and clipping out of range
> values. Dave Rice

Disclaimer - I know nothing about broadcasting!

Random observations.

I have looked at the yuv values of decoded broadcast mpeg2/h264 and
there are plenty of over/under samples produced.

Your sample is quite extreme so has more than "real" stuff would.

If your source is full range then maybe it should be scaled rather than
clipped.

"The players involved are broadcast television servers"

confuses me - are they mpeg encoders needing clipped raw input, in which
case the lut does its job, or do they take some high bitrate mpeg2 you
are trying to make? If so maybe there will be less over/under from that
than this test.


More information about the ffmpeg-user mailing list