From 00d1e96bf4fc0467744f840fbc85d1a65cbb6f08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= <Reimar.Doeffinger@gmx.de>
Date: Wed, 3 Nov 2010 20:52:28 +0000
Subject: [PATCH] H.264 decode: support cropping up to 28 pixels in interlaced
 mode. Contrary to progressive, just being able to crop up to 14/15 pixels is
 not enough to encode all supported resolutions, and the new behaviour is also
 consistent with e.g. MPEG-2 etc.

Originally committed as revision 25669 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavcodec/h264.c      | 2 +-
 libavcodec/h264_ps.c   | 2 +-
 libavcodec/mpegvideo.c | 2 +-
 libavcodec/utils.c     | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 6c2cdf81748..f99f7ea6ad7 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1810,7 +1810,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
     if(h->sps.frame_mbs_only_flag)
         s->height= 16*s->mb_height - 2*FFMIN(h->sps.crop_bottom, 7);
     else
-        s->height= 16*s->mb_height - 4*FFMIN(h->sps.crop_bottom, 3);
+        s->height= 16*s->mb_height - 4*FFMIN(h->sps.crop_bottom, 7);
 
     if (s->context_initialized
         && (   s->width != s->avctx->width || s->height != s->avctx->height
diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index d1479289fbf..876bcb2a433 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -373,7 +373,7 @@ int ff_h264_decode_seq_parameter_set(H264Context *h){
         if(sps->crop_left || sps->crop_top){
             av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ...\n");
         }
-        if(sps->crop_right >= 8 || sps->crop_bottom >= (8>> !sps->frame_mbs_only_flag)){
+        if(sps->crop_right >= 8 || sps->crop_bottom >= 8){
             av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, this could look slightly wrong ...\n");
         }
     }else{
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 1a2de3a4cbc..9650066ceea 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -498,7 +498,7 @@ av_cold int MPV_common_init(MpegEncContext *s)
 
     if(s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
         s->mb_height = (s->height + 31) / 32 * 2;
-    else
+    else if (s->codec_id != CODEC_ID_H264)
         s->mb_height = (s->height + 15) / 16;
 
     if(s->avctx->pix_fmt == PIX_FMT_NONE){
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 4d13e0aa6ea..36918772c80 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -140,7 +140,7 @@ void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int l
     case PIX_FMT_YUVA420P:
         w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
         h_align= 16;
-        if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP)
+        if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264)
             h_align= 32; // interlaced is rounded up to 2 MBs
         break;
     case PIX_FMT_YUV411P:
-- 
GitLab