Commit e3803f99 authored by gferry's avatar gferry Committed by Andrey Kamaev

fix for OpenCV issue #2815

- libavcodec issue
- some decoders alter AVCodecContext width/height values, in a wrong way
- eg. in issue 2815, vp6f decoder changes these values, resulting in distorted / invalid frames
- this patch forces default AVCodecContext values
parent f0dce1fa
...@@ -560,6 +560,10 @@ bool CvCapture_FFMPEG::open( const char* _filename ) ...@@ -560,6 +560,10 @@ bool CvCapture_FFMPEG::open( const char* _filename )
if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0) if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0)
{ {
// backup encoder' width/height
int enc_width = enc->width;
int enc_height = enc->height;
AVCodec *codec = avcodec_find_decoder(enc->codec_id); AVCodec *codec = avcodec_find_decoder(enc->codec_id);
if (!codec || if (!codec ||
#if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0) #if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0)
...@@ -570,6 +574,10 @@ bool CvCapture_FFMPEG::open( const char* _filename ) ...@@ -570,6 +574,10 @@ bool CvCapture_FFMPEG::open( const char* _filename )
< 0) < 0)
goto exit_func; goto exit_func;
// checking width/height (since decoder can sometimes alter it, eg. vp6f)
if (enc_width && (enc->width != enc_width)) { enc->width = enc_width; }
if (enc_height && (enc->height != enc_height)) { enc->height = enc_height; }
video_stream = i; video_stream = i;
video_st = ic->streams[i]; video_st = ic->streams[i];
picture = avcodec_alloc_frame(); picture = avcodec_alloc_frame();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment