Hi, I'm trying to work on bug 378 (
https://bugzilla.libav.org/show_bug.cgi?id=378) and have the h264 decoder
correctly interpret at least the right and bottom SPS cropping.
According to the documentation there coded_width and coded_height that
represent the bitstream size and width and height that represent the size
of what should be displayed.
So, as I got hinted on IRC, it should be possible to apply cropping at the
end of the decoding stage and so setting avcodeccontext width to
coded_width - right_cropping (and similarly for height).

However if I'm to not exactly sure *where* this should be done in libav
code: if I do that in h264_decode_end() I get a correct size, but the image
is just stretched, not cropped, while if I put it in decode_slice() I
either get a corrupt image or just a full size picture or a lot of error
messages (regarding MB decoding or reinitialization). I've pasted my
current modifications with the cropping applied in h264_decode_end().

What I'm doing wrong? Can anyone give me a few more pointers?
Vittorio

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index a903b7b..5351959 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2702,7 +2702,7 @@ static int decode_slice_header(H264Context *h,
H264Context *h0)

     s->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p

-    s->width = 16 * s->mb_width - (2 >> CHROMA444) *
FFMIN(h->sps.crop_right, (8 << CHROMA444) - 1);
+    s->width = 16 * s->mb_width;
     if (h->sps.frame_mbs_only_flag)
         s->height = 16 * s->mb_height - (1 << s->chroma_y_shift) *
FFMIN(h->sps.crop_bottom, (16 >> s->chroma_y_shift) - 1);
     else
@@ -4253,6 +4253,8 @@ static av_cold int h264_decode_end(AVCodecContext
*avctx)
     H264Context *h    = avctx->priv_data;
     MpegEncContext *s = &h->s;

+    s->avctx->width = s->avctx->coded_width - (2 >> CHROMA444) *
h->sps.crop_right;
+
     ff_h264_free_context(h);

     ff_MPV_common_end(s);
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to