From patchwork Fri Feb 2 18:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 45985 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a28:b0:199:de12:6fa6 with SMTP id cj40csp1122164pzb; Fri, 2 Feb 2024 10:17:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4twvtH5vQ+4X6TtY/2IxiP0Z2oTcyRT/iuNkiRklLi4sYTv48XsQxf0qiEQqJ3aTD/m0C X-Received: by 2002:a05:6402:125a:b0:55f:e584:221e with SMTP id l26-20020a056402125a00b0055fe584221emr265697edw.29.1706897837547; Fri, 02 Feb 2024 10:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706897837; cv=none; d=google.com; s=arc-20160816; b=nE4E7gqLdwKNUbtscARYpJiXOZXmzGMEww7MgbwZ96Uj1uOL+fVcTiEnvecNxHsrJw XL72gHIR8XgKKF0UOvCv1IIjxw4rgGXrwkRXIKfLFb4RQjCPr/IWRhWH5Viwy5C9Q8gD 5CzZ5Y9weUZk/k4viX7vaLyoq0wRIxND9Nua+WR81LiyXWPlLnhc4wKoS9tv83fe1Npq Usgnnx2P8/kemrOm7euFZuVtPsylmyOsMIT0nROccQdvOl/mEQU+dPltAgtra+h0xgsT XMQmpMIstXNj82JJ2kP5IPKmXGrnKGYjT6LnTQ7r1gqCp7WRRY9v7t+W406lDNqtlZ6K AV9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=7TmyVLOIG19ntAKwOyFCeitWXTwo7SBwLjbxJPio2lk=; fh=mExDH3ZB/Pc6Ch4rudHfIuTu9Yl6nG73hyi9XfGCgiI=; b=SsE3CDSE8xCTaZQQUEY3gpeiy8oAh1sbJFkKMNhu2Ipg4HhX+l93Q3Cf1zWRsjQ0/c 5unr0xnCgSZ1WYeIfQJWwUaAKEuVJ0RnTZjXI6YRu7x5wlNC1NJ987ldoXCImEz7G7K6 V0jrbf9jREvAT4GPWvRTF+nQ9DCzsQnuUotv5F0f5Fk18FNFaZL1YnHoaZTTpFsgdPUI 9M0/Z4G3b14HbZrR79yY5/bzb22XV4s1yEE6XIbGAFM+gbjRLOHGy9D+XTfWMootcDDw 3bIHeIEV40UrSE2Hie6AJpR8geXCIFbz7dZE0Km9ZDq+xNwgMTrn8GeQkmCvvEhOwyse ZF7A==; dara=google.com 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 X-Forwarded-Encrypted: i=0; AJvYcCVi5MNWYLcWmh7W9du/V5/oXd3MTQywVq1C3iHw2m80bR/+zHXnMojSEoLX+IcR6ythHd99OnFPjVSEGZHmrq9Rt8IqnQoJB/lu3ddWfUhNcguE4wALBtD2Q5bEBKE+V8H/QPOjD95Pq4xFi+hahhuPXi0jrY8KbCe4nraTT11G/uLUpeYEvSHblhZi66c1zGQ88LlRpDgCH10btIT27pXGlKR0S93lBtLV9OVeOo3rIw9xaJDGl1i4mI4cOyp4XjXyLQPjKTy3FjRLtjU2Fg9pOK+m5WsPNwKcHc9EIBGG1UvsGnr/Od04qkdA1fAr+M+PO6ltrxbGKQgbQVeeKISAT8dfYVadZO1p7PpQy7awBQv0sdBx3n4knxraDlL/XHe8hLghkhwhooSvpyK+V3lytl0FGfBJy3w43WjHnGpbdysuduWIyF+sbrf9VBAMJ0R6TD2d6Ikk42ZG1BGwK8TwViI4Rp7gEO+BxhGnCoPQv8xQqy9HbFgAbO8CCR4Gi/9sD2oPd9tARGmqB7xsG56oihN5cj1C6nZq354nNyrKinIWcJFKMBTVxmIJoh2O+QbCpD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P id b2-20020a05640202c200b0055ff9b0f092si630293edx.565.2024.02.02.10.17.16; Fri, 02 Feb 2024 10:17:17 -0800 (PST) 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 EFC8368D0ED; Fri, 2 Feb 2024 20:17:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: g4lLeaE46xiy 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);