[Ffmpeg-devel] Re: img_convert crashes

Mohnhaupt, Denis Denis.Mohnhaupt
Wed Aug 23 09:10:33 CEST 2006



this is the code I used to decode the video, where the error occurs


global Variables are


AVFormatContext *pFormatCtx;

int             i, videoStream;

AVCodecContext  *pCodecCtx;

AVCodec         *pCodec;

AVFrame         *pFrame; 

AVFrame         *pFrameRGB;

int             numBytes;

int             framecounter;






void get_next_frame(int *success, unsigned char picture[])


    int frameFinished;

    static AVPacket packet;

    int line=0;

    int byte=0;

    int lineInv;

    bool bIsVideo;

    int xbuffer, ybuffer; //these contain the dimensions of the video
frame or the texture, whichever are smaller


   while((av_read_frame(pFormatCtx, &packet)>=0) )


        bIsVideo = false;

        // Is this a packet from the video stream?



                        bIsVideo = true;

            // Decode video frame

            avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, 

                packet.data, packet.size);


            // Did we get a video frame?





printf("Debug: attempting to convert image to RGB...\n");

              // Convert the image from its native format to RGB

              img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,

                        (AVPicture*)pFrame, pCodecCtx->pix_fmt,



printf("Debug: RGB conversion done...\n");



              //copy image linewise to the buffer which is used to
update the texture

              for(line = 0; line < ybuffer; line = line +1)


                lineInv = ybuffer - line - 1; //the picture is
y-inverted, so we have to flip lines

                for(byte = 0; byte < (xbuffer*3); byte++)


                  picture[byte + (lineInv*xbuffer*3)] = (unsigned char)




        // Free the packet that was allocated by av_read_frame


        if(frameFinished && bIsVideo)



            break; //we got our video frame




    *success = frameFinished; 






Thanks for your help.


Kind regards,


More information about the ffmpeg-devel mailing list