[FFmpeg-devel] [PATCH] avcodec/h263dec: add mb_pos_size & mmb options which allow debuging damaged videos

Michael Niedermayer michaelni at gmx.at
Mon May 5 02:55:07 CEST 2014


From: arnezami <@>

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavcodec/avcodec.h       |    9 ++++++++
 libavcodec/h263dec.c       |   49 ++++++++++++++++++++++++++++++++++++++++++++
 libavcodec/options_table.h |    2 ++
 3 files changed, 60 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index c191d23..0c96119 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2589,6 +2589,7 @@ typedef struct AVCodecContext {
 #define FF_DEBUG_BUFFERS     0x00008000
 #define FF_DEBUG_THREADS     0x00010000
 #define FF_DEBUG_NOMC        0x01000000
+#define FF_DEBUG_MB_POS_SIZE 0x02000000
 
 #if FF_API_DEBUG_MV
     /**
@@ -3066,6 +3067,14 @@ typedef struct AVCodecContext {
      * - decoding: unused.
      */
     uint16_t *chroma_intra_matrix;
+
+    /**
+     * Instructions to move the bitpositions of macroblocks
+     * - decoding: set by user
+     * - encoding: unused
+     */
+    char *mmb;
+
 } AVCodecContext;
 
 AVRational av_codec_get_pkt_timebase         (const AVCodecContext *avctx);
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 474714e..8b6cdd4 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -27,6 +27,7 @@
 
 #define UNCHECKED_BITSTREAM_READER 1
 
+#include "libavutil/avstring.h"
 #include "libavutil/cpu.h"
 #include "avcodec.h"
 #include "error_resilience.h"
@@ -167,6 +168,33 @@ static int get_consumed_bytes(MpegEncContext *s, int buf_size)
     }
 }
 
+static int get_bitpos_from_mmb_part (int mb_x, int mb_y, const char *mmb_part) {
+    int bitpos = -1;
+    int mmb_x, mmb_y, mmb_pos;
+
+    if (sscanf(mmb_part, "%d:%d:%d", &mmb_x, &mmb_y, &mmb_pos) == 3) {
+        if (mb_x == mmb_x && mb_y == mmb_y) {
+            bitpos = mmb_pos;
+        }
+    }
+
+    return bitpos;
+}
+
+static int get_bitpos_from_mmb (int mb_x, int mb_y, const char *mmb) {
+    int bitpos = -1;
+
+    while (bitpos < 0 && mmb && *mmb) {
+        char *token = av_get_token(&mmb, ",");
+        if (*mmb)
+            mmb++;
+        bitpos = get_bitpos_from_mmb_part(mb_x, mb_y, token);
+        av_free(token);
+    }
+
+    return bitpos;
+}
+
 static int decode_slice(MpegEncContext *s)
 {
     const int part_mask = s->partitioned_frame
@@ -223,6 +251,19 @@ static int decode_slice(MpegEncContext *s)
         ff_init_block_index(s);
         for (; s->mb_x < s->mb_width; s->mb_x++) {
             int ret;
+            int bit_count_before_decode;
+
+            av_dlog(s, "%d %d %06X\n",
+                    ret, get_bits_count(&s->gb), show_bits(&s->gb, 24));
+
+            if (s->avctx->mmb) {
+                int new_bitpos = get_bitpos_from_mmb(s->mb_x, s->mb_y, s->avctx->mmb);
+
+                if (new_bitpos >= 0) {
+                    int bit_count_now = get_bits_count(&s->gb);
+                    skip_bits(&s->gb, new_bitpos - bit_count_now);
+                }
+            }
 
             ff_update_block_index(s);
 
@@ -233,12 +274,20 @@ static int decode_slice(MpegEncContext *s)
 
             s->mv_dir  = MV_DIR_FORWARD;
             s->mv_type = MV_TYPE_16X16;
+
             av_dlog(s, "%d %d %06X\n",
                     ret, get_bits_count(&s->gb), show_bits(&s->gb, 24));
 
             tprintf(NULL, "Decoding MB at %dx%d\n", s->mb_x, s->mb_y);
+
+            bit_count_before_decode = get_bits_count(&s->gb);;
+
             ret = s->decode_mb(s, s->block);
 
+            if (s->avctx->debug & FF_DEBUG_MB_POS_SIZE) {
+                av_log(s->avctx, AV_LOG_DEBUG, "MB pos/size: %d %02d:%02d:%d %d\n", ret, s->mb_x, s->mb_y, bit_count_before_decode, get_bits_count(&s->gb) - bit_count_before_decode );
+            }
+
             if (s->pict_type != AV_PICTURE_TYPE_B)
                 ff_h263_update_motion_val(s);
 
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index f115ea7..986ca96 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -234,6 +234,7 @@ static const AVOption avcodec_options[] = {
 {"pict", "picture info", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_PICT_INFO }, INT_MIN, INT_MAX, V|D, "debug"},
 {"rc", "rate control", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_RC }, INT_MIN, INT_MAX, V|E, "debug"},
 {"bitstream", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_BITSTREAM }, INT_MIN, INT_MAX, V|D, "debug"},
+{"mb_pos_size", "macroblock x, y, bitposition and bitsize", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_MB_POS_SIZE }, INT_MIN, INT_MAX, V|D, "debug"},
 {"mb_type", "macroblock (MB) type", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_MB_TYPE }, INT_MIN, INT_MAX, V|D, "debug"},
 {"qp", "per-block quantization parameter (QP)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_DEBUG_QP }, INT_MIN, INT_MAX, V|D, "debug"},
 #if FF_API_DEBUG_MV
@@ -414,6 +415,7 @@ static const AVOption avcodec_options[] = {
 {"bb", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_FIELD_BB }, 0, 0, V|D|E, "field_order" },
 {"tb", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_FIELD_TB }, 0, 0, V|D|E, "field_order" },
 {"bt", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_FIELD_BT }, 0, 0, V|D|E, "field_order" },
+{"mmb", "move the bitposition of macroblocks", OFFSET(mmb), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|D},
 {NULL},
 };
 
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list