From: Romain Beauxis <romain.beauxis@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Romain Beauxis <romain.beauxis@gmail.com>
Subject: [FFmpeg-devel] [PATCH v4 3/6] Pass secondary ogg/opus chained streams metadata.
Date: Mon, 10 Feb 2025 13:25:57 -0600
Message-ID: <20250210192600.42502-4-romain.beauxis@gmail.com> (raw)
In-Reply-To: <20250210192600.42502-1-romain.beauxis@gmail.com>
These changes parse ogg/opus comment in secondary chained ogg/opus
streams and attach them as extradata to the corresponding packet.
They can then be decoded in the opus decoder and attached to the next
decoded frame.
libavformat/oggparseopus.c: Parse comments from
secondary chained ogg/opus streams and pass them as ogg stream new_metadata.
libavcodec/opus/dec.c: Unpack comments from secondary chained ogg/opus
streams and attach them to the next decoded frame.
---
libavcodec/opus/dec.c | 25 ++++++++++++++++++++++---
libavformat/oggparseopus.c | 16 +++++++++++++++-
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/libavcodec/opus/dec.c b/libavcodec/opus/dec.c
index 88a650c81c..cddcefcb5f 100644
--- a/libavcodec/opus/dec.c
+++ b/libavcodec/opus/dec.c
@@ -125,6 +125,8 @@ typedef struct OpusContext {
AVFloatDSPContext *fdsp;
float gain;
+ AVDictionary *pending_metadata;
+
OpusParseContext p;
} OpusContext;
@@ -485,12 +487,24 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
int decoded_samples = INT_MAX;
int delayed_samples = 0;
int i, ret;
+ size_t size;
+ const uint8_t *side_metadata;
- if (buf_size > 8 && (
- !memcmp(buf, "OpusHead", 8) ||
- !memcmp(buf, "OpusTags", 8)))
+ if (buf_size > 8 && !memcmp(buf, "OpusHead", 8))
return buf_size;
+ if (buf_size > 8 && !memcmp(buf, "OpusTags", 8)) {
+ /* New metadata */
+ side_metadata = av_packet_get_side_data(avpkt, AV_PKT_DATA_METADATA_UPDATE, &size);
+ if (side_metadata) {
+ av_dict_free(&c->pending_metadata);
+ ret = av_packet_unpack_dictionary(side_metadata, size, &c->pending_metadata);
+ if (ret < 0)
+ return ret;
+ }
+ return buf_size;
+ }
+
/* calculate the number of delayed samples */
for (int i = 0; i < c->p.nb_streams; i++) {
OpusStreamContext *s = &c->streams[i];
@@ -631,6 +645,11 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame,
frame->nb_samples = decoded_samples;
*got_frame_ptr = !!decoded_samples;
+ if (c->pending_metadata) {
+ av_dict_copy(&frame->metadata, c->pending_metadata, AV_DICT_APPEND);
+ av_dict_free(&c->pending_metadata);
+ }
+
return avpkt->size;
}
diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index 950b93bd31..3e94a7df3c 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -116,6 +116,7 @@ static int opus_packet(AVFormatContext *avf, int idx)
AVStream *st = avf->streams[idx];
struct oggopus_private *priv = os->private;
uint8_t *packet = os->buf + os->pstart;
+ AVDictionary *new_metadata = NULL;
int ret;
if (!os->psize)
@@ -133,8 +134,21 @@ static int opus_packet(AVFormatContext *avf, int idx)
return 0;
}
- if (os->psize > 8 && !memcmp(packet, "OpusTags", 8))
+ if (os->psize > 8 && !memcmp(packet, "OpusTags", 8)) {
+ ret = ff_vorbis_comment(avf, &new_metadata, os->buf + os->pstart + 8,
+ os->psize - 8, 1);
+
+ if (ret < 0)
+ return ret;
+
+ os->new_metadata = av_packet_pack_dictionary(new_metadata, &os->new_metadata_size);
+ av_dict_free(&new_metadata);
+
+ if (!os->new_metadata)
+ return AVERROR(ENOMEM);
+
return 0;
+ }
if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {
int seg, d;
--
2.39.5 (Apple Git-154)
_______________________________________________
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:[~2025-02-10 19:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-10 19:25 [FFmpeg-devel] [PATCH v4 0/5] Properly decode ogg metadata in ogg/flac and ogg/opus chained bitstreams Romain Beauxis
2025-02-10 19:25 ` [FFmpeg-devel] [PATCH v4 1/6] Pass ogg/opus secondary header packets to the Romain Beauxis
2025-02-10 19:25 ` [FFmpeg-devel] [PATCH v4 2/6] tests: Add stream dump test API util Romain Beauxis
2025-02-10 19:25 ` Romain Beauxis [this message]
2025-02-13 21:53 ` [FFmpeg-devel] [PATCH v4 3/6] Pass secondary ogg/opus chained streams metadata Lynne
2025-02-13 23:27 ` Romain Beauxis
2025-02-13 23:37 ` Lynne
2025-02-14 15:48 ` Romain Beauxis
2025-02-14 16:18 ` Lynne
2025-02-14 16:50 ` Romain Beauxis
2025-02-14 17:55 ` Lynne
2025-02-14 18:08 ` Romain Beauxis
2025-02-16 21:02 ` Romain Beauxis
2025-02-16 21:03 ` Romain Beauxis
2025-02-10 19:25 ` [FFmpeg-devel] [PATCH v4 4/6] tests: Add chained ogg/opus stream dump test Romain Beauxis
2025-02-10 19:25 ` [FFmpeg-devel] [PATCH v4 5/6] Parse secondary chained ogg/flac stream comments Romain Beauxis
2025-02-10 19:26 ` [FFmpeg-devel] [PATCH v4 6/6] tests: Add chained ogg/flac stream dump test Romain Beauxis
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=20250210192600.42502-4-romain.beauxis@gmail.com \
--to=romain.beauxis@gmail.com \
--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