[x264-devel] Lossless Compression

Mo DeJong mo at modejong.com
Thu Aug 22 22:00:38 CEST 2013


Alain, could you provide an example command line that shows how lossless encoding with x264 should actually work? I have looked all around online and it seems that x264 should be able to support lossless encoding of video data, but my testing shows that the data is not getting encoded in a lossless way. What I mean is that if I encode a grayscale ramp image that has values from 0 -> 255 with ffmpeg and x264, the data I get back out does not match the original input data.

Here are the commands I use to encode the video with x264 and then extract the image data to PNG frames using ffmpeg: (recent ffmpeg 1.2.1 and x264 build from source on a Mac)

ffmpeg -y -i Grayscale256.mov -c:v libx264 -pix_fmt yuv444p -preset:v slow -profile:v high444 -qp 0 -x264opts no-8x8dct Grayscale256_qp0_no8_444.m4v

ffmpeg -y -i Grayscale256_qp0_no8_444.m4v -f image2 Grayscale256_qp0_no8_444_F%2d.png

I am using the YUV 4:4:4 pixel format and the high444 profile along with qp 0, I also disabled the 8x8 like you mentioned. Perhaps I am misunderstanding something, but I though these settings would be able to hold the full range of RGB values, and this example is a grayscale ramp only.

When I then compare the original PNG to the Grayscale256_qp0_no8_444_F01.png file extracted by ffmpeg, the two image files are not identical. Of 256 rows, 6 are identical but the rest differ slightly.

Mo DeJong


On Aug 21, 2013, at 9:26 AM, Alain Champenois wrote:

> Hi Raul,
> 
> I reported the same issue two months ago (Subject: Potential bug in transform bypass 8x8).
> Transform bypass is the technical name for lossless compression.
> 
> In summary, for lossless compresison x264 is not compliant with the H.264 spec and neither
> is ffmpeg (libavcodec) because it was developped to be compatible with x264.
> 
> The issue is related to the 8x8dct functionnality. If you want to generate lossless stream 
> with x264 respecting the standard (compatible with JM), you need to disable 8x8dct by using 
> the option  --no-8x8dct  when encoding. The streams generated by x264 will then respect the 
> standard while still being compatible with the buggy ffmpeg (libavcodec).
> 
> I suggested the --no-8x8dct option become enabled automaticly when doing lossless, but this 
> modification has not been accepted (yet).
> 
> Btw, the loss of compression resulting from disabling 8x8dct is minimal (less then 0.03%).
> 
>   Alain
> 
> _______________________________________________
> x264-devel mailing list
> x264-devel at videolan.org
> https://mailman.videolan.org/listinfo/x264-devel



More information about the x264-devel mailing list