From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 4A2754BA3E for <ffmpegdev@gitmailbox.com>; Thu, 27 Mar 2025 18:18:41 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7C015687C72; Thu, 27 Mar 2025 20:18:36 +0200 (EET) Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02olkn2109.outbound.protection.outlook.com [40.92.50.109]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D080D687BD6 for <ffmpeg-devel@ffmpeg.org>; Thu, 27 Mar 2025 20:18:29 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xOGywsSvsTidK8mrv9ay8wO/en8qYxgkGledLRb6UwZ3Zew73g5xZVX6fkIJCz6amrcp3/xMIzSnRBLvCOqOfFvStpRc9FkPAPR3gXiGSfgLJ5jZo/cTrJorJXrPEOrOpnfqZ1DWKtUddFfg5Is5B6HDvN4Sf1bHWgcR65BtX7YtuJUiXrcrzADKzbotKzbq3X+bfg4oYXwnnaJ92YWW0wsr6XMYhsNkkqidSG+w/SoC6Fy5A0cRseTMiZrchSQQ3hhRjNbxr6uxZDFkTVoyFZPv861ol14b2kebuwBEZfNtBMKIfpqT+4BpwVttqaR0tBGC0JjgEsJxP6xnkLVmGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MbSjzmFzxzI3dpTGKoK3wtix+yEmbfgGGrvPDtmdgqY=; b=fArzujtgQBGBkf4CJFSKIC0PL0YVkSKL74eWIjlkA6eohPO+OOAPHXCfYUwEtuKX831Y8Q7kZ/tq2RV4H72u+R5QvmWZkiOnhvgCNUCxhaBH/DgAaB2lLvny+M1z5xXEQ13G4b43Wjs95pBMmPmZhOeNEuSPDPW1YqlWzCk73Gk+7Jnu1e+EJNhF1lzeh/X8bFuB+pkE80c9QqUkIz7MHfh8xpl6a+My0vs2dYTzKHqR3kMzwD4vbI9okeVCilw6pz+uqzmHNF3srbxVOovxGowc3wZ6OIm55u0bJvX1nioeN0GWjnQa0KLB18a0X9FzXJKjXvi7uF9tMjOibHjn6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MbSjzmFzxzI3dpTGKoK3wtix+yEmbfgGGrvPDtmdgqY=; b=l3tOJjuu83JnEwkeojK7zlirIVhD8yG8UUmkY4JQv+RM6pBFUebP0OQUQ8gY1S5qZfGlBL/DlHVhdfbmriDaS8V2n+2UnZI2TVdzzkSMtrWo0beSHkTjWtweDC4YubV5xJc+Sn4yJRTgSyP7Gq6krPJE2teSyKtY+zI+/IreKmn+zhhIs7lPCROPmQfErPsxZ2x6NIgHNeeDcoDGTSSIVxO+2DRUlzA9YOjbbN1PUzjFazFhTVNqaqdp9CUg9CwURMep8x+DKXjwyItz+P0CxUCDkhVStTS8KIKOaHNqPf/uSapbgVG1bdfLzO/F1ownJZGGIsNVFFEChW1mALL1GA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DB9P250MB0522.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:339::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8583.23; Thu, 27 Mar 2025 18:18:28 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9%4]) with mapi id 15.20.8583.027; Thu, 27 Mar 2025 18:18:28 +0000 Message-ID: <AS8P250MB074461A9D25440982D7FE0028FA12@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> Date: Thu, 27 Mar 2025 19:18:26 +0100 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: <20250324155737.83118-1-derek.buitenhuis@gmail.com> Content-Language: en-US From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> In-Reply-To: <20250324155737.83118-1-derek.buitenhuis@gmail.com> X-ClientProxiedBy: ZR0P278CA0030.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1c::17) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <e975833a-af14-4283-9f27-a5027ef1fb74@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DB9P250MB0522:EE_ X-MS-Office365-Filtering-Correlation-Id: c3c84217-720f-47b1-a828-08dd6d5bc55b X-Microsoft-Antispam: BCL:0; ARA:14566002|6090799003|5072599009|461199028|8060799006|19110799003|7092599003|15080799006|3412199025|440099028|41001999003; X-Microsoft-Antispam-Message-Info: =?utf-8?B?VkgvMWhRQW1ySVRUakliWUdxQ3ZJczdvMjliQ094VkhTeUJ6bDZiVFY3MmJr?= =?utf-8?B?d0g0NHdUY2llbnlJUk0vUkJuNzJEY1kxSkIwdFhOWXdLUDhQV2ZIMFBMN0x2?= =?utf-8?B?QW9IeFJ4ZGpDMytoVFNqUWZsZUNQZkpFN3llNWYzOFNyREtGTkxrWjBsRncw?= =?utf-8?B?UTFhYitsaU85R25SdkRrU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Y1YVpPNWR5dFhJczNnQUZyRGo5TXdl?= =?utf-8?B?ZWc1U0ZoemFWVEtpVW84bEM4ZE1XTU5ON2lHSUUxNUZyVElNVk1nM0JGTFNj?= =?utf-8?B?c2FkQmZrMm1WaG9uSHNIcUhOTm14SmZWQ1oybWpIalN1dU53bkpuc21Qdnha?= =?utf-8?B?QkhsK3pTVGY0a0tmaG55ekk0Nkx2UGczTG1VZ1MxUnRUMUhreTkrOVp5Y3hV?= =?utf-8?B?a0kwajhaT1hXQVUwV1FiZjZFcnh4bkNiZWlOT290akFpVjRVaE83amZGcUFY?= =?utf-8?B?eXlmempyNmVLUDhBWUhJZElNZzl2dTVIajFFVEJOT0hONGl2b2puZndubHRI?= =?utf-8?B?RzNsV29CODFEY3gyTUM1d3ZyQzVsYWQ4VnhBTHlDVlg3THZUS2M3czR3cDdL?= =?utf-8?B?WmNCbHJ6OVAzMVZzeFZvN3p1K1RYazNaTHgvQ1JBU1RYVkk1eElkbHpmbzAx?= =?utf-8?B?Qi8yZi9iUUM0TWg5MUtTRkMwUFFETHFFajJ1QkRDTHNQL2tsNy9aeXlZRmly?= =?utf-8?B?bFRtaVo2S0VtS2xEOXZhTGVSclRpcVVvSDJOSksyVVFmRURpMmM2OUZhSzFB?= =?utf-8?B?R1JBaTdQOTBjbVZZVno4dz09?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3c84217-720f-47b1-a828-08dd6d5bc55b X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2025 18:18:28.0661 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9P250MB0522 Subject: Re: [FFmpeg-devel] [PATCH] 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 <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/AS8P250MB074461A9D25440982D7FE0028FA12@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> Derek Buitenhuis: > From: Justin Ruggles <justinr@vimeo.com> > > 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. > > 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. > > Signed-off-by: Justin Ruggles <justinr@vimeo.com> > Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> > --- > libavformat/dhav.c | 38 +++++++++++++++++++++++++++++--------- > 1 file changed, 29 insertions(+), 9 deletions(-) > > diff --git a/libavformat/dhav.c b/libavformat/dhav.c > index b2ead99609..15a75b5033 100644 > --- a/libavformat/dhav.c > +++ b/libavformat/dhav.c > @@ -232,34 +232,54 @@ static void get_timeinfo(unsigned date, struct tm *timeinfo) > timeinfo->tm_sec = sec; > } > > +#define MAX_DURATION_BUFFER_SIZE (1024*1024) > + > static int64_t get_duration(AVFormatContext *s) > { > DHAVContext *dhav = s->priv_data; > int64_t start_pos = avio_tell(s->pb); > + int64_t end_pos = -1; > int64_t start = 0, end = 0; > struct tm timeinfo; > - int max_interations = 100000; > + uint8_t *end_buffer; > + int64_t end_buffer_size; > + int64_t end_buffer_pos; > > if (!s->pb->seekable) > return 0; > > + end_buffer_size = FFMIN(MAX_DURATION_BUFFER_SIZE, avio_size(s->pb)); > + end_buffer = av_malloc(end_buffer_size); > + if (!end_buffer) > + return 0; > + end_buffer_pos = avio_size(s->pb) - end_buffer_size; > + avio_seek(s->pb, end_buffer_pos, SEEK_SET); > + ffio_ensure_seekback(s->pb, end_buffer_size); This can fail. > + avio_read(s->pb, end_buffer, end_buffer_size); > + av_freep(&end_buffer); You read into a buffer just to ignore the read data? Why don't you just rewrite the loop below to inspect the data directly? > + > avio_seek(s->pb, avio_size(s->pb) - 8, SEEK_SET); > - while (avio_tell(s->pb) > 12 && max_interations--) { > + while (avio_tell(s->pb) > end_buffer_pos) { > if (avio_rl32(s->pb) == MKTAG('d','h','a','v')) { > int64_t seek_back = avio_rl32(s->pb); > - > - avio_seek(s->pb, -seek_back, SEEK_CUR); > - read_chunk(s); > - get_timeinfo(dhav->date, &timeinfo); > - end = av_timegm(&timeinfo) * 1000LL; > + end_pos = avio_tell(s->pb) - seek_back; > break; > } else { > - avio_seek(s->pb, -12, SEEK_CUR); > + avio_seek(s->pb, -5, SEEK_CUR); > } > } > > - avio_seek(s->pb, start_pos, SEEK_SET); > + if (end_pos < 0) { > + avio_seek(s->pb, start_pos, SEEK_SET); > + return 0; > + } > + > + avio_seek(s->pb, end_pos, SEEK_SET); > + read_chunk(s); > + get_timeinfo(dhav->date, &timeinfo); > + end = av_timegm(&timeinfo) * 1000LL; > > + avio_seek(s->pb, start_pos, SEEK_SET); > read_chunk(s); > get_timeinfo(dhav->date, &timeinfo); > start = av_timegm(&timeinfo) * 1000LL; _______________________________________________ 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".