From patchwork Thu Dec 28 18:43:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 45372 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp4354614pzh; Thu, 28 Dec 2023 10:43:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEpKaX1GDsHaF93jE0tqq8bASRMcu6b0qthX1a/d6cwcq9oCSH+iqpGTjv7RfOCEkTmwola X-Received: by 2002:a17:906:697:b0:a25:c2c:8263 with SMTP id u23-20020a170906069700b00a250c2c8263mr4821952ejb.136.1703789033335; Thu, 28 Dec 2023 10:43:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703789033; cv=none; d=google.com; s=arc-20160816; b=U+IJMJWZTaMyrAyrcVTQH61Nyal8nyFs0Pb8LuI0vnGNxbyGTmPiOT5lDubvpZcf/F 8SLxdxJ7C0zzO1TNrPTCS22n8GM8mdBWZuIEerOyndCtZLCvVw3XIL4dRFA0KVgNVytn f7fyU7MTo18wJ8zBeLZ26OeKH8kbmO1yCZ68JFDKfQI9GfOmjeEmI2DWL6B2GLQ7wsi+ MDXNo8W1YE9raPbjdUhGwQ7CVtUb2T7J47aQO942s8hhHTnaeCs7PBj9nz60rhxXdeEG /V0mMMVuU7PsopQuGK6b+yenWcg9ACdA9YPYfzcgcNYuu+TiRY23Uxdh87PMMagJftcz pDzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:user-agent:references:in-reply-to:date:to:from :message-id:delivered-to; bh=0DrkwxbgsbywG+UbMfquZ305ZzV7XN/PHfB1/J0vsao=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=hg8iIS9cza1KORxEgIuRY3ELoD/R1gGMm/ot3T2oGBDKfPTwB2h1+1+b0BdymRcM5q DicNfw3eUOgFEEeHM1seMfkcCUd2+PdL7EiE6pjW6VGIMmbAqp86SmHaP0lUNjeYOTVG rOTWExoaS6Siepel3TlD9oVkWM1AlFtuZUGsth3nzPiXaTRhqLw8caWzpzZl4ZLUf6N/ ltc8I4cK2upnxIAePnUr3xvgBRjCFmFefkce5Xf/HJOX88Y4D1QoJweACjyXa/nOxVP0 nceLNOqt1/43UXrqRxsOCz5dCil52Rzbppfkm9ZDl24XndHsz9FABlV4oi0yPrqjCQQz 7TYA== 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h1-20020a17090619c100b00a236e119480si529744ejd.644.2023.12.28.10.43.53; Thu, 28 Dec 2023 10:43:53 -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 CCA5168CCAF; Thu, 28 Dec 2023 20:43:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from glom.nmugroup.com (glom.nmugroup.com [193.183.80.6]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F1F2A68CC3E for ; Thu, 28 Dec 2023 20:43:44 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by glom.nmugroup.com (Postfix) with ESMTP id 9848754252BF for ; Thu, 28 Dec 2023 19:43:44 +0100 (CET) Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) (Authenticated sender: git01) by glom.nmugroup.com (Postfix) with ESMTPSA id 537F554252BB for ; Thu, 28 Dec 2023 19:43:44 +0100 (CET) Message-ID: <7ff90b8b486e63412e3a3ba3dac9dc550bbf17c5.camel@haerdin.se> From: Tomas =?iso-8859-1?q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Thu, 28 Dec 2023 19:43:43 +0100 In-Reply-To: References: User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] lavf/codec2: Compute duration from filesize 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FrGOfTblDgjK From 1576f9206b51ea9946495e7c5e293403541d49a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Wed, 27 Dec 2023 16:32:49 +0100 Subject: [PATCH 2/6] lavf/codec2: Compute duration from filesize --- libavformat/codec2.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libavformat/codec2.c b/libavformat/codec2.c index 1d6ef2a14a..47fff2a695 100644 --- a/libavformat/codec2.c +++ b/libavformat/codec2.c @@ -124,9 +124,10 @@ static int codec2_mode_bit_rate(AVFormatContext *s, int mode) return 8 * 8000 * block_align / frame_size; } -static int codec2_read_header_common(AVFormatContext *s, AVStream *st) +static int codec2_read_header_common(AVFormatContext *s, AVStream *st, int header) { int mode = codec2_mode_from_extradata(st->codecpar->extradata); + int64_t sz = avio_size(s->pb); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = AV_CODEC_ID_CODEC2; @@ -143,6 +144,12 @@ static int codec2_read_header_common(AVFormatContext *s, AVStream *st) return AVERROR_INVALIDDATA; } + // compute duration from filesize + if (sz >= header) { + int64_t frames = (sz - header) / st->codecpar->block_align; + if (frames <= INT64_MAX / st->codecpar->frame_size) + st->duration = frames * st->codecpar->frame_size; + } avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; @@ -180,7 +187,7 @@ static int codec2_read_header(AVFormatContext *s) ffformatcontext(s)->data_offset = CODEC2_HEADER_SIZE; - return codec2_read_header_common(s, st); + return codec2_read_header_common(s, st, CODEC2_EXTRADATA_SIZE); } static int codec2_read_packet(AVFormatContext *s, AVPacket *pkt) @@ -258,7 +265,7 @@ static int codec2raw_read_header(AVFormatContext *s) codec2_make_extradata(st->codecpar->extradata, c2->mode); - return codec2_read_header_common(s, st); + return codec2_read_header_common(s, st, 0); } //transcoding report2074.c2 to wav went from 7.391s to 5.322s with -frames_per_packet 1000 compared to default, same sha1sum -- 2.39.2