[Libav-user] How to keep AVFrame data after codec close
eric.beuque at gmail.com
Thu Dec 5 10:33:11 CET 2013
Hi, i'm using libavcodec from FFMpeg 1.1.2.
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.
Here a sample program showing the function i use:
int main(int argc, char **argv)
AVCodec* pCodec = avcodec_find_decoder (CODEC_ID_MJPEG);
AVCodecContext* pAVContext = avcodec_alloc_context3 (pCodec);
avcodec_open2(pAVContext, pCodec, NULL);
std::string content = get_file_contents("../img1.jpg", iSize);
packet.data = (unsigned char*)content.c_str();
packet.size = iSize;
AVFrame* pFrame = avcodec_alloc_frame();
avcodec_decode_video2 (pAVContext, pFrame, &bGotPicture, &packet);
// Here pFrame->data is valid
// Here pFrame->data has been freed, access may crash
pFrame = NULL;
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
Is data memcpy the only way to do this?
Note, that i also can't upgrade to new version of FFMPEG.
Thanks for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libav-user