From patchwork Sun Oct 1 12:55:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 44080 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp849789pzf; Sun, 1 Oct 2023 05:56:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsFJCSTH+aUl3lMjZ00rFQkKw/ZIGE+Skt2/5wu21rlOv+kW8GkQkAE5gruNejTY4UA/Su X-Received: by 2002:a05:6402:1810:b0:52f:c073:9c37 with SMTP id g16-20020a056402181000b0052fc0739c37mr7394667edy.3.1696165003540; Sun, 01 Oct 2023 05:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696165003; cv=none; d=google.com; s=arc-20160816; b=S5j5pxrBpDHaYL3oAi2phUrAHhHKUtQ1W8yB0/2h1oWf85aWX40NAa25yu3wFtc8WD kwy0nvqrjC2pZjCSglOAEmho7N0S/WTrq7ifHAxy/y/DOlIKkcedSRTmSQMY3fqK99F6 a0lyQf66oWc1hAm9acig2GoWo9RZ6kjG+shdYUNTd+c/ZgB1PoDEOAglqXb4K6o2UEjw XCNiHXkv8I/acISj5Lmy0g8amqE8eyDf8cAxY9bFknoc4Zc/k6FmYnc0f5J2oPbcbdj5 zE/9qhIGxxzFAe4STSTdmCWeHPKz7Y09knS5tFRz8k6vWK70Fy/uAKpPcnqjNmAhAa9j wXpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=stUUhKAVFgWBeM+p8/qDLYCUTBd+olN8MetEwzY1q8k=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=mflByODQmbl1JMuu8Ougjtuvqj96fQls45WH7fDfUxvudoUp9m1rariisZCSO7LNAI 6ZDbE1eWuPQbGr7HAf2hkuyYjuayPi1K3mNemUxKODUJU8HZtmTagRE/urQDyYsy6CMZ 3Za/EkpsIWnfATJvd89jGEuaCGm9liierYIPCE03323Wk7c8aUAT5c8MtrYEV39eQirX ShHqXVc0mRqUi0GFpmlpvKeq20/pbBjswVf8uVl8yplhv/vA5nNA0P9rHsDKoi+76Nl5 /oKFITK9hpcPFHiVyncrtDUWjVymfm6tm7lk5utTh8ohw2nlgZKgxiqK6GqgrEcfkYa8 9zxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c8-20020aa7c748000000b0053320ad1187si18388344eds.577.2023.10.01.05.56.43; Sun, 01 Oct 2023 05:56:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1C12768CDD9; Sun, 1 Oct 2023 15:56:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UyyDiqDJRy61 * 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,