Search code examples
videofile-formatyuv

What is the file structure of a YUV 420 movie stream


The question is not about a library or tool, but about the specifications (either the standard or the summarized definition) of a YUV 4:2:0 movie stream.

Are YUV 420 movie streams just some concatenated YUV images, and if so, what is the specification of these frames and of the stream?

I want to make a simple images to YUV 420 helper, but if it happens that it requires also some computations / compression / prediction, I'll just surrender. If it just requires to convert images to YUV then append them together, I'll code it and share the C# source here.


Solution

  • Two ways: The first is really just concatenated YUV images (note that the order of planes is usually YVU, not YUV). For the format of a single frame look up for example the YV12 format, which is one way to lay out YUV 420 images in memory.

    The other way is the YUV for MPEG format, which does the same but starts with a bit of header information: See for example here: http://wiki.multimedia.cx/index.php?title=YUV4MPEG2

    If you have a YUV for MPEG file you have all the information needed to work with it in the file. If you have a raw YUV file you need to know the resolution, frame rate and subsampling to work with it.

    Another fun wrinkle here is that there are different ways to convert a 4:4:4 YUV image into a 4:2:0 YUV image, depending on where you put your subsampling grid. Interlacing makes this a bit complicated also.