[FFmpeg-user] Streaming music with just ffmpeg, how to let concat preserve ogg metadata?
Mark Gaiser
markg85 at gmail.com
Sat Jan 25 01:23:41 EET 2025
Hi,
I'm trying to make a music streaming server with just ffmpeg and mpv [1].
The architecture is a typical client (C) server (S) model.
S has the music files, does pre-processing and library management.
C plays these files.
I've added some randomization so that S serves a random music file every
time a new song starts playing.
C plays music like this: mpv "tcp://0.0.0.0:8988?listen"
And S streams music like this:
ffmpeg -re -stream_loop -1 -f concat -safe 0 -i /tmp/playlist.txt
-flush_packets 0 \
-c:a copy -vn -f ogg tcp://10.0.3.14:8988
The playlist "/tmp/playlist.txt" contains:
ffconcat version 1.0
file /tmp/song1
file /tmp/song2
An external tool makes sure that song1 and song2 are pre-processed to
actual songs. They are OGG files.
This works! Mostly...
Metadata from the OGG files isn't preserved. On the receiving end in mpv
it's just one long massive stream. I've tried many [2] many [3] many [4, 5]
options but all have their own issues (mostly with the stream stopping
after an EOF of the music file itself.
The concat option, however weird it is to use, is near perfect! The only
downside to me is that it drops metadata. I'd like to preserve that! Any
ideas on how to do that?
As an aside as it's bound to be asked. No, I cannot easily mount the data
from S on C and play music that way. On a technical level C is essentially
an raspberry pi with a speaker attached. S is doing some audio
pre-processing (normalizing) and monitoring for new files. It would get a
bit too heavy for C to do that too.
Best regards,
Mark
[1] https://mpv.io/ it uses ffmpeg under the hood
[2] Streaming per ogg file does give metadata on the receiving end.
However, after a song is done playing both ends stop (EOF).
[3] A variation on [2], let ffmpeg output into a pipe (mkfifo) and cat that
pipe over the network using cat and nc. That works again for just one
(sometimes two) songs when using cat.
[4] A variation on [3], using tail instead of cat (as tail doesn't send
EOF). Only the first song plays, mpv simply hangs after the first one.
Neither mpv nor ffmpeg close.
[5] I also tried a variation where i'm streaming to shoutcast and play that
using mpv. This suffers from the same issues but just in the shoutcast
ingest point. I don't want to go the full shoutcast webradio server route.
More information about the ffmpeg-user
mailing list