[vlc-devel] Chroma question on geting raw video data

Rémi Denis-Courmont remi at remlab.net
Sat Jun 9 13:22:24 CEST 2012

Le samedi 9 juin 2012 14:05:08 Seven Du, vous avez écrit :
> I'm not to VLC, I'm trying to get video data via callbacks in the following
> code
> libvlc_video_set_format(context->mp, "YUYV", 352, 288, 288 * 2);

That can't work. YUYV a.k.a. YUY2 is a form of packed YUV 4:2:2. In fact, the 
name comes from the packing order (Y1, U, Y2, V). Each pixel occupies two 
bytes. Thus the pitch must be (at least) double the pixel width.

Furthermore, some code paths assume each lines are aligned on a 16 bytes 
memory boundary and the number of lines is even.

> libvlc_video_set_callbacks(context->mp, vlc_video_lock_callback,
> vlc_video_unlock_callback, vlc_video_display_callback, context);
> I want to use a buffer to get all the decoded or raw data on opening a mp4
> file with H264 video and AAC audio, and I can get audio data fine, but
> with video, what the buffer size should be set in the lock callback? 
> Someone told me 352 * 288 * 1.5 for YUYV, it that true?

By definition of the pitch, the buffers must be (at least) as large as product 
of the line pitch with the pixel height, so 352 * 2 * 288.

> And I also want to get raw H264 video data without decode,  so is it
> possible to replace the "YUYV" param to sth. like "RAW" ?

You need to use the libvlc_video_set_format_callbacks() to preserve the chroma 
and/or the resolution. AVC is usually decoded to I420, but not always. And, in 
any case, libvlc_video_set_callbacks() cannot deal with I420 well since I420 
has multiple planes of different sizes.

> Or I guess it's
> not hard to make a module that just copy the raw data to the buffer like
> the "YUYV" module does, so question is - which module is actually decoding
> "YUYV" ?

YUYV is raw. You cannot "decode" YUYV.

Rémi Denis-Courmont

More information about the vlc-devel mailing list