<div dir="ltr"><div><div><div><div><div>Hi, i'm using libavcodec from FFMpeg 1.1.2.<br><br></div>I'm decoding MJPEG stream. My problem is that i need to keep a reference to the decoded frame, after the codec close. But when using avcodec_close, it freed the AVFrame data.<br>

<br></div>Here a sample program showing the function i use:<br><br>int main(int argc, char **argv)<br>{<br>    int bGotPicture;<br><br>    avcodec_register_all();<br>    <br>    AVCodec* pCodec = avcodec_find_decoder (CODEC_ID_MJPEG);<br>

    AVCodecContext* pAVContext = avcodec_alloc_context3 (pCodec);<br><br>    avcodec_open2(pAVContext, pCodec, NULL);<br><br>    AVPacket packet;<br>    av_init_packet (&packet);<br><br>    size_t iSize;<br>    std::string content = get_file_contents("../img1.jpg", iSize);<br>

    packet.data = (unsigned char*)content.c_str();<br>    packet.size = iSize;<br><br>    AVFrame* pFrame = avcodec_alloc_frame();<br>    avcodec_decode_video2 (pAVContext, pFrame, &bGotPicture, &packet);<br><br>
    // Here pFrame->data is valid<br>
<br>    av_free_packet(&packet);<br>    avcodec_close(pAVContext);<br>    av_free(pAVContext);<br><br>    // Here pFrame->data has been freed, access may crash<br><br>    av_free(pFrame);<br>    pFrame = NULL;<br>
}<br>
<br></div>How i can tell libavcodec that i want to become the owner of the data and be able to free it, to without codec context instance? I was thinking about using get/release_buffer functions, but i don't know how to compute size of the data.<br>

<br></div>Is data memcpy the only way to do this?<br><br></div>Note, that i also can't upgrade to new version of FFMPEG.<br><br>Thanks for your help.<br></div>