Pregunta

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.

¿Fue útil?

Solución

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.

Otros consejos

This a very old topic but it took me some considerable time to fix my YUV4MPEG2 uncompressed video routine, so I decided to write it down.

What is important to understand is the the Y, U, V frame are written as separate frames. The easiest way is to write in 444 format since you have to load only one input image each time.

Assuming you have images of 800x600 pixels, names image1, image2,... and want a frame rate of 5 fps:

First write an string header:

        'YUV4MPEG2 W800 H600 F05:1 Ip A0:0 C444'+#10

load input image1 and write a string head FRAME ending with char 10:

        'FRAME'+#10

Write full 800x600 pixels Y frame where Y:=trunc(R x 77/256 + G x 150/256 + B x 29/256) and R,G,B are the red,green and blue pixel values. Y is a 1 byte value

         YYYY
         YYYY
         YYYY
         YYYY

Write full 800x600 pixels U frame where U:=trunc(R x -43/256 + G x -84/256 + B x 127/256 +128) and R,G,B are the red,green and blue pixel values. U is 1 byte value.

         UUUU
         UUUU
         UUUU
         UUUU

Write full 800x600 pixels V frame where V:=trunc(R x 127/256 + G x -106/256 + B x -21/256 +128) and R,G,B are the red, green and blue pixel values. V is a 1 byte value.

         VVVV
         VVVV
         VVVV
         VVVV

Repeat this for the next images starting with 'FRAME'+#10 each time. Files can be displayed by VLC, FFMPEG and Youtube. More info: http://wiki.multimedia.cx/index.php?title=YUV4MPEG2

See also https://en.wikipedia.org/wiki/YUV

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top