[Libav-user] (AVStream *)av_malloc(sizeof(AVStream)) crashed the application
cbhattac at adobe.com
Tue Oct 30 12:28:06 CET 2012
>> Hi Chandranath
>> But I already allocated memory for the pointer *ic_enc_mjpeg
OK. Sorry. I did not realize you meant the crash occurred even after allocation.
>> AVFormatContext *ic_enc_mjpeg;
>> ic_enc_mjpeg = (AVFormatContext *)av_malloc(sizeof(AVFormatContext));
>> Then I tried to allocate the memory for ic_enc_mjpeg->streams, then it crashed.
streams variable inside AVFormatContext is AVStream **. So the allocation of AVFormatContext using av_malloc is not supposed to initialize/allocate it. Hence the crash.
Check the documentation in header avformat.h for more info.
The crash can be fixed by the following code.
ic_enc_mjpeg = (AVFormatContext *)av_malloc(sizeof(AVFormatContext));
ic_enc_mjpeg->streams = (AVStream **)av_malloc(sizeof(AVStream *)); // <== DO THIS.
ic_enc_mjpeg->nb_streams = 1; // OR WHATEVER.
ic_enc_mjpeg->streams = (AVStream *)av_malloc(sizeof(AVStream));
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libav-user