[FFmpeg-devel] [PATCH]Decode broken v210 samples

Carl Eugen Hoyos cehoyos at ag.or.at
Fri Dec 16 23:37:49 CET 2011


Hi!

QuickTime specification states for v210 that:
Each line of video data in an image buffer is padded out to the nearest 128 
byte boundary.

Ticket 743 contains some evidence that not all applications are following this 
recommendation.

Unfortunately, I cannot play (any) v210 samples with QuickTime, so I cannot 
test if our interpretation of the specification is correct.

Please review, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
index 147f1f2..d424e28 100644
--- a/libavcodec/v210dec.c
+++ b/libavcodec/v210dec.c
@@ -84,6 +84,18 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         stride = aligned_width * 8 / 3;
     }
 
+    if (avpkt->size < stride * avctx->height) {
+        if ((((avctx->width + 23) / 24) * 24 * 8) / 3 * avctx->height == avpkt->size) {
+            stride = avpkt->size / avctx->height;
+            if (!s->stride_warning_shown)
+                av_log(avctx, AV_LOG_WARNING, "Broken v210 with too small padding (64 byte) detected\n");
+            s->stride_warning_shown = 1;
+        } else {
+            av_log(avctx, AV_LOG_ERROR, "packet too small\n");
+            return -1;
+        }
+    }
+
     aligned_input = !((uintptr_t)psrc & 0xf) && !(stride & 0xf);
     if (aligned_input != s->aligned_input) {
         s->aligned_input = aligned_input;
@@ -94,11 +106,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     if (pic->data[0])
         avctx->release_buffer(avctx, pic);
 
-    if (avpkt->size < stride * avctx->height) {
-        av_log(avctx, AV_LOG_ERROR, "packet too small\n");
-        return -1;
-    }
-
     pic->reference = 0;
     if (avctx->get_buffer(avctx, pic) < 0)
         return -1;
diff --git a/libavcodec/v210dec.h b/libavcodec/v210dec.h
index 48be729..1f06f9e 100644
--- a/libavcodec/v210dec.h
+++ b/libavcodec/v210dec.h
@@ -26,6 +26,7 @@ typedef struct {
     AVClass *av_class;
     int custom_stride;
     int aligned_input;
+    int stride_warning_shown;
     void (*unpack_frame)(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width);
 } V210DecContext;
 


More information about the ffmpeg-devel mailing list