[x264-devel] Is lossless luma encoding possible without high444 if UV values are known to be zero?

Mo DeJong mo at modejong.com
Sun Sep 1 20:35:29 CEST 2013


Hello

What I would like to do is encode a single frame of 4x4 grayscale YUV without having the Y values quantized (each U and V is zero). I understand that there is a special lossless mode for the high444 profile, but files encoded with that profile do not work on my hardware. The first command I tried was this:

echo -en "\x4f\x50\x51\x53\x80\x80" > raw.yuv

> x264 --no-progress --qp 0 --no-8x8dct --input-fmt raw --range pc --input-range pc --preset fast --profile main --input-res 2x2 --fps 30 -o raw.h264 raw.yuv
x264 [error]: main profile doesn't support lossless


Clearly not supported, so I tried to use -qp 1 to see how close to lossless encoding x264 could get with a plain 4:2:0 grayscale I frame:


x264 --no-progress --qp 1 --no-8x8dct --input-fmt raw --range pc --input-range pc --preset fast --profile main --input-res 2x2 --fps 30 -o raw.h264 raw.yuv

yuv [info]: 2x2p 0:0 @ 30/1 fps (cfr)
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
x264 [info]: profile Main, level 1.0
x264 [info]: frame I:1     Avg QP: 0.00  size:   691
x264 [info]: mb I  I16..4:  0.0%  0.0% 100.0%
x264 [info]: coded y,uvDC,uvAC intra: 25.0% 0.0% 0.0%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 75% 19%  6%  0%  0%  0%  0%  0%  0%
x264 [info]: i8c dc,h,v,p: 100%  0%  0%  0%
x264 [info]: kb/s:165.84

encoded 1 frames, 119.06 fps, 165.84 kb/s

Comparing the raw bytes from the original to the bytes decoded from this x264 encoded file:

> hexdump -C raw.yuv
00000000  4f 50 51 53 80 80                                 |OPQS..|
00000006

hexdump -C raw_decoded.yuv
00000000  4f 51 51 53 80 80                                 |OQQS..|
00000006


See how that second byte value gets changed from 50 to 51? I am wondering if there is any way I can get x264 to encode the luma value in a lossless way, but without having to enable the high444 profile. The data I want to encode is grayscale yuv 4:2:0, and any UV samples are always set to zero (128 -> 0x80 in this example).

After reading up on x264 command line arguments, I found that I could also pass the following:

--ipratio=1.0 --pbratio=1.0

Passing these two arguments fixed the problem for this simple little example, but for larger images there is still quite a lot of modification of the luma values (in one test frame I tried more than 90% of the luma values were changed).

Are there additional parameters I could pass to get x264 to encode the original Y U V samples into the output file without modification?

thanks
Mo



More information about the x264-devel mailing list