Is it possible to use ffmpeg to clamp dark values to 0 in h.264?
Hi!
I've got a video that I'd like to display with transparency, and the framework being used for playback only allows a single value to be assigned for alpha (I've set it to #000000). I can export the video in any format, but I'm using h.264 for size efficiency. On a high quality export and with keyframe distance set to 1 I'm still getting black fringing around edges where the pixels are not-quite-black, even after setting the black point quite high in the editor. I'm going through the documentation, but since I'm not familiar with using ffmpeg, I wanted to ask here too. Does anyone know if ffmpeg will let me do something like set all values below a threshold to #000000, or if that's even possible with how h.264 compresses? Thanks!
Posted Sep 21, 2022, 9:22 PM UTC
Most H.264 videos do not use the RGB color format, YCbCr is used instead. Limited-range YCbCr, to be specific. Each component in 8-bit full range RGB can go from 0 to 255 (
0xFF), in limited-range YCbCr, the luma (Y) component goes from16to235and both chroma components from16to240, meaning gray is exactly in the center, at Cb=Cr=128 (0x80).Anyway, you could try using the
lutfilter to clip luma values below a certain threshold:You'll need to find a reasonable value for
<offset>.I see, I'll give it a shot, thanks for the help