videoio: fixed segmentation fault at frame size change

This commit is contained in:
Sergiu Dotenco 2015-10-06 15:09:31 +02:00
parent e2e25e9af3
commit 9da4fe4b02

View File

@ -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,