[FFmpeg-devel] [PATCH v4 1/6] Pass ogg/opus secondary header packets to the
Romain Beauxis
romain.beauxis at gmail.com
Mon Feb 10 21:25:55 EET 2025
These changes make it possible to access the initial header packets of
secondary chained ogg/opus bitstreams.
libavformat/oggparseopus.c: Parse extradata from
secondary chained streams header packet.
libavformat/oggdec.c: Do not force ogg stream header parsing on
secondary ogg/opus chained streams.
libavcodec/opus/dec.c: Ignore opus header packets from secondary chained
streams.
---
libavcodec/opus/dec.c | 5 +++++
libavformat/oggdec.c | 4 ----
libavformat/oggparseopus.c | 11 +++++++++++
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/libavcodec/opus/dec.c b/libavcodec/opus/dec.c
index 6c59dc1f46..88a650c81c 100644
--- a/libavcodec/opus/dec.c
+++ b/libavcodec/opus/dec.c
@@ -486,6 +486,11 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
int delayed_samples = 0;
int i, ret;
+ if (buf_size > 8 && (
+ !memcmp(buf, "OpusHead", 8) ||
+ !memcmp(buf, "OpusTags", 8)))
+ return buf_size;
+
/* calculate the number of delayed samples */
for (int i = 0; i < c->p.nb_streams; i++) {
OpusStreamContext *s = &c->streams[i];
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 5339fdd32c..4425279ce8 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -239,10 +239,6 @@ static int ogg_replace_stream(AVFormatContext *s, uint32_t serial, char *magic,
os->start_trimming = 0;
os->end_trimming = 0;
- /* Chained files have extradata as a new packet */
- if (codec == &ff_opus_codec)
- os->header = -1;
-
return i;
}
diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index 218e9df581..950b93bd31 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -125,6 +125,17 @@ static int opus_packet(AVFormatContext *avf, int idx)
return AVERROR_INVALIDDATA;
}
+ if (os->psize > 8 && !memcmp(packet, "OpusHead", 8)) {
+ if ((ret = ff_alloc_extradata(st->codecpar, os->psize)) < 0)
+ return ret;
+
+ memcpy(st->codecpar->extradata, packet, os->psize);
+ return 0;
+ }
+
+ if (os->psize > 8 && !memcmp(packet, "OpusTags", 8))
+ return 0;
+
if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {
int seg, d;
int duration;
--
2.39.5 (Apple Git-154)
More information about the ffmpeg-devel
mailing list