Opened 12 months ago

Last modified 12 months ago

#10364 new enhancement

Missing metadata in chained ogg/flac streams

Reported by: toots Owned by:
Priority: normal Component: avformat
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by toots)

Reproduction steps for this bug are similar to https://trac.ffmpeg.org/ticket/10363

How to reproduce:

  • Create two short ogg/opus files:
ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -c:a flac -metadata title="test title" /tmp/test.ogg

ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -c:a flac -metadata title="test title 2" /tmp/test2.ogg
  • Send a stream to a icecast server

Unfortunately, I couldn't find a way to send a chained ogg bitstream using ffmpeg CLI. It seems to always send a single stream so I used ices (https://icecast.org/ices/)

(Doc on ogg chained bitstreams: https://xiph.org/ogg/doc/oggstream.html)

echo /tmp/test.ogg > /tmp/test.txt
echo /tmp/test2.ogg >> /tmp/test.txt

Ices config:

<?xml version="1.0"?>
<ices>
    <background>0</background>
    <consolelog>1</consolelog>


    <stream>
        <input>
            <module>playlist</module>
            <param name="type">basic</param>
            <param name="file">/tmp/test.m3u</param>
            <param name="once">0</param>
        </input>

        <instance>
            <hostname>localhost</hostname>
            <port>8000</port>
            <password>hackme</password>
            <mount>/test.ogg</mount>
            <yp>0</yp>
        </instance>
    </stream>
</ices>

Finally: ices /tmp/ices.xml

  • Use the attached program to read the stream:
cc flac_chained_metadata.c -g -lavformat -lavutil -o flac_chained_metadata

./flac_chained_metadata http://localhost:8000/test.ogg

Output:

encoder=Lavc60.3.100 libopus;Lavc60.3.100 libopus;Lavc60.3.100 libopus
title=test title
....

Expected:
Title should alternate between "test title" and "test title 2"

Solution: add metadata parsing in libavformat/oggparseflac.c:

+static int flac_packet(AVFormatContext *s, int idx)
+{
+    struct ogg *ogg = s->priv_data;
+    struct ogg_stream *os = ogg->streams + idx;
+    int ret;
+
+    if (os->psize > 4 && (*(os->buf + os->pstart) & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
+        AVStream *st = s->streams[idx];
+        av_dict_free(&st->metadata);
+        ret = ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 4,
+                                       os->psize - 4);
+
+        if (ret < 0) return ret;
+    }
+
+    return 0;
+}
+
+
 const struct ogg_codec ff_flac_codec = {
     .magic = "\177FLAC",
     .magicsize = 5,
     .header = flac_header,
+    .packet = flac_packet,
     .nb_header = 2,
 };

Patch has been sent but needs an update which will be coming soon.

Attachments (1)

flac_chained_metadata.c (1.4 KB ) - added by toots 12 months ago.

Download all attachments as: .zip

Change History (2)

by toots, 12 months ago

Attachment: flac_chained_metadata.c added

comment:1 by toots, 12 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.