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 B2E8A472C8 for ; Fri, 2 Feb 2024 18:17:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B3BAF68D0E9; Fri, 2 Feb 2024 20:17:12 +0200 (EET) Received: from srv-infra-1.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 435E168ABB5 for ; Fri, 2 Feb 2024 20:17:06 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 6BDAD20642; Fri, 2 Feb 2024 18:07:26 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Feb 2024 19:07:19 +0100 Message-Id: <20240202180719.784910-1-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/demux: Add more retries to get more stream durations 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: Nicolas Gaullier 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: The number of extra retries to get more than a single duration is currently limited to 1 (see commit 77a0df4b5). This patch raises this number of retries to 3 (amongst the overall 6 max retries). Exemple: this sample requires 3 retries to get all durations: http://samples.ffmpeg.org/archive/extension/ts/ mpegts+mpeg2video+ac3++mpegts_multiple_ts_packets_pmt_pid_0x50.ts Moreover, when an mpegts file is cleany cut at a precise pts independantly for audio and video, it results in a big gap between the last video packet and the last audio packet. And above the probing benefits themselves, having all durations is somewhat recommanded for using concatdec, and even required when using concatdec with streamcopy. Signed-off-by: Nicolas Gaullier --- libavformat/demux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index 6f640b92b1..f489868d34 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1742,6 +1742,7 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) #define DURATION_MAX_READ_SIZE 250000LL #define DURATION_MAX_RETRY 6 +#define MORE_DURATIONS_MAX_RETRY 3 /* only usable for MPEG-PS streams */ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) @@ -1753,6 +1754,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) int is_end; int64_t filesize, offset, duration; int retry = 0; + int retry_get_more_durations = 0; /* flush packet queue */ ff_flush_packet_queue(ic); @@ -1783,7 +1785,6 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) /* XXX: may need to support wrapping */ filesize = ic->pb ? avio_size(ic->pb) : 0; do { - is_end = found_duration; offset = filesize - (DURATION_MAX_READ_SIZE << retry); if (offset < 0) offset = 0; @@ -1833,7 +1834,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) } /* check if all audio/video streams have valid duration */ - if (!is_end) { + if (found_duration) { is_end = 1; for (unsigned i = 0; i < ic->nb_streams; i++) { const AVStream *const st = ic->streams[i]; @@ -1846,6 +1847,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) } } } while (!is_end && + (!found_duration || ++retry_get_more_durations <= MORE_DURATIONS_MAX_RETRY) && offset && ++retry <= DURATION_MAX_RETRY); -- 2.30.2 _______________________________________________ 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".