Monday, February 8, 2016

Capturing audio output with gstreamer

To figure out which output gstreamer's pulsesink will be using, and try to capture it, check

pactl list | grep -A2 "Source #"

Look for a monitor device which seems to correspond to speakers in this list - in my example this is "alsa_output.pci-0000_00_14.2.analog-stereo.monitor", shown as source #1 in my list.

Now catch the output using gstreamer, and save to some filename

gst-launch -e pulsesrc device="alsa_output.pci-0000_00_14.2.analog-stereo.monitor" ! audioconvert ! wavenc ! filesink location=test_wav.wav

You can listen to this file (if something was playing through xmms2 already), and verify that this gstreamer command is catching the right output device. It took me a few tries to figure out which monitor output was the right one.

This filename dump can also be a fifo, which means that the output can also be used with netcat.

First, on the listening machine
nc -l 8000 > test_wav.wav

Next, on the streamer

mkfifo streamer

gst-launch -e pulsesrc device="alsa_output.pci-0000_00_14.2.analog-stereo.monitor" ! audioconvert ! wavenc ! filesink location=streamer

then in another terminal, in the same directory

nc ip_addr_of_listening 8000 < streamer

No comments:

Post a Comment