I do something similar converting QImage to avframe. Here's how I do it.

AVFrame* pTmpPicture =alloc_picture(PIX_FMT_RGBA32, pCodecContext->width,
pCodecContext->height);
QImage image(pTmpPicture->data[0], pCodecContext->width,
pCodecContext->height, QImage::Format_ARGB32);
// populate image with your image data
AVFrame* pPicture=NULL;
img_convert((AVPicture*)pPicture, pCodecContext->pix_fmt,
(AVPicture*)pTmpPicture, PIX_FMT_RGBA32, pCodecContext->width,
pCodecContext->height);
write_video_frame(pFormat, pVideoStream)


where:

AVFrame* alloc_picture(int pixfmt, int width, int height) {
  AVFrame* pPic = avcodec_alloc_frame();
  int size = avpicture_get_size(pixfmt, width, height);
  uint8_t* pPicBuf = (uint8_t*)malloc(size);
  avpicture_fille((AVPicture*)pPic, pPicBuf, pixfmt, width, height);
  return pPic;
}

bool write_video_Frame(...); // this will write pPicture from above to the
video stream with time basing, etc.

Works fine for me...hope it helps.


On Tue, Dec 23, 2008 at 1:38 PM, <[email protected]> wrote:

> Hi to everybody,
>
> I've got the following problem:
>
> I'm trying to encode a movie out of different QImages(Part of the Qt
> library). Therefore I've written this function:
>
> bool MediaSaver::write_vid_frame(uint8_t** data,int linesize)
> {
>        AVPacket pkt;
>        int out_size;
>        if(sws_cont)//means we've got different input-output pixelformat
>        {
>
>  
> sws_scale(sws_cont,(uint8_t**)data,&linesize,0,codcon->height,frm->data,frm->linesize);
>        }
>        else
>        {
>                frm->data[0]=data[0];
>                frm->data[1]=data[1];
>                frm->data[2]=data[2];
>                frm->data[3]=data[3];
>        }
>
>        av_init_packet(&pkt);
>        pkt.stream_index= vid->index;
>
>        if(cont->flags&AVFMT_RAWPICTURE)
>        {
>                pkt.flags|=PKT_FLAG_KEY;
>                pkt.data=(uint8_t*)frm;
>                pkt.size=sizeof(AVPicture);
>        }
>        else
>        {
>                out_size=avcodec_encode_video(codcon, video_outbuf,
> video_outbuf_size, frm);
>                if(out_size<=0)
>                        return false;
>        if (codcon->coded_frame->pts != AV_NOPTS_VALUE)
>            pkt.pts= av_rescale_q(codcon->coded_frame->pts,
> codcon->time_base, vid->time_base);
>        if(codcon->coded_frame->key_frame)
>            pkt.flags |= PKT_FLAG_KEY;
>        pkt.data=video_outbuf;
>        pkt.size=out_size;
>        }
>
> where codcon is a CodexContext* and frm is an AVFrame* wich are alloced
> proper.
> Then I call it:
>
> write_vid_frame((uint8_t**)im.bits(),im.bytesPerLine());
>
> where im is my QImage.At this point my programm crashes.
>
> All necessary initalization has been done.
>
> Greetings and have a nice christmas
>
> Alex
> _______________________________________________________________________
> Täglich 1.000.000 Euro gewinnen! Jetzt kostenlos WEB.DE MillionenKlick
> spielen! https://millionenklick.web.de/[email protected]@home
>
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to