From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 65C4D47AC1 for ; Sun, 1 Oct 2023 12:56:41 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DEB5C68CDD6; Sun, 1 Oct 2023 15:56:15 +0300 (EEST) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37ABA68CDB4 for ; Sun, 1 Oct 2023 15:56:08 +0300 (EEST) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 18EE0526A for ; Sun, 1 Oct 2023 14:56:06 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id l-lUyumvfQrG for ; Sun, 1 Oct 2023 14:56:02 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 10228522E for ; Sun, 1 Oct 2023 14:56:02 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B31B93A25D1 for ; Sun, 1 Oct 2023 14:55:54 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 1 Oct 2023 14:55:48 +0200 Message-Id: <20231001125552.23976-5-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231001125552.23976-1-anton@khirnov.net> References: <20231001125552.23976-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/9] lavc/mpegvideo_parser: improve exporting field-coding information X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: * export AVCodecParserContext.picture_structure. * when there are two field pictures in the packet, set the interlacing parameters accordingly: * repeat_pict=1 and picture_structure=FRAME to indicate 2 fields * field_order to indicate the first field of the two --- libavcodec/mpegvideo_parser.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index 76cd2a5131..2cd0348317 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -111,9 +111,15 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, int bit_rate = 0; int vbv_delay = 0; enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; -//FIXME replace the crap with get_bits() - s->repeat_pict = 0; + // number of picture coding extensions (i.e. MPEG2 pictures) + // in this packet - should be 1 or 2 + int nb_pic_ext = 0; + // when there are two pictures in the packet this indicates + // which field is in the first of them + int first_field = AV_FIELD_UNKNOWN; + +//FIXME replace the crap with get_bits() while (buf < buf_end) { uint32_t start_code = -1; buf= avpriv_find_start_code(buf, buf_end, &start_code); @@ -124,7 +130,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, s->pict_type = (buf[1] >> 3) & 7; if (bytes_left >= 4) vbv_delay = ((buf[1] & 0x07) << 13) | (buf[2] << 5) | (buf[3] >> 3); - s->repeat_pict = 1; } break; case SEQ_START_CODE: @@ -190,6 +195,7 @@ FF_ENABLE_DEPRECATION_WARNINGS int progressive_frame = buf[4] & (1 << 7); /* check if we must repeat the frame */ + s->repeat_pict = 1; if (repeat_first_field) { if (pc->progressive_sequence) { if (top_field_first) @@ -208,6 +214,19 @@ FF_ENABLE_DEPRECATION_WARNINGS s->field_order = AV_FIELD_BB; } else s->field_order = AV_FIELD_PROGRESSIVE; + + s->picture_structure = buf[2] & 3; + + if (!nb_pic_ext) { + // remember parity of the first field for the case + // when there are 2 fields in packet + switch (s->picture_structure) { + case AV_PICTURE_STRUCTURE_BOTTOM_FIELD: first_field = AV_FIELD_BB; break; + case AV_PICTURE_STRUCTURE_TOP_FIELD: first_field = AV_FIELD_TT; break; + } + } + + nb_pic_ext++; } break; } @@ -243,6 +262,12 @@ FF_ENABLE_DEPRECATION_WARNINGS s->coded_width = FFALIGN(pc->width, 16); s->coded_height = FFALIGN(pc->height, 16); } + + if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO || nb_pic_ext > 1) { + s->repeat_pict = 1; + s->picture_structure = AV_PICTURE_STRUCTURE_FRAME; + s->field_order = nb_pic_ext > 1 ? first_field : AV_FIELD_PROGRESSIVE; + } } static int mpegvideo_parse(AVCodecParserContext *s, -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".