[FFmpeg-devel] [RFC] M-bit to N-bit YUV conversions

Oskar Arvidsson oskar at irock.se
Thu Aug 25 02:18:21 CEST 2011


There have been complaints about how ffmpeg/libav converts M-bit to N-bit YUV, 
e.g. see http://forum.doom9.org/showthread.php?t=161915 which I've been asked 
to look into.

The current code in swscale is based on how 8-bit to 16-bit YUV conversions 
have been done earlier - basically duplicating each input byte in the output 
(e.g. 0xf0 -> 0xf0f0, 0x65 -> 0x6565). I believe this is the right thing for 
full range content.

As I can see the issues with the current code is mainly:

1) Does not follow standards such as BT.709 for limited range YUV
2) Signed chroma is treated as unsigned
3) Dithering back to the original bit depth may not preserve original value.

An example of 3) is conversion from bit depth 8 to 10 and back again with 
input 0x80, which would be converted to 0x201 and then possibly dithered to 
(0x201 + 3) >>2 = 0x81.

BT.709 as well as Microsoft propose simple shifting for upscaling to a high 
bit depth.

Now, for my questions:

a) What method should be used for conversion? Current method? Simple shifting?
b) Should we distinguish between limited and full range YUV?
c) Other comments, ideas?

Oskar Arvidsson

Oskar Arvidsson
+46 (0)701766451
oskar at irock.se

More information about the ffmpeg-devel mailing list