From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 6F2664BEE3 for ; Thu, 22 May 2025 22:34:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id D58D768DD85; Fri, 23 May 2025 01:34:03 +0300 (EEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 305D568DA5C for ; Fri, 23 May 2025 01:33:57 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 4A898432FC for ; Thu, 22 May 2025 22:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1747953236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nwY29Y37DkkqO1o+bU69zRX5Vd14sFSTgoILEWP5drM=; b=Nis9JP9ZNQvZ1+aCUBRzc+TpgcUkxPihYlWL2qFmT+JpX6aDiz25Dz7RO6R40URqon8kEd z0VXondJRXlVv9o/evabjsl3NbalDyq+hdUnHNVYIOBq6E2YvsKR3rYLHkto9ZzQmIk5/z 4rd5KGqTDqdj9GkXqciKA1MBfwPp7Nq5a3B/Hiuu4yDcxTd574eLYmJ2VJppurEB08msVL V/UwtMB/OyaxeEiER1eS6TU7PdLo6RO0bmoi9O4fw2AtkHyt9twawy/piGFYcjq6a1rSHo dmVpQIY34FZ5PnNrA1toY41VWcpCsTuyBNDQdbVeHiyIjQI65GM2XzLwB6Jsqg== Date: Fri, 23 May 2025 00:33:55 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20250522223355.GQ29660@pb2> References: <20250521132300.32387-1-derek.buitenhuis@gmail.com> MIME-Version: 1.0 In-Reply-To: <20250521132300.32387-1-derek.buitenhuis@gmail.com> X-GND-State: clean X-GND-Score: -85 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdejudejucdltddurdegfedvrddttddmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdduhedmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfpihgvuggvrhhmrgihvghruceomhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtqeenucggtffrrghtthgvrhhnpeeigeektdejudffjefhteegjedtgeettefggedthfejgfevhfetgeekjedtvdfhveenucfkphepgedurdeiiedrieejrdduudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepgedurdeiiedrieejrdduudefpdhhvghloheplhhotggrlhhhohhsthdpmhgrihhlfhhrohhmpehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgdpnhgspghrtghpthhtohepuddprhgtphhtthhopehffhhmphgvghdquggvvhgvlhesfhhfmhhpvghgrdhorhhg X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH v3] avformat/dhav: fix backward scanning for get_duration and optimize seeking 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 Content-Type: multipart/mixed; boundary="===============0702518754318389682==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============0702518754318389682== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Zgbii/ieujL2eaRx" Content-Disposition: inline --Zgbii/ieujL2eaRx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi On Wed, May 21, 2025 at 02:23:00PM +0100, Derek Buitenhuis wrote: > From: Justin Ruggles >=20 > The backwards scanning done for incomplete final packets should not > assume a specific alignment at the end of the file. Truncated files > result in hundreds of thousands of seeks if the final packet does not > fall on a specific byte boundary, which can be extremely slow. > For example, with HTTP, each backwards seek results in a separate > HTTP request. >=20 > This changes the scanning to check for the end tag 1 byte at a time > and buffers the last 1 MiB using ffio_ensure_seekback to avoid additional > seek operations. >=20 > Co-authored-by: Derek Buitenhuis > Signed-off-by: Justin Ruggles > Signed-off-by: Derek Buitenhuis > --- > libavformat/dhav.c | 54 +++++++++++++++++++++++++++++++++------------- > 1 file changed, 39 insertions(+), 15 deletions(-) >=20 > diff --git a/libavformat/dhav.c b/libavformat/dhav.c > index b2ead99609..d9db775802 100644 > --- a/libavformat/dhav.c > +++ b/libavformat/dhav.c > @@ -22,6 +22,7 @@ > =20 > #include > =20 > +#include "libavutil/intreadwrite.h" > #include "libavutil/mem.h" > #include "libavutil/parseutils.h" > #include "avio_internal.h" > @@ -232,37 +233,60 @@ static void get_timeinfo(unsigned date, struct tm *= timeinfo) > timeinfo->tm_sec =3D sec; > } > =20 > +#define MAX_DURATION_BUFFER_SIZE (1024*1024) > + > static int64_t get_duration(AVFormatContext *s) > { > int64_t start_pos =3D avio_tell(s->pb); > + int64_t end_pos =3D -1; > int64_t start =3D 0, end =3D 0; > struct tm timeinfo; > - int max_interations =3D 100000; > + uint8_t *end_buffer; > + int64_t end_buffer_size; > + int64_t end_buffer_pos; > + int64_t offset; > + unsigned date; > =20 > if (!s->pb->seekable) > return 0; > =20 > + if (start_pos + 16 > avio_size(s->pb)) > + return 0; > =20 > + avio_skip(s->pb, 16); > + date =3D avio_rl32(s->pb); > + get_timeinfo(date, &timeinfo); > + start =3D av_timegm(&timeinfo) * 1000LL; > + > + end_buffer_size =3D FFMIN(MAX_DURATION_BUFFER_SIZE, avio_size(s->pb)= ); > + end_buffer =3D av_malloc(end_buffer_size); > + if (!end_buffer) { > + avio_seek(s->pb, start_pos, SEEK_SET); > + return 0; > + } > + end_buffer_pos =3D avio_size(s->pb) - end_buffer_size; calling avio_size() multiple times and assuming its always teh same value feels risky to me thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The worst form of inequality is to try to make unequal things equal. -- Aristotle --Zgbii/ieujL2eaRx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCaC+mTwAKCRBhHseHBAsP q2dsAJ4s1bW7TL7XxKdWvZAnX7S8y/lcoACeOw4oDpb6a9bS+7uF67xymeexpkQ= =VO8O -----END PGP SIGNATURE----- --Zgbii/ieujL2eaRx-- --===============0702518754318389682== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============0702518754318389682==--