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 ESMTPS id 3B8604CE1C for ; Mon, 27 Jan 2025 03:55:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B251668B9EE; Mon, 27 Jan 2025 05:55:27 +0200 (EET) Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C39E68B0F4 for ; Mon, 27 Jan 2025 05:55:21 +0200 (EET) Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7b6ed9ed5b9so607708485a.2 for ; Sun, 26 Jan 2025 19:55:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737950119; x=1738554919; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7olJubEL+apGGdpWYqXRV6T0ZtQteOhnkvvwNpiLV3I=; b=EIY44+DZN9YO+HP2aNkEnlGa4ekm92+KFkxEi/GWRq7PslUR40n9dqHYmosrnDI766 BaAkwSvhV1/76Q/jUGgCIj7eMpa+Rb7oBXgy3l9f0G/fKsBnqih1GROMXBKBD2Aduw38 L9bkesb9CGOOnFP1GxiOt3EGHeH01FN1nR9Tkb49I32l2X1heiYfCSZfI/Zo1tHFc/Lx 5olxSOBdjRk/mIYcV76uwGGJzSq3ssXpCv272DabCadtqjUCbDf1grLWdbKgJUT3Vf5P 13p77pN2Zv8YV3xKR5a+GriRfyM7KI6UeOEvwMmV7gVuvix4Xbjw8x5ifJr1Hwh8a/ve 2fPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737950119; x=1738554919; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7olJubEL+apGGdpWYqXRV6T0ZtQteOhnkvvwNpiLV3I=; b=bx4jY6Dbd8ulLtSwen5uAl9bZe9ZL6pfnxzDVOiLa1hFlDw/9nPiuuXWHSxPwxEaDh Ib0RCrljWTK0uJVRdMtHlqFeBzRprfAros9fQQHe8pO/YjBcHQeblajrkM1NWrHI/6qT asJVWtMwiKWyek+rnS3X9OhQC1T6pmFK076XLNQrovzX6l/BKGXNLrbt9fjdfB12y4Kj GrPqM+dPoF6pAgvqEX91epCyhecqXKJvL1p9Jgf3LMLZimZZB1KIEGxLnKEr0/jO6Awh Fim9mDgkC4zVJ+DL3NdHIgVYd68+n9Y5Lxvc1P9FzGCNOTgEA5y3LbtK8nsdfeXCszrD Oo1w== X-Gm-Message-State: AOJu0YxWebvSrfzmt2k9hG2s26raXNS99IBbd6rzO9n1OKB1UUqG8N5i h+pdtCUJYqu9umXIlOwVhuzIAM6dnVYY3ywyIZnPt3jq6tb+MoeGcDcrTg== X-Gm-Gg: ASbGncv7/0+nfo3SKqe59uNif2i9/nBiK/LZdAI/Ali/65/O7Vl4TW1pIPeAOtTty+C qTwvvxqlS63Dqe4u4ioq3BreAcjlRKRT2PO1XflZtcZSIniRBNrG4m6LvKoa5nWCshQnIpDqvxJ Dox5eaH4uI+V0txXLk5T3akc78BirtXjLBqv/5TkgWcV3wbr/0YtWpeRmiZRY/RuXumar9mKHYY I6f257Xd3nqOBvQpdWLWyjGZKmY0Ftp9CtUu+X7iDjY27FnXsoWhtTLQ98K/c285xyKbOtACve/ tnbVGeh9box+F4rVi7K1kRNA05dh9wirWYCraHxJUbwK1XM3p4RTApGM0iVI4NOTLzQFDQ== X-Google-Smtp-Source: AGHT+IH3VaCJ6WgRha9iKRG4MLEIp/aYAq7XcZPVugNyCpPE7EHxtiKQ5EASeU+pSod6qzXbNvNyog== X-Received: by 2002:a05:620a:2452:b0:7b6:d420:7883 with SMTP id af79cd13be357-7be6320dd11mr5694994385a.33.1737950118772; Sun, 26 Jan 2025 19:55:18 -0800 (PST) Received: from craggy.ristobar.nom.menu (pool-108-50-194-163.nwrknj.fios.verizon.net. [108.50.194.163]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7be9ae9b0b1sm345700185a.65.2025.01.26.19.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2025 19:55:17 -0800 (PST) From: Gavin Li X-Google-Original-From: Gavin Li To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Jan 2025 22:54:05 -0500 Message-ID: <20250127035406.2213162-1-git@thegavinli.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 1/2] avformat/demux: use per-packet repeat_pict to calculate frame duration 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 Cc: Gavin Li 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: For h264/hevc, when using the raw demuxer, parse_packet() may parse multiple frames from a single input packet, depending on the setting of -raw_packet_size. The first parsed packet is returned from read_frame_internal(), while the subsequent parsed packets are stored in the parse queue, and returned in later calls to read_frame_internal(). However, during the increment of sti->info->codec_info_duration_fields, the repeat_pict value of the first parsed packet is reused for the rest of the packets in the parse queue. This causes the field count to be inaccurate in interlaced video with variable pic_struct values, particularly when -raw_packet_size is a large value. This can be demonstrated with the FATE sample h264-conformance/CVSE2_Sony_B.jsv: with the default -raw_packet_size of 1024, avg_frame_rate is incorrectly detected as 29.67 fps, while with a smaller -raw_packet_size of 128, avg_frame_rate is correctly detected as 29.97 fps. To fix this, store the repeat_pict value in AVPacket instead of AVCodecParserContext (where it would get overridden when processing subsequent packets), and use it to calculate the frame duration. Signed-off-by: Gavin Li --- libavcodec/packet.h | 5 +++++ libavformat/demux.c | 11 +++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/packet.h b/libavcodec/packet.h index c1f1ad7b43..c28174d7fb 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -581,6 +581,11 @@ typedef struct AVPacket { * or muxers. */ AVRational time_base; + + /** + * See AVFrame.repeat_pict for details. + */ + int repeat_pict; } AVPacket; #if FF_API_INIT_PACKET diff --git a/libavformat/demux.c b/libavformat/demux.c index d8ab29431e..5ac79dae49 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -710,16 +710,10 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, int ticks_per_frame = (sti->codec_desc && (sti->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1; av_reduce(pnum, pden, - codec_framerate.den, + codec_framerate.den * (1LL + (pc ? pkt->repeat_pict : 0)), codec_framerate.num * (int64_t)ticks_per_frame, INT_MAX); - if (pc && pc->repeat_pict) { - av_reduce(pnum, pden, - (*pnum) * (1LL + pc->repeat_pict), - (*pden), - INT_MAX); - } /* If this codec can be interlaced or progressive then we need * a parser to compute duration of a packet. Thus if we have * no parser in such case leave duration undefined. */ @@ -1241,6 +1235,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, out_pkt->pts = sti->parser->pts; out_pkt->dts = sti->parser->dts; out_pkt->pos = sti->parser->pos; + out_pkt->repeat_pict = sti->parser->repeat_pict; out_pkt->flags |= pkt->flags & (AV_PKT_FLAG_DISCARD | AV_PKT_FLAG_CORRUPT); if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) @@ -2819,7 +2814,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) } else sti->info->codec_info_duration += pkt->duration; sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && fields - ? sti->parser->repeat_pict + 1 : 2; + ? pkt->repeat_pict + 1 : 2; } } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { -- 2.47.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".