From 9da4fe4b0203030940551cd8cc7421dbd77879f3 Mon Sep 17 00:00:00 2001 From: Sergiu Dotenco Date: Tue, 6 Oct 2015 15:09:31 +0200 Subject: [PATCH] videoio: fixed segmentation fault at frame size change --- modules/videoio/src/cap_ffmpeg_impl.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index 4f743ec76c..8f2efd5a65 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -750,9 +750,6 @@ bool CvCapture_FFMPEG::retrieveFrame(int, unsigned char** data, int* step, int* if( !video_st || !picture->data[0] ) return false; - avpicture_fill((AVPicture*)&rgb_picture, rgb_picture.data[0], AV_PIX_FMT_RGB24, - video_st->codec->width, video_st->codec->height); - if( img_convert_ctx == NULL || frame.width != video_st->codec->width || frame.height != video_st->codec->height ) @@ -775,8 +772,17 @@ bool CvCapture_FFMPEG::retrieveFrame(int, unsigned char** data, int* step, int* if (img_convert_ctx == NULL) return false;//CV_Error(0, "Cannot initialize the conversion context!"); + + rgb_picture.data[0] = (uint8_t*)realloc(rgb_picture.data[0], + avpicture_get_size( AV_PIX_FMT_BGR24, + video_st->codec->width, video_st->codec->height )); + frame.data = rgb_picture.data[0]; } + avpicture_fill((AVPicture*)&rgb_picture, rgb_picture.data[0], AV_PIX_FMT_RGB24, + video_st->codec->width, video_st->codec->height); + frame.step = rgb_picture.linesize[0]; + sws_scale( img_convert_ctx, picture->data,