Page 1 of 1

YUV frame to image example?

Posted: 2011-05-20T07:38:56-07:00
by petke
I understand that it should be possible to:

0) Fill a raw data buffer with some a frames worth of values (say a YUV422 planar or interleaved buffer)
1) Create a YUV blob from the raw data buffer.
2) Create an image from the blob.

I have not managed to get this to work, or find any info how it should be done. Step 2 always errors ("unexpected end of file") probably because the image expect the YUV blob to be in some undocumented format that I don't know about. Could someone who knows better, create a quick example or pseudo-code to show how this should be done.

If I cant get this working I will have to ditch trying to create a YUV blob, and do the YUV buffer to RGB pixel buffer conversions myself and then pass the pixel buffer to the Image constructor.. but I'd rather not do this as that will be inefficient and IM must know how to do these YUV to RGB conversions.

The same question was asked about five years ago but unfortunately no example solution was given: viewtopic.php?f=1&t=8796

Thanks

Re: YUV frame to image example?

Posted: 2011-05-21T22:48:12-07:00
by anthony
What image format is the image blob?

IM will automatically convert images to RGB format for some image formats.

One solution for this is to convert the image to the colorspace wanted ("-colorspace YUV"), but the set that images colorspace to RGB without data change ("-set colorspace RGB"). Now when saved IM will save the data wiithout change.

Re: YUV frame to image example?

Posted: 2011-05-24T07:20:36-07:00
by petke
Hi

> What image format is the image blob?

I was hoping you could tell me what YUV formats Magick::Blob/Magick::Image can work with, so that I know how to programatically create one.

Just to clarify. Im not using the imagemagick command line tool, but the magick++ API. My use case here is I have a video decoding application that can give me uncomcompressed planar/interleaved, 8/16 bit, YUV422/YUV444 (Rec. 601 Y’CBCR) frames. I want to save such a frame to an Magick::Image. This means my source is a uncomressed video YUV frame, and not the data from an imagefile.

I was under the impression that it is possible to construct a Magick::Image from an uncompressed YUV frame, if I first construct somekind of YUV Magick::Blob. But I have not managed to get that working. I managed to get it working if I convert from my YUV buffer to a RGB pixel buffer myself. But I'd rather not if there was some more direct way to get a Magick::Image directly from the YUV frame.

Thanks

Re: YUV frame to image example?

Posted: 2011-05-24T18:10:58-07:00
by anthony
Apologies I seemed to be getting confused between YUV colorspace and YUV image file format!

I am not familar with the YUV file format and do not know how IM handles colorspace when YUV is involved.

Hmmm looking at YUV coder source...
The write function has the line
TransformImageColorspace(yuv_image,YCbCrColorspace);
which indicates that any image not in that colorspace will be converted to that colorspace before writing to the YUV file. Then other than some handling of sampling factors (using a resize, with triangle filter, for 'scaling) it just writes out the pixels to the file without further modification.

As such if you want to set image data as YUV raw data, make sure the colorspace is at least set to YCbCr

I hope this helps, and makes up for my mistake.