Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 0/4] ogg/{vorbis, opus, flac}: Decode metadata from secondary chained streams.
@ 2025-06-01 16:49 Romain Beauxis
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 1/4] libavformat/oggdec.h, libavformat/oggparsevorbis.c: Factor out vorbis metadata update mechanism Romain Beauxis
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Romain Beauxis @ 2025-06-01 16:49 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Romain Beauxis, dev

This is a redo of a previous patchset. It is pending the review and
commit of
https://ffmpeg.org/pipermail/ffmpeg-devel/2025-June/344442.html but I
wanted to send right away for early review.

After removing ogg header packets from the demuxer, the changes are
really nice:
* Factor out vorbis metadata update mechanism
* Switch oggdec to use AV_PKT_DATA_STRINGS_METADATA for metadata update
  through extradata since this is the mechanism already implemented.
--> At this point, vorbis chained metadata start working!
* Use newly factored out function in ogg/flac parser to enable metadata
  updates.
* Use newly factored out function in ogg/opus parser to enable metadata
  updates.

Voila!

Romain Beauxis (4):
  libavformat/oggdec.h, libavformat/oggparsevorbis.c: Factor out vorbis
    metadata update mechanism.
  libavformat/oggdec.c: Use AV_PKT_DATA_STRINGS_METADATA to pass
    metadata updates.
  libavformat/oggparseflac.c: Parse ogg/flac comments in new ogg
    packets, add them to ogg stream new_metadata.
  libavformat/oggparseopus.c: Parse comments from secondary chained
    streams header packet.

 libavformat/oggdec.c                       |  2 +-
 libavformat/oggdec.h                       | 14 ++++++++++++
 libavformat/oggparseflac.c                 |  7 ++++++
 libavformat/oggparseopus.c                 |  5 +++++
 libavformat/oggparsevorbis.c               | 25 +++++++++++++++-------
 tests/ref/fate/ogg-flac-chained-meta.txt   |  3 ++-
 tests/ref/fate/ogg-opus-chained-meta.txt   |  3 ++-
 tests/ref/fate/ogg-vorbis-chained-meta.txt |  2 +-
 8 files changed, 49 insertions(+), 12 deletions(-)

-- 
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 1/4] libavformat/oggdec.h, libavformat/oggparsevorbis.c: Factor out vorbis metadata update mechanism.
  2025-06-01 16:49 [FFmpeg-devel] [PATCH 0/4] ogg/{vorbis, opus, flac}: Decode metadata from secondary chained streams Romain Beauxis
@ 2025-06-01 16:49 ` Romain Beauxis
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 2/4] libavformat/oggdec.c: Use AV_PKT_DATA_STRINGS_METADATA to pass metadata updates Romain Beauxis
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Romain Beauxis @ 2025-06-01 16:49 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Romain Beauxis

---
 libavformat/oggdec.h         | 14 ++++++++++++++
 libavformat/oggparsevorbis.c | 25 +++++++++++++++++--------
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h
index c15fbe738e..d10a9b1a89 100644
--- a/libavformat/oggdec.h
+++ b/libavformat/oggdec.h
@@ -160,6 +160,20 @@ int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m,
 int ff_vorbis_stream_comment(AVFormatContext *as, AVStream *st,
                              const uint8_t *buf, int size);
 
+/**
+ * Parse Vorbis comments, add metadata to an AVStream
+ *
+ * This function also attaches the metadata to the next decoded
+ * packet as AV_PKT_DATA_METADATA_UPDATE
+ *
+ * @note  The buffer will be temporarily modifed by this function,
+ *        so it needs to be writable. Furthermore it must be padded
+ *        by a single byte (not counted in size).
+ *        All changes will have been reverted upon return.
+ */
+int ff_vorbis_update_metadata(AVFormatContext *s, AVStream *st,
+                              const uint8_t *buf, int size);
+
 static inline int
 ogg_find_stream (struct ogg * ogg, int serial)
 {
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 7e812846fe..7b7c76a3e0 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -263,20 +263,16 @@ static void vorbis_cleanup(AVFormatContext *s, int idx)
     }
 }
 
-static int vorbis_update_metadata(AVFormatContext *s, int idx)
+int ff_vorbis_update_metadata(AVFormatContext *s, AVStream *st,
+                              const uint8_t *buf, int size)
 {
     struct ogg *ogg = s->priv_data;
-    struct ogg_stream *os = ogg->streams + idx;
-    AVStream *st = s->streams[idx];
+    struct ogg_stream *os = ogg->streams + st->index;
     int ret;
 
-    if (os->psize <= 8)
-        return 0;
-
     /* New metadata packet; release old data. */
     av_dict_free(&st->metadata);
-    ret = ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 7,
-                                   os->psize - 8);
+    ret = ff_vorbis_stream_comment(s, st, buf, size);
     if (ret < 0)
         return ret;
 
@@ -349,6 +345,19 @@ static int vorbis_parse_header(AVFormatContext *s, AVStream *st,
     return 1;
 }
 
+static int vorbis_update_metadata(AVFormatContext *s, int idx)
+{
+    struct ogg *ogg = s->priv_data;
+    struct ogg_stream *os = ogg->streams + idx;
+    AVStream *st = s->streams[idx];
+
+    if (os->psize <= 8)
+        return 0;
+
+    return ff_vorbis_update_metadata(s, st, os->buf + os->pstart + 7,
+                                     os->psize - 8);
+}
+
 static int vorbis_header(AVFormatContext *s, int idx)
 {
     struct ogg *ogg = s->priv_data;
-- 
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 2/4] libavformat/oggdec.c: Use AV_PKT_DATA_STRINGS_METADATA to pass metadata updates.
  2025-06-01 16:49 [FFmpeg-devel] [PATCH 0/4] ogg/{vorbis, opus, flac}: Decode metadata from secondary chained streams Romain Beauxis
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 1/4] libavformat/oggdec.h, libavformat/oggparsevorbis.c: Factor out vorbis metadata update mechanism Romain Beauxis
@ 2025-06-01 16:49 ` Romain Beauxis
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 3/4] libavformat/oggparseflac.c: Parse ogg/flac comments in new ogg packets, add them to ogg stream new_metadata Romain Beauxis
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 4/4] libavformat/oggparseopus.c: Parse comments from secondary chained streams header packet Romain Beauxis
  3 siblings, 0 replies; 5+ messages in thread
From: Romain Beauxis @ 2025-06-01 16:49 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Romain Beauxis

---
 libavformat/oggdec.c                       | 2 +-
 tests/ref/fate/ogg-vorbis-chained-meta.txt | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index da3ef815db..10b9725bfb 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -880,7 +880,7 @@ retry:
     }
 
     if (os->new_metadata) {
-        ret = av_packet_add_side_data(pkt, AV_PKT_DATA_METADATA_UPDATE,
+        ret = av_packet_add_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
                                       os->new_metadata, os->new_metadata_size);
         if (ret < 0)
             return ret;
diff --git a/tests/ref/fate/ogg-vorbis-chained-meta.txt b/tests/ref/fate/ogg-vorbis-chained-meta.txt
index 1206f86c1f..60d9aeb9fa 100644
--- a/tests/ref/fate/ogg-vorbis-chained-meta.txt
+++ b/tests/ref/fate/ogg-vorbis-chained-meta.txt
@@ -7,7 +7,7 @@ Stream ID: 0, packet PTS: 704, packet DTS: 704
 Stream ID: 0, frame PTS: 704, metadata: N/A
 Stream ID: 0, packet PTS: 0, packet DTS: 0
 Stream ID: 0, new metadata: encoder=Lavc61.19.100 libvorbis:title=Second Stream
-Stream ID: 0, frame PTS: 0, metadata: N/A
+Stream ID: 0, frame PTS: 0, metadata: encoder=Lavc61.19.100 libvorbis:title=Second Stream
 Stream ID: 0, packet PTS: 128, packet DTS: 128
 Stream ID: 0, frame PTS: 128, metadata: N/A
 Stream ID: 0, packet PTS: 704, packet DTS: 704
-- 
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 3/4] libavformat/oggparseflac.c: Parse ogg/flac comments in new ogg packets, add them to ogg stream new_metadata.
  2025-06-01 16:49 [FFmpeg-devel] [PATCH 0/4] ogg/{vorbis, opus, flac}: Decode metadata from secondary chained streams Romain Beauxis
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 1/4] libavformat/oggdec.h, libavformat/oggparsevorbis.c: Factor out vorbis metadata update mechanism Romain Beauxis
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 2/4] libavformat/oggdec.c: Use AV_PKT_DATA_STRINGS_METADATA to pass metadata updates Romain Beauxis
@ 2025-06-01 16:49 ` Romain Beauxis
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 4/4] libavformat/oggparseopus.c: Parse comments from secondary chained streams header packet Romain Beauxis
  3 siblings, 0 replies; 5+ messages in thread
From: Romain Beauxis @ 2025-06-01 16:49 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Romain Beauxis

---
 libavformat/oggparseflac.c               | 7 +++++++
 tests/ref/fate/ogg-flac-chained-meta.txt | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c
index d66b85b09e..e81e4021a1 100644
--- a/libavformat/oggparseflac.c
+++ b/libavformat/oggparseflac.c
@@ -85,6 +85,8 @@ flac_packet (AVFormatContext * s, int idx)
 {
     struct ogg *ogg = s->priv_data;
     struct ogg_stream *os = ogg->streams + idx;
+    AVStream *st = s->streams[idx];
+    int ret;
 
     if (os->psize > OGG_FLAC_MAGIC_SIZE &&
         !memcmp(
@@ -95,6 +97,11 @@ flac_packet (AVFormatContext * s, int idx)
 
     if (os->psize > 0 &&
         ((os->buf[os->pstart] & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT)) {
+        ret = ff_vorbis_update_metadata(s, st, os->buf + os->pstart + 4,
+                                        os->psize - 4);
+        if (ret < 0)
+            return ret;
+
         return 1;
     }
 
diff --git a/tests/ref/fate/ogg-flac-chained-meta.txt b/tests/ref/fate/ogg-flac-chained-meta.txt
index 28e22aa29e..5abf37dcee 100644
--- a/tests/ref/fate/ogg-flac-chained-meta.txt
+++ b/tests/ref/fate/ogg-flac-chained-meta.txt
@@ -5,6 +5,7 @@ Stream ID: 0, frame PTS: 0, metadata: N/A
 Stream ID: 0, packet PTS: 4608, packet DTS: 4608
 Stream ID: 0, frame PTS: 4608, metadata: N/A
 Stream ID: 0, packet PTS: 0, packet DTS: 0
-Stream ID: 0, frame PTS: 0, metadata: N/A
+Stream ID: 0, new metadata: encoder=Lavc61.19.100 flac:title=Second Stream
+Stream ID: 0, frame PTS: 0, metadata: encoder=Lavc61.19.100 flac:title=Second Stream
 Stream ID: 0, packet PTS: 4608, packet DTS: 4608
 Stream ID: 0, frame PTS: 4608, metadata: N/A
-- 
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 4/4] libavformat/oggparseopus.c: Parse comments from secondary chained streams header packet.
  2025-06-01 16:49 [FFmpeg-devel] [PATCH 0/4] ogg/{vorbis, opus, flac}: Decode metadata from secondary chained streams Romain Beauxis
                   ` (2 preceding siblings ...)
  2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 3/4] libavformat/oggparseflac.c: Parse ogg/flac comments in new ogg packets, add them to ogg stream new_metadata Romain Beauxis
@ 2025-06-01 16:49 ` Romain Beauxis
  3 siblings, 0 replies; 5+ messages in thread
From: Romain Beauxis @ 2025-06-01 16:49 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Romain Beauxis

---
 libavformat/oggparseopus.c               | 5 +++++
 tests/ref/fate/ogg-opus-chained-meta.txt | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index 65b93b4053..ae4ff22c53 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -154,6 +154,11 @@ static int opus_packet(AVFormatContext *avf, int idx)
     }
 
     if (os->psize > 8 && !memcmp(packet, "OpusTags", 8)) {
+        ret = ff_vorbis_update_metadata(avf, st, os->buf + os->pstart + 8,
+                                        os->psize - 8);
+        if (ret < 0)
+            return ret;
+
         priv->need_comments = 0;
         return 1;
     }
diff --git a/tests/ref/fate/ogg-opus-chained-meta.txt b/tests/ref/fate/ogg-opus-chained-meta.txt
index addc41c1eb..aad9b83700 100644
--- a/tests/ref/fate/ogg-opus-chained-meta.txt
+++ b/tests/ref/fate/ogg-opus-chained-meta.txt
@@ -13,7 +13,8 @@ Stream ID: 0, frame PTS: 3528, metadata: N/A
 Stream ID: 0, packet PTS: 4488, packet DTS: 4488
 Stream ID: 0, frame PTS: 4488, metadata: N/A
 Stream ID: 0, packet PTS: -312, packet DTS: -312
-Stream ID: 0, frame PTS: -312, metadata: N/A
+Stream ID: 0, new metadata: encoder=Lavc61.19.100 libopus:title=Second Stream
+Stream ID: 0, frame PTS: -312, metadata: encoder=Lavc61.19.100 libopus:title=Second Stream
 Stream ID: 0, packet PTS: 648, packet DTS: 648
 Stream ID: 0, frame PTS: 648, metadata: N/A
 Stream ID: 0, packet PTS: 1608, packet DTS: 1608
-- 
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".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-01 16:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-01 16:49 [FFmpeg-devel] [PATCH 0/4] ogg/{vorbis, opus, flac}: Decode metadata from secondary chained streams Romain Beauxis
2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 1/4] libavformat/oggdec.h, libavformat/oggparsevorbis.c: Factor out vorbis metadata update mechanism Romain Beauxis
2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 2/4] libavformat/oggdec.c: Use AV_PKT_DATA_STRINGS_METADATA to pass metadata updates Romain Beauxis
2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 3/4] libavformat/oggparseflac.c: Parse ogg/flac comments in new ogg packets, add them to ogg stream new_metadata Romain Beauxis
2025-06-01 16:49 ` [FFmpeg-devel] [PATCH 4/4] libavformat/oggparseopus.c: Parse comments from secondary chained streams header packet Romain Beauxis

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