2009/11/25 Alexander Bokovikov <openwo...@uralweb.ru>:
>> // Capturing image data
>> int size = avpicture_get_size(PIX_FMT_YUV420P, width, height);
>> uint8_t * pic_dat = reinterpret_cast<UINT8 *>(malloc(size));
>> memset(pic_dat, image.bits(), size);
>
> AFAIU, this is not correct.
> size = (width * height * 3) / 2 for YUV420 color space. But you're trying to
> fill it out with RGB image data (which are width *height * 3 in size).
> AFAIK, QImage is a usual RGB(A) image. It doesn't support YUV color space.
> You must manually convert RGB => YUV. Am I incorrect?

Thanks Alexander, You are absolutely right. The problem was the incompatibility
between the color space coming from the QImage data and the color space used
by FFmpeg (in my code).
Fortunately, I found the solution and here is the code:

// Getting QImage dimensions
int w = c->width;
int h = c->height;

// Preparing the buffer to get YUV420P data
int size = avpicture_get_size(PIX_FMT_YUV420P, w, h);
uint8_t *pic_dat = (uint8_t *) av_malloc(size);

// Transforming data from RGB to YUV420P
RGBtoYUV420P(image.bits(), pic_dat, image.depth()/8, true, w, h);

// Setting up AVFrame
picturePtr = avcodec_alloc_frame();
picturePtr->quality = 0;

// Filling AVFrame with YUV420P data
avpicture_fill((AVPicture *)picturePtr, pic_dat,
                   PIX_FMT_YUV420P, w, h);

The function RGBtoYUV420P can be taken from here:
http://qtdvd.com/guides/ffmpeg_test.tar.bz2
It is really cryptic but it works!

Now I can create swf and mpeg videos from QImage arrays!
It was a tough task, but the goal is reached!

Thanks Alex!

-- 
============================
  Gustavo Gonzalez
  xting...@gmail.com
============================
_______________________________________________
libav-user mailing list
libav-user@mplayerhq.hu
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to