av_frame_free crashes when using av_frame_get_buffer

For the developers that use FFmpeg in their software.
Post Reply
Armando
Posts: 1
Joined: Mon Jul 02, 2018 6:29 pm

av_frame_free crashes when using av_frame_get_buffer

Post by Armando » Mon Jul 02, 2018 6:31 pm

Whenever a allocate an AVFrame* using the folling code:

Code: Select all

AVFrame *frame = av_frame_alloc();
frame->format = codec_context->pix_fmt;
frame->width = codec_context->width;
frame->height = codec_context->height;
if(av_frame_get_buffer(frame, 0) < 0){
    //handle error
}
And later try to free that frame* with

Code: Select all

av_frame_free(&frame);
, my program crashes... however, if I allocate the frame using:

Code: Select all

AVFrame *frame = av_frame_alloc();    
int num_bytes = av_image_get_buffer_size(codec_context->pix_fmt, codec_context->width, codec_context->height, 1);
buffer = (uint8_t*) av_malloc(num_bytes * sizeof(uint8_t));
av_image_fill_arrays(frame->data, frame->linesize, buffer, codec_context->pix_fmt, codec_context->width, codec_context->height, 1);
Then av_frame_free(&frame) does not crash. What am I doing wrong? What are the differences of allocating my frame these 2 ways? Thanks for any help!

c++ c ffmpeg

Post Reply