[FFmpeg-devel] [PATCH 2/2] ffv1dec: Ensure that pixel format constraints are respected

Vittorio Giovara vittorio.giovara at gmail.com
Tue Jul 17 22:39:19 EEST 2018


YUV410P requires that sizes are divisible by 4. There are some encoders
(including ffmpeg's) that ignore this constraint and encode a different
value in the bitstream itself. Handle that case by exporting the relative
cropping information.
---
Alternatively it is possible to always enforce mod4 sizes and call
it a day. I haven't explored ways to fix the encoder (or if other
decoders are affected).
Vittorio

 libavcodec/ffv1dec.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 7658a51685..8ff0f0deb8 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -971,6 +971,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
     if ((ret = av_frame_ref(data, f->picture.f)) < 0)
         return ret;
 
+    if (p->format == AV_PIX_FMT_YUV410P) {
+        p->crop_left   = 0;
+        p->crop_top    = 0;
+        p->crop_right  = FFALIGN(p->width,  4) - p->width;
+        p->crop_bottom = FFALIGN(p->height, 4) - p->height;
+    }
+
     *got_frame = 1;
 
     return buf_size;
@@ -1091,5 +1098,5 @@ AVCodec ff_ffv1_decoder = {
     .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
     .capabilities   = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/ |
                       AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
-    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_EXPORTS_CROPPING,
 };
-- 
2.17.1



More information about the ffmpeg-devel mailing list