From patchwork Sat Dec 30 21:25:11 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: 45403 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp5486754pzh; Sat, 30 Dec 2023 13:25:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdV3Sy1UZ9MyqqFoAXU1tDpmOBcb3lRpTY990sgLCUndiYS9EH7/X7R18DP2LYgBDL+77X X-Received: by 2002:a05:600c:3114:b0:40d:70c9:eb14 with SMTP id g20-20020a05600c311400b0040d70c9eb14mr2123101wmo.146.1703971521758; Sat, 30 Dec 2023 13:25:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703971521; cv=none; d=google.com; s=arc-20160816; b=s0URrfInO1+hpMmsQoksLCIb7HY0OUJ4kqaSjJtKfaHl4ISh9auhjMUETupkQsAcP4 kyJO/assGRRMce+BydyEqq0MpaoDCkDTeQsFKFCX9bcWjOHfRnGqf/MvU3CXl5NHn1oL scUqelfT8EIfdmoT3JxYBB2zUYzwtkg4NJRkK3BccmjnK2njkNZSPGazjhdZ4e3hnl0x RhMwI5Kv4a5uRbdVD6NBPhCbZt0mI4qmxcJNtCF5MFNeAHErY98+3g7eu1Y54f96Sgfj sjhZrIv5dl4WadcN6fGdy3+rJp3tSCSh8lo3AF8vCYzMU2RZ4QaJapFV/w//xtflE7hy ub4Q== 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=nrO/YQG7BgBo7jvVMrFhO2LH2p5nGHgUtrWaFnrATaI=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=aI5K/SFimVS0j35SA0vTu3wZwjvEhROJepTD+y2EPvXZBTUNnJopVuLUKnVWZyNOru U6r/d6gcBz78wMBET9OmiZzggLr0xE8w0/A/upLXyew68QdWI0WkuCYKHJlfZdkF1IUh izwy8+23arEJB1fSgJCKnIigqfvc4DAbeRQgbVRqncMLNFiAeJWRmHAedabdt3joualX Z9VfFeyBDXAHIBSD82qGn5nAGCbiuBu0RfFDxO6c+nDEj3+CUOpsOT8FM9QIbYbd33tk J73d9CwSRR9zQA0FB47KHO1GqWHHoETtaiUXqO9OryS1bqlxwFJXGFt0gLLuGC7fOr1K HgSA== 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 oq2-20020a170906cc8200b00a26f1e22c1esi4823986ejb.311.2023.12.30.13.25.21; Sat, 30 Dec 2023 13:25:21 -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 4DF4168CCC9; Sat, 30 Dec 2023 23:25:19 +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 898D668CC40 for ; Sat, 30 Dec 2023 23:25:12 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by glom.nmugroup.com (Postfix) with ESMTP id 31B815428493 for ; Sat, 30 Dec 2023 22:25:12 +0100 (CET) Received: from debian.lan (unknown [IPv6:2a00:66c0:a::72c]) (Authenticated sender: git01) by glom.nmugroup.com (Postfix) with ESMTPSA id E383A5428441 for ; Sat, 30 Dec 2023 22:25:11 +0100 (CET) Message-ID: From: Tomas =?iso-8859-1?q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Sat, 30 Dec 2023 22:25:11 +0100 In-Reply-To: References: User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/7] 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: K5wQOps4pnE0 Previous version accidentally used CODEC2_EXTRADATA_SIZE not CODEC2_HEADER_SIZE /Tomas From 6fda817b2bc237081e6bf6daeff9087b6543647b 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 3/7] 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..78bc339209 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_HEADER_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