From 2c9106257ffca8faef367a410c16bd8220942f6e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 12 Nov 2016 12:31:35 +0100 Subject: [PATCH] avcodec/mpeg4videodec: Workaround interlaced mpeg4 edge MC bug Signed-off-by: Michael Niedermayer --- libavcodec/avcodec.h | 1 + libavcodec/mpeg4videodec.c | 7 +++++++ libavcodec/mpegvideo.c | 2 ++ libavcodec/mpegvideo_motion.c | 4 ++++ libavcodec/options_table.h | 1 + 5 files changed, 15 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 211112fe9f..e5e7f4225d 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2878,6 +2878,7 @@ typedef struct AVCodecContext { #define FF_BUG_DC_CLIP 4096 #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. #define FF_BUG_TRUNCATED 16384 +#define FF_BUG_IEDGE 32768 /** * strictly follow the standard (MPEG-4, ...). diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 3adf28d2f8..1a2771a1f9 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -2195,6 +2195,13 @@ int ff_mpeg4_workaround_bugs(AVCodecContext *avctx) if (ctx->lavc_build <= 4712U) s->workaround_bugs |= FF_BUG_DC_CLIP; + if ((ctx->lavc_build&0xFF) >= 100) { + if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752552 && + (ctx->lavc_build < 3752037 || ctx->lavc_build > 3752191) // 3.2.1+ + ) + s->workaround_bugs |= FF_BUG_IEDGE; + } + if (ctx->divx_version >= 0) s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; if (ctx->divx_version == 501 && ctx->divx_build == 20020416) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 59be078262..e5424cbacf 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -2117,6 +2117,8 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; uint8_t *vbuf =ubuf + 10 * s->uvlinesize; + if (s->workaround_bugs & FF_BUG_IEDGE) + vbuf -= s->uvlinesize; s->vdsp.emulated_edge_mc(ubuf, ptr_cb, uvlinesize >> field_based, uvlinesize >> field_based, 9, 9 + field_based, diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c index b97a6cb303..a310bd4690 100644 --- a/libavcodec/mpegvideo_motion.c +++ b/libavcodec/mpegvideo_motion.c @@ -327,6 +327,8 @@ void mpeg_motion_internal(MpegEncContext *s, if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; uint8_t *vbuf = ubuf + 10 * s->uvlinesize; + if (s->workaround_bugs & FF_BUG_IEDGE) + vbuf -= s->uvlinesize; uvsrc_y = (unsigned)uvsrc_y << field_based; s->vdsp.emulated_edge_mc(ubuf, ptr_cb, s->uvlinesize, s->uvlinesize, @@ -550,6 +552,8 @@ static inline void qpel_motion(MpegEncContext *s, if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; uint8_t *vbuf = ubuf + 10 * s->uvlinesize; + if (s->workaround_bugs & FF_BUG_IEDGE) + vbuf -= s->uvlinesize; s->vdsp.emulated_edge_mc(ubuf, ptr_cb, s->uvlinesize, s->uvlinesize, 9, 9 + field_based, diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index e5cc7bfa29..ba5297c76c 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -163,6 +163,7 @@ static const AVOption avcodec_options[] = { {"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"}, {"ms", "work around various bugs in Microsoft's broken decoders", 0, AV_OPT_TYPE_CONST, {.i64 = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"}, {"trunc", "truncated frames", 0, AV_OPT_TYPE_CONST, {.i64 = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"}, +{"iedge", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_BUG_IEDGE }, INT_MIN, INT_MAX, V|D, "bug"}, {"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"}, {"very", "strictly conform to a older more strict version of the spec or reference software", 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, A|V|D|E, "strict"}, {"strict", "strictly conform to all the things in the spec no matter what the consequences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},