However, things start to go wrong when trying to play HLS streams, which have the .m3u8 file extension.
ffserver is (or rather was) an easy way to take a input feed and transcode it to one or may output streams while being provided with the ffmpeg binaries. Since ffmpeg can already decode .m3u8 HLS streams, it can be used directly as an input feed to ffserver. Given the right configuration, on can then expose this feed as a streaming mp3/ogg/aac file which can be understood by the Chromecast, or any other dumb player which can play a file from an HTTP stream.
N.B. ffserver has been officially deprecated in 2016 and subsequently dropped from ffmpeg binaries in 2018. Ubuntu 18.04 repositories serve ffmpeg 3.4.6 which still includes ffserver.
ffserver’s configuration itself is pretty straightforward. We both define an input feed and an output stream. Multiple streams can be defined for the same feed.
Running ffserver should now start an HTTP server, which serves our stream1.ogg on http://localhost:5000/stream1.ogg .
A while ago, I had the idea of a simple Minecraft mod which would allow the creation of custom music discs in Minecraft using YouTube as the primary way of distributing and synchronizing the actual music tracks amongst players. All of this, while allowing any player on the server to add their own favorite music tracks.
The actual Minecraft mod is quite simple. It reads a simple JSON-formatted list of tracks, and register them as items with Forge Mod Loader, giving them a game ID. At the same time, they get an item texture assigned, which is simply one of the existing record item textures.
To get the music tracks to play, the mod uses a separate resource pack, built by grabbing YouTube videos, and extracting the audio using ffmpeg. I made a simple java program to parse the JSON track list and download the tracks, while creating the required directory structure for a Minecraft resource pack. At this step, track titles also get added into the game.
Keeping Clients Coherent
Since the primary use case of this mod is multiplayer gameplay, we needed a way of keeping clients coherent, while still allowing a frequent additions. I came up with a simple CRUD-style application hosted on a Heroku container, which would serve a properly formatted track list, and offer a simple form for user to add new songs, all of that using a free-tier database. The only downside to this approach is that the container shuts itself off after 30 minutes of inactivity, then requiring roughly 25 seconds to serve the next request. This causes the game client to freeze in the loading screen, while waiting for a reply. This could be easily fixed by stepping to a more premium usage tier, but the very light usage mostly makes this a non-issue.