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 B4617492A3 for ; Tue, 6 Feb 2024 23:52:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 249E668CF10; Wed, 7 Feb 2024 01:52:16 +0200 (EET) Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 84D4668CAB8 for ; Wed, 7 Feb 2024 01:52:09 +0200 (EET) Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5601eb97b29so183222a12.0 for ; Tue, 06 Feb 2024 15:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707263529; x=1707868329; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=xXqH1JucvnBOunreyE8SeeCTuzxKED7+6vILDsj1hn0=; b=CcWC7BLkron4shNsmhBRVqMP4pA3SO3tpy1WW25/VoSr7JNC1SiPrAq5tV8xW3uhFY bEIuzFru1+dlXAb17473tYM1mBoNUSIBksXNtDPz/Z5CKL2OqxtYV2JOYejvfgaQvppg Tq1yQkSFzVLnIUZ6CVdsO09Gv3Sh6zsZi4ArLEYvcxvWfj86th35D5C+Ew+b8pM5pdmC ERrPovKSel+5ZHiFQaF0k54ZVg8SmtwgXZswfGxJJdltxGURSUfC+X7Kag7/4lKrSSMI fGUtXjv2U1wO+y9LAveMVcTneOdDQZ7beh5vVYS/2DTSOB8GlVhyEX4K1HGntyrHGPVJ a7ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707263529; x=1707868329; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xXqH1JucvnBOunreyE8SeeCTuzxKED7+6vILDsj1hn0=; b=cc8xyzXphIO+Gz5KiVkmosQfgebupI0/LIfGIxLGAperNWFo88IxC4aE3x7Oxt9Tof 55+afajQj4JkTJolSYaVWl44LMbpkP0vxlZaqHEtQkSe2g0D1RVfrulUwdsWQiln5wBx EzoSj1DsPmJc7YgBnxA3Qx2kW7DgD7r79OBzkUwB3h+2td3b1JM3vEOyZG4shBGLw895 ZXru0fi9soo1MsYCg8DAjH4jGx5aflPdHhB7eiaCF2llelLoiiRKlIdbhMtS5GnDySje vKJY9LrYM6G+3nB2QSHe1ZBkkN1jbeXhhRyQSFVvHcTXJR/asOFNpPPiiJrQqEznwhUf 4T1Q== X-Gm-Message-State: AOJu0YzMPpFWJS70CPhn2K3wUpq6rTbtGuJY5QQ9vqbXaZBw7KQTVW2D vkcQakqf2bwYzEORnwEP7BrKQFyfZ1KjPPH++NFHygn6VNb0zGzsyj+MgMxf X-Google-Smtp-Source: AGHT+IH3EV7401CP16ZlwHPO+WG6Q0+CIVldhSM8HAwEr9/dqvbBHv2UeQ1uk9lMVhS/zuMe8oJeFw== X-Received: by 2002:a50:cc98:0:b0:55f:d6b9:245f with SMTP id q24-20020a50cc98000000b0055fd6b9245fmr12255912edi.6.1707263528602; Tue, 06 Feb 2024 15:52:08 -0800 (PST) Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it. [84.220.189.10]) by smtp.gmail.com with ESMTPSA id p5-20020a05640243c500b00560c6ff443esm50870edc.66.2024.02.06.15.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 15:52:08 -0800 (PST) Received: by mariano (Postfix, from userid 1000) id 2632DBFCDC; Wed, 7 Feb 2024 00:52:07 +0100 (CET) Date: Wed, 7 Feb 2024 00:52:07 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches , Nicolas Gaullier References: <20240206105209.315221-1-nicolas.gaullier@cji.paris> <20240206105209.315221-2-nicolas.gaullier@cji.paris> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240206105209.315221-2-nicolas.gaullier@cji.paris> User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH 1/1] avformat/demux: Add durationprobesize AVOption 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: On date Tuesday 2024-02-06 11:52:09 +0100, Nicolas Gaullier wrote: > Yet another probesize used to get the last pts (and thus the duration) > of mpegts/ps files. It is aimed at users interested in better durations probing > for itself, or because using avformat_find_stream_info indirectly and requiring > exact values: for concatdec for exemple, especially if streamcopying above it. nit: exemple typo > The current code does not behave well with high bitrates and high video buffering > (physical gap between the last video packet and the last audio packet). > > Default behaviour is unchanged: 250k up to 250k << 6 (step by step) > Setting this new option has two effects: > - override the maximum probesize (currently 250k << 6) > - reduce the number of steps to 1 instead of 6, this is to avoid detecting > the audio "too early" and failing to reach a video packet. Here, even if audio > duration is found but not the video duration, there will be a retry, so at the > end the full user-overriden probesize will be used. > > Signed-off-by: Nicolas Gaullier > --- > libavformat/avformat.h | 8 ++++++++ > libavformat/demux.c | 13 ++++++++----- > libavformat/options_table.h | 1 + > 3 files changed, 17 insertions(+), 5 deletions(-) please add missing user doc in doc/formats.texi (you might reuse the hightlight above to explain why this is needed), also the new field requires an entry in doc/APIChanges > diff --git a/libavformat/avformat.h b/libavformat/avformat.h > index 5d0fe82250..533f5a963d 100644 > --- a/libavformat/avformat.h > +++ b/libavformat/avformat.h > @@ -1823,6 +1823,14 @@ typedef struct AVFormatContext { > * Freed by libavformat in avformat_free_context(). > */ > AVStreamGroup **stream_groups; > + > + /** > + * Maximum number of bytes read at the end of input in order to determine the > + * stream durations. Used by avformat_find_stream_info() for MPEG-TS/PS. let's clarify this: is there any reason why this should not be used with other formats? If this the case, probably a private option would be best. If not, probably we should amend the doxy as it suggests it is only useful with MPEG TS/PS. > + * > + * Demuxing only, set by the caller before avformat_open_input(). > + */ > + int64_t duration_probesize; > } AVFormatContext; > > /** > diff --git a/libavformat/demux.c b/libavformat/demux.c > index 6f640b92b1..798b44c979 100644 > --- a/libavformat/demux.c > +++ b/libavformat/demux.c > @@ -1740,8 +1740,9 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) > "Estimating duration from bitrate, this may be inaccurate\n"); > } > > -#define DURATION_MAX_READ_SIZE 250000LL > -#define DURATION_MAX_RETRY 6 > +#define DURATION_MAX_READ_SIZE_DEFAULT 250000LL > +#define DURATION_MAX_RETRY_DEFAULT 6 > +#define DURATION_MAX_RETRY_USER 1 > > /* only usable for MPEG-PS streams */ > static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) > @@ -1749,6 +1750,8 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) > FFFormatContext *const si = ffformatcontext(ic); > AVPacket *const pkt = si->pkt; > int num, den, read_size, ret; > + int64_t duration_max_read_size = ic->duration_probesize ? ic->duration_probesize >> DURATION_MAX_RETRY_USER : DURATION_MAX_READ_SIZE_DEFAULT; > + int duration_max_retry = ic->duration_probesize ? DURATION_MAX_RETRY_USER : DURATION_MAX_RETRY_DEFAULT; > int found_duration = 0; > int is_end; > int64_t filesize, offset, duration; > @@ -1784,7 +1787,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) > filesize = ic->pb ? avio_size(ic->pb) : 0; > do { > is_end = found_duration; > - offset = filesize - (DURATION_MAX_READ_SIZE << retry); > + offset = filesize - (duration_max_read_size << retry); > if (offset < 0) > offset = 0; > > @@ -1793,7 +1796,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) > for (;;) { > AVStream *st; > FFStream *sti; > - if (read_size >= DURATION_MAX_READ_SIZE << (FFMAX(retry - 1, 0))) > + if (read_size >= duration_max_read_size << (FFMAX(retry - 1, 0))) > break; > > do { > @@ -1847,7 +1850,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) > } > } while (!is_end && > offset && > - ++retry <= DURATION_MAX_RETRY); > + ++retry <= duration_max_retry); > > av_opt_set_int(ic, "skip_changes", 0, AV_OPT_SEARCH_CHILDREN); > > diff --git a/libavformat/options_table.h b/libavformat/options_table.h > index 91708de453..c2bdb484a7 100644 > --- a/libavformat/options_table.h > +++ b/libavformat/options_table.h > @@ -108,6 +108,7 @@ static const AVOption avformat_options[] = { > {"max_streams", "maximum number of streams", OFFSET(max_streams), AV_OPT_TYPE_INT, { .i64 = 1000 }, 0, INT_MAX, D }, > {"skip_estimate_duration_from_pts", "skip duration calculation in estimate_timings_from_pts", OFFSET(skip_estimate_duration_from_pts), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D}, > {"max_probe_packets", "Maximum number of packets to probe a codec", OFFSET(max_probe_packets), AV_OPT_TYPE_INT, { .i64 = 2500 }, 0, INT_MAX, D }, > +{"durationprobesize", "maximum number of bytes to probe the stream durations", OFFSET(duration_probesize), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX, D}, duration_probesize? ... to probe the stream duration (why the plural?) _______________________________________________ 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".