From: "Tomas Härdin" <git@haerdin.se>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH v2 3/7] lavf/codec2: Compute duration from filesize
Date: Sat, 30 Dec 2023 22:25:11 +0100
Message-ID: <ba3a90b55cf55901c6206749b0e0a75d60d9cd07.camel@haerdin.se> (raw)
In-Reply-To: <a85bc5d6a405ba989d98383a10612d42d015ea90.camel@haerdin.se>
[-- Attachment #1: Type: text/plain, Size: 92 bytes --]
Previous version accidentally used CODEC2_EXTRADATA_SIZE not
CODEC2_HEADER_SIZE
/Tomas
[-- Attachment #2: 0003-lavf-codec2-Compute-duration-from-filesize.patch --]
[-- Type: text/x-patch, Size: 2171 bytes --]
From 6fda817b2bc237081e6bf6daeff9087b6543647b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
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
[-- Attachment #3: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
next prev parent reply other threads:[~2023-12-30 21:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-30 21:22 [FFmpeg-devel] [PATCH v2 1/7] lavc/codec2utils: Use actual libcodec2 version Tomas Härdin
2023-12-30 21:23 ` [FFmpeg-devel] [PATCH v2 2/7] lavc/libcodec2: Report actual bitrate used both when decoding and encoding Tomas Härdin
2023-12-30 21:25 ` Tomas Härdin [this message]
2023-12-30 21:25 ` [FFmpeg-devel] [PATCH v2 4/7] lavf/codec2: Allow versions between 0.8 and 1.X Tomas Härdin
2023-12-30 21:25 ` [FFmpeg-devel] [PATCH v2 5/7] lavf/codec2: Multiple of block_align -> not corrupt Tomas Härdin
2023-12-30 21:26 ` [FFmpeg-devel] [PATCH v2 6/7] lavf/codec2: Silence warnings when either muxer/demuxer is disabled Tomas Härdin
2023-12-30 21:27 ` [FFmpeg-devel] [PATCH v2 7/7] Add FATE tests for codec2, codec2raw and libcodec2 wrapper Tomas Härdin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ba3a90b55cf55901c6206749b0e0a75d60d9cd07.camel@haerdin.se \
--to=git@haerdin.se \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git