4

I have a video that is stored in the YUV 4:2:0 colour space. Assuming I used a lossless video codec but set the output colour space to YUV 4:2:0, would this still be a lossless encode or would I have to use a 4:4:4 colour space to make the encode lossless?

2
  • Would it help as a test to do the re-encode, then compare the file sizes from the original to the new? If there's no change, then is it probably lossless?
    – tomh
    Jan 3, 2015 at 21:33
  • 1
    @Tomh - not necessarily, lossless compression algorithms have different levels of efficiency. The file size could go up and not be lossless and it could go down and still be lossless.
    – AJ Henderson
    Jan 4, 2015 at 18:07

3 Answers 3

2

A lossless codec that can read/write yuv 4:2:0 samples is logically like zip for the bytes of video data. You get literally identical (same md5 hash, byte-for-byte identical) output back after decompressing. That is the definition of lossless.

See my answer to https://superuser.com/questions/347433/how-to-create-an-uncompressed-avi-from-a-series-of-1000s-of-png-images-using-ff/864520#864520 for an example of compressing and then verifying losslessness with ffmpeg.

We all know converting between RGB and YUV is lossy, but even upsampling the chroma and then downsampling again is not necessarily lossless. Here's a post in a discussion about the lossyness of storing 4:2:0 video by upsampling to 4:2:2 for huffyuv. Depending on the upsampling algorithm, downsampling again might round differently in the last bit. (jagabo on that forum knows what he's talking about, not everyone else does.)

So use libx264 -qp 0 -preset ultrafast, or utvideo for lossless tmp files, if you don't have a raid array of scratch space for uncompressed temporary files. They both support all relevant pixel formats (rgb, 444, 422, and 420), and are fast. IDK about higher bit-depth support in utvideo, but x264 does support it.

1

Probably no loss, but there is more to it than just YUV420. You can need to make sure the same ITU-R Recommendation is used (BT.601, BT.708 or maybe even 2020) In addition make sure the same color ranges is used (0-255 vs 16-235)

0

Some people could be more in depth about this, but my understanding is that it depends on how the color is compressed. Going to 4:4:4 would certainly be lossless, but not necessarily worth it.

1
  • Converting to 4:4:4 and back to 4:2:0 could actually introduce rounding errors. Jan 15, 2015 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.