<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 5, 2013 at 12:41 PM, Paul B Mahol <span dir="ltr"><<a href="mailto:onemda@gmail.com" target="_blank">onemda@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5">On 12/5/13, Eric Beuque <<a href="mailto:eric.beuque@gmail.com">eric.beuque@gmail.com</a>> wrote:<br>


> Hi, i'm using libavcodec from FFMpeg 1.1.2.<br>
><br>
> I'm decoding MJPEG stream. My problem is that i need to keep a reference to<br>
> the decoded frame, after the codec close. But when using avcodec_close, it<br>
> freed the AVFrame data.<br>
><br>
> 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>
> How i can tell libavcodec that i want to become the owner of the data and<br>
> be able to free it, to without codec context instance? I was thinking about<br>
> using get/release_buffer functions, but i don't know how to compute size of<br>
> the data.<br>
><br>
> Is data memcpy the only way to do this?<br>
><br>
> Note, that i also can't upgrade to new version of FFMPEG.<br>
><br>
> Thanks for your help.<br>
><br>
<br>
</div></div>Use reference counting system.<br>
They you need to manually free frame once you will not need it<br>
(otherwise you leak memory), so you do not need to do copy.<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
</blockquote></div><br></div><div class="gmail_extra">Thank you for your answer, i saw that av_frame_ref/av_frame_unref is avaliable in FFMpeg 2.0, but i'm using 1.1.2, and I don't find any way to use reference couting in this version. Is this feature available in 1.1.x throught some others functions?<br>

</div><div class="gmail_extra"><br></div></div>