Is there a way to stream the live output of the soundcard from our 12.04.1 LTS amd64 desktop to a DLNA-compliant external device in our network? Selecting media content in shared directories using Rygel, miniDLNA, and uShare is always fine - but so far we completely failed to get a live audio stream to a client via DLNA.
Pulseaudio claims to have a DLNA/UPnP media server that together with Rygel is supposed to do just this. But we were unable to get it running.
We followed the steps outlined in live.gnome.org, this answer here, and also in another similar guide.
In 12.04 LTS we can select the local audio device, or our GST-Launch stream in the DLNA client but Rygel displays the following message and the client states it reached the end of the playlist:
(rygel:7380): Rygel-WARNING **: rygel-http-request.vala:97: Invalid seek request
There was no way to listen to live audio streams on the client.
Only after a distribution upgrade to 14.04 LTS we were able to select a live stream on our DLNA renderers from settings nicely outlined in below answer. Still, we needed to select an established stream after we started rygel and were unable to push a new stream to our UPnP devices. Audio metadata were not transmitted.
Are there any other alternatives for sending the audio of our soundcard as live stream to a DLNA client?
Pulseaudio-DLNA
I created a little server which discovers all upnp renderers in your network and adds them as sinks to pulseaudio. So you can control every application via pavucontrol to play on your upnp devices.
That's the kind of comfort I always wanted when dealing with upnp devices under linux.
The application can be installed from source or DEB package downloadable from git, or after we had added the project's official ppa:qos/pulseaudio-dlna to our sources with:
We then run pulseaudio-dlna from the command line with following options:
See also the pulseaudio-dlna "About" for more.
When there was a DLNA renderer present we can then select it from the sound menu as an output sink:
Pavucontrol is the missing item in this jigsaw puzzle! I had also set up everything correctly and the external device(LG TV) was showing that the sound was being played but I did not hear any sound. Today I installed pavucontrol and when I opened it I found the option to channel sound through the DLNA server. The DLNA option is only shown when there is sound output from a player to pulseaudio.
I'm sorry I can't help you with Rygel at all, but there may be an alternative which may work for you.
The principle is get a program to record the stream to an audiofile, then launch miniDLNA with a custom config which points to the directory that stream is in.
Example: Say we're working in ~/stream/. Create ~/stream/minidlna.conf
Then save the stream to an audiofile in that directory. Googling for "FFmpeg record sound card audio" yielded this command
but I didn't have much luck with it. Another option is vlc is you have a GUI available and this doesn't work.
Then boot up miniDLNA in another terminal window:
It should locate OutputStream.flac and then be accessible from your network device.
Hopefully if you haven't already got it solved that's given you a few ideas.
One idea I had to stream "what I hear" to a DLNA renderer (like WDTV) was to server the stream with VLC as http stream with
pulse://alsa_output.xxx.monitor
as input and transcode it to MP3 or FLAC. Then I wanted to use some DLNA control point to let the renderer play taht stream. VLC does serve the transcoded stream correctly, but it does not allow to set the mime type, so the renderer refuses to play it.The next idea was to write a http server in python that serves the stream instead. It gets the audio stream from pulse with
parec
, encodes it withflac
(orlame
or whatever you want) and sets the mime type correctly.It works with the following (very simple) script:
Adjust the parameters, run it, and point the DLNA renderer to your machine. It worked for me with a WDTV as renderer and an Android phone with BubbleUPnP as control point (You can type in the stream URL when adding a new item to the playlist manually). But it should work with any DLNA compliant devices.
NOTE: This solution works, but a newer and probably better solution has been proposed by Massimo.
Here's an answer for Ubuntu 14.04 (also tested and working on 15.04), for completeness:
install any needed packages:
sudo apt-get install rygel rygel-preferences rygel-gst-launch
create the file
~/.config/rygel.conf
that contains the following:Execute the following commands from the commandline (these could be put into a script if desired):
Run the
paprefs
command, and ensure that both DLNA options are enabled (checked) on the "Network Server" tab.Play some audio on your computer. Run the
pavucontrol
program, and on the "Playback" tab, change the output device to "DLNA/UPnP Streaming".At this point, you should be able to play the MPEG and FLAC streams from a DLNA client (renderer / control point).
NOTE: you may need to restart your computer (or restart pulse) in order for things to begin to work.
The python script from Adam is just what I needed. Brilliant. Rygel with gst-launch doesn't work with one of my renderers, but this script works with both. In my case I'm taking an audio stream input from squeezelite (for squeezebox) and sending to a renderer. The script also works in the original form to take input from a pulseaudio monitor if that's what is needed.
Knowing little about any of this I managed to make some additions to the script that:
i) allow it to be run from a shell script and be terminated with a SIGTERM/SIGKILL (the 'except' statement now includes 'systemexit')
ii) allows the script to be stopped and restarted and re-use the same port (as it was the restarted script tended to fail saying it could not open the port if the renderer still had it open) - (the allow_reuse_address = True statement)
iii) make a version that takes input from stdin and resamples it using sox to output in wav format (on port 8082)
So my version looks like:
Not sure if this is will be useful for you now, but I written a post about getting this to work on Ubuntu 12.10:
http://dpc.ucore.info/blog/2012/11/07/dlna-streaming-in-ubuntu-12-dot-10/