You are not logged in.

#1 2020-12-31 08:26:44

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,171
Website

Stream audio to other local machine

This seems to be a common desire - to send audio on the local network, usually to play music from a desktop computer's hard drive collection to a big stereo system in another room, without long wires trailing everywhere. There's plenty of material to be websearched, but it all looked complicated and messy to me.

Eventually it all worked out though, and wasn't all that difficult, so I thought I'd share it here.

I only wanted audio - video looks more complicated but seems also to be possible, and anyone with advice on that, or alternative methods or anything else related to this topic, please post!

Pulseaudio by itself can do streaming, but I gathered that the audio goes out in uncompressed PCM with latency problems. Luckily BunsenLabs' default media player VLC doesn't just play any media file known to humanity, it also does streaming out of the box, and can transcode to something lighter like mp3 on the fly. cool

TL:DR
OK try this first - it might just work out of the box!

cvlc pulse://alsa_output.pci-0000_00_1b.0.analog-stereo.monitor --sout '#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100,scodec=none}:http{dst=:8080/music.mp3}' --no-sout-all --sout-keep

If the command fails, try adding an option -vvv to get some hints, otherwise test the stream by going to another machine on your local network and connecting. (I've tested this with an android smartphone and was able to play the stream there too.) If you don't know the server's local IP, then (assuming a BL setup) right-click the Network Manager icon (on the server machine) and hit "Connection Information". You want the "IP Address" item: in my case it's 192.168.0.10
Now vlc or any audio player that handles a network URI should be able to play the stream with eg (edit the IP):

mpv http://192.168.0.10:8080/music.mp3

The server VLC is streaming on port 8080 with a path of /music.mp3 but you can change those as you wish (as everything else in that first command).

If the pulse://alsa... part of the first command was wrong for you, you can find PulseAudio's alsa audio output (everything playing on the machine) with:

pactl list | grep "Monitor Source"

This streams everything playing on the "server" machine - music files, net radio, microphone, system sounds, whatever, but it's also very easy to send out just a sequence of music files. There's a GUI way and a CLI way, but VLC's GUI makes creating command lines easy anyway, so even if you eventually run this in a terminal VLC's GUI is helpful.

OK let's open VLC. (If you've got vlc's one-instance option set you'll need to shut down the above server first.)
Then "Media > Stream"
"Add" to choose a file
"Stream" to open a streaming wizard
"Next" under "destination" dropdown choose HTTP, then don't forget "Add"
Choose the port and path you want. Default 8080 seems fine. Some sources say the file extension has to match the media type you're sending, so I used "music.mp3" but it also seemed to work with just /. I didn't test extensively though.
"Next" if you want to send mp3 (please try other options and report back!) then make sure "Activate Transcoding" is checked, and choose Audio-MP3 (FLAC is available too).
"Next" shows the CLI options generated. You might want to copy those somewhere for future use. You can also edit it right there if you know better.
Then click "Stream".

That's streaming a file from the GUI, but you can access that Pulseaudio thing like this:
View > Playlist
Scroll down and click "Audio Capture"
Expand the right-hand item to see "Monitor of Built-i...", right-click, "Stream..." and you're in the same wizard as before. You can also check the pulse-audio source under "Source". I haven't yet checked if the pulse:// protocol is VLC-only or not.

You can just as easily do this with the command-line app cvlc once you've found out all the necessary VLC options. There's a lot of VLC documentation online, but it might take you some time to figure it all out if you don't use the above GUI shortcuts first.

Notes:
*) options start with -- or with : See the VLC docs for the difference (single or multiple instances).
*) watch the quoting: that long #transcode bit needs protecting: '#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100,scodec=none}:http{dst=:8080/music.mp3}'
*) --sout 'stuff' and --sout='stuff' both work but only :sout='stuff' works, :sout 'stuff' does not.
*) The http stream we generate here with VLC should be playable on just about anything - no special client software needs to be installed.
*) Alternative avenues would be ffmpeg or netcat - if you get something working there, please share!
*) Acting as a wifi audio relay might be a good use for an obsolete smartphone?

OK give that a try, and please post any insights! smile

Last edited by johnraff (2021-01-03 04:59:55)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

Board footer

Powered by FluxBB