El día 24 de noviembre de 2009 09:31, Gustavo González
<[email protected]> escribió:
> Hello everyone,
>
> I was looking for a cool example about how to
> convert a QImage object in to an AVPicture or
> AVFrame with no luck yet.

*************************************
After hours browsing the network, taking a bunch
of lines from here and there... I started to code two
ideas.
Sad comment: There are several examples solving the
problem but using a deprecated function (img_convert).

Ok. This is my first approach. Compilation is ok and
when I run it I got video files in many extensions, but
all I can see is a boring purple screen.

// Imagine you already got var QImage image initialized

// picturePtr is the frame where the image will be saved
AVFrame *picturePtr;
picturePtr = avcodec_alloc_frame();
picturePtr->quality = 0;

// Ensuring memory space for image data
int size = avpicture_get_size(PIX_FMT_YUV420P, picWidth, picHeight);

// Capturing image data
uint8_t * pic_dat = (uint8_t *) av_malloc(size);
memcpy(pic_dat, image.bits(), size);

// Casting the frame for a moment, to copy the Qimage data inside
// the frame
avpicture_fill((AVPicture *)picturePtr, pic_dat,
                      PIX_FMT_YUV420P, picWidth, picHeight);

// Inserting frame picturePtr to the movie... etc, etc, etc

*************************************
And this is my second approach. It compiles but it crashes when
I run it (signal 11, memcpy memory issue)

// Imagine you already got var QImage image initialized

// 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);

// Filling an AVPicture object with data coming from QImage
AVPicture pic;
avpicture_fill(&pic, pic_dat, PIX_FMT_YUV420P, width, height);

// picturePtr is the frame where the image will be saved
AVFrame *picturePtr;
picturePtr = avcodec_alloc_frame();
picturePtr->quality = 0;

// copy the data from AVpicture to AVFrame
for (int i=0; i<4; ++i){
   picturePtr->data[i]= pic.data[i];
   picturePtr->linesize[i]= pic.linesize[i];
}

// Inserting frame picturePtr to the movie... etc, etc, etc

Any help is very welcome :)

-- 
============================
  Gustavo Gonzalez
  [email protected]
============================
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to