[FFmpeg-devel] [PATCH v5 5/6] Parse comments from secondary chained ogg/opus streams
Romain Beauxis
romain.beauxis at gmail.com
Mon Feb 17 18:19:20 EET 2025
libavformat/oggparseopus.c: Parse comments from secondary chained streams header
packet.
This is the same processing as with ogg/flac except that is done in the
`opus_header` handler.
This is because, in the case of opus streams, the header is currently parsed
again on secondary chained streams so this is where comments have to be
extracted too.
---
libavformat/oggparseopus.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index 218e9df581..76c51d2961 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -29,6 +29,7 @@
struct oggopus_private {
int need_comments;
+ int comments_parsed;
unsigned pre_skip;
int64_t cur_dts;
};
@@ -43,6 +44,7 @@ static int opus_header(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 (!priv) {
@@ -81,7 +83,24 @@ static int opus_header(AVFormatContext *avf, int idx)
if (priv->need_comments) {
if (os->psize < 8 || memcmp(packet, "OpusTags", 8))
return AVERROR_INVALIDDATA;
- ff_vorbis_stream_comment(avf, st, packet + 8, os->psize - 8);
+
+ if (!priv->comments_parsed) {
+ ff_vorbis_stream_comment(avf, st, packet + 8, os->psize - 8);
+ priv->comments_parsed = 1;
+ } else {
+ ret = ff_vorbis_comment(avf, &new_metadata, packet + 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);
+ }
+
priv->need_comments--;
return 1;
}
--
2.39.5 (Apple Git-154)
More information about the ffmpeg-devel
mailing list