[FFmpeg-devel] [PATCH] Fix distortion problem in MPEG1/2 video
Heesuk Jung
hsjung1305 at gmail.com
Fri May 10 08:13:51 CEST 2013
In some MPEG1/2 AVI files, there are video distortion problem in bottom of screen.
(I just test files using ffplay)
1. MPEG1 video problematic file link
- https://docs.google.com/open?id=0B6r7ZfWFIypCMkltZHJDY0pQN1U
2. MPEG2 video problematic file link
- https://docs.google.com/open?id=0B6r7ZfWFIypCM0ZremxpbXc1N3c
Root cause of this problem is wrong frame size based on header information.
Suggests to use full parsing option after checking frame size within some frames in order
to prevent performance loss.
Please refer the concern of performance loss at my previous patch.
(http://ffmpeg.org/pipermail/ffmpeg-devel/2012-November/134186.html)
---
libavcodec/mpegvideo_parser.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index f127218..dddc11f 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -24,6 +24,10 @@
#include "mpeg12.h"
#include "internal.h"
+#define MAX_RETRY_FULL_PARSING 7
+
+static uint8_t retry_num = 0;
+
struct MpvParseContext {
ParseContext pc;
AVRational frame_rate;
@@ -160,6 +164,16 @@ static int mpegvideo_parse(AVCodecParserContext *s,
ParseContext *pc= &pc1->pc;
int next;
+ if (retry_num < MAX_RETRY_FULL_PARSING &&
+ s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+ int measured_buf_size;
+ measured_buf_size = ff_mpeg1_find_frame_end(pc, buf, buf_size, s);
+
+ if (measured_buf_size > 0 && measured_buf_size < buf_size)
+ s->flags &= ~PARSER_FLAG_COMPLETE_FRAMES;
+ }
+ retry_num++;
+
if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
next= buf_size;
}else{
@@ -204,6 +218,7 @@ static int mpegvideo_split(AVCodecContext *avctx,
static int mpegvideo_parse_init(AVCodecParserContext *s)
{
s->pict_type = AV_PICTURE_TYPE_NONE; // first frame might be partial
+ retry_num = 0;
return 0;
}
--
1.8.1.2
More information about the ffmpeg-devel
mailing list