WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: ffmpeg rtmp stream of alsa / application sound  (Read 391 times)

Offline onelife

  • Jr. Member
  • **
  • Posts: 64
ffmpeg rtmp stream of alsa / application sound
« on: February 12, 2018, 12:40:21 AM »
Hi there Forum,

I'm hoping someone might have had some experience with this but maybe not posted here in the forum as I can't find much.

In short, I was trying to follow a setup guide that would create a loopback device of alsa similar to this :

Load the snd_aloop module:

Code: [Select]
modprobe snd-aloop pcm_substreams=1
Set the default ALSA audio output to one substream of the Loopback device in your .asoundrc (or /etc/asound.conf)

Code: [Select]
# .asoundrc
pcm.!default { type plug slave.pcm "hw:Loopback,0,0" }

You can now record audio from a running application using:

Code: [Select]
ffmpeg -f alsa -ac 2 -ar 44100 -i hw:Loopback,1,0 out.wav
But in trying to add the /etc/asound.conf file it causes alsa to stop working all together.

I'm trying to run a command in the end that would take the already playing sound from alsa (an application) and use ffmpeg to then send that stream to a RTMP server that would offer the feed as a streaming audio service.

Any ideas would be super welcome :)

Thank you!


Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9968
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #1 on: February 12, 2018, 02:31:34 AM »
Would it be easier to do it with pulseaudio?

Offline onelife

  • Jr. Member
  • **
  • Posts: 64
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #2 on: February 13, 2018, 12:55:32 AM »
Hummm, I'm not sure about Pulse - I've never used Pulse and our application works well with Alsa at the moment as it also uses an audio daemon similar to mpd. So could be difficult to move over to pulse  :(

Anyone got any ideas ?

Offline onelife

  • Jr. Member
  • **
  • Posts: 64
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #3 on: February 14, 2018, 03:16:41 AM »
Anyone have any ideas why this :

https://trac.ffmpeg.org/wiki/Capture/ALSA

The part about capturing from an application doesn't work on Pi Core? :

Record audio from an application
Load the snd_aloop module:

modprobe snd-aloop pcm_substreams=1
Set the default ALSA audio output to one substream of the Loopback device in your .asoundrc (or /etc/asound.conf)

# .asoundrc
pcm.!default { type plug slave.pcm "hw:Loopback,0,0" }
You can now record audio from a running application using:

ffmpeg -f alsa -ac 2 -ar 44100 -i hw:Loopback,1,0 out.wav

Really need to create a basic /etc/asound.conf file that will allow me to use ffmpeg.

Hope someone has any idea :)

Thanks

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9968
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #4 on: February 14, 2018, 03:53:47 AM »
tinycore extensions should be configured to use /usr/local/etc and not /etc - did you try ~/.asoundrc?

Offline onelife

  • Jr. Member
  • **
  • Posts: 64
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #5 on: February 14, 2018, 04:24:52 AM »
Sadly no luck, even with the .asoundrc in the folder /home/snb/ it doesn't seem to work.

Strangely in the file :

/usr/local/share/alsa/alsa.conf

It points to use /etc ?

Code: [Select]
snb@snb:~$ cat /usr/local/share/alsa/alsa.conf
#
#  ALSA library configuration file
#

# pre-load the configuration files

@hooks [
{
func load
files [
{
@func concat
strings [
{ @func datadir }
"/alsa.conf.d/"
]
}
"/etc/asound.conf"
"~/.asoundrc"
]
errors false
}
]

# load card-specific configuration files (on request)

cards.@hooks [

Really seems weird and in theory should be a simple setup :( - I've also tried the route of sending our application audio to /dev/stdout and that I can do, but then ffmpeg can't pipe it in.

ANY help from anyone please :)

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9968
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #6 on: February 14, 2018, 05:32:18 AM »
alsa was definately compiled to use /usr/local/etc/alsa in x86/x86_64 and alsa.conf still points to /etc/asound.conf

It doesn't help your case, but I'll change it in x86_64 and test what happens.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9968
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #7 on: February 15, 2018, 12:57:07 AM »
I gave this a go in corepure64 - I can record from my laptop built-in microphone (after first un-muting it) like this:
Code: [Select]
ffmpeg -f alsa -i hw:1 -t 30 out.wav
..but if i modify .asoundrc and load the loopback module as you mention above, I do not get any errors, but nothing is recorded.

You could ask for help on the alsa mailing list(s)?
« Last Edit: February 15, 2018, 03:06:54 AM by Juanito »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9968
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #8 on: February 15, 2018, 03:01:49 AM »
Got it  :)

If I set xmms to alsa playback via hw:2,0 - I can then record what xmms is playing with:
Code: [Select]
$ ffmpeg -f alsa -ac 2 -ar 44100 -i hw:2,1 out.wav
Where:
Code: [Select]
$ aplay -l | grep Loopback
card 2: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
card 2: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]

This is with a laptop running corepure64 - note also that, for some reason, hdmi sound always comes up as the alsa default and sound will not work unless I first load graphics-KERNEL.

I haven't played with sound much on the RPi, but as it also has hdmi there might be a similar issue?

Edit: This works on an RPi3 with picore 9.0.3:

Make some noise with:
Code: [Select]
$ speaker-test -Ddefault:1 -c2 -t wav -l1
Record the noise with:
Code: [Select]
$ ffmpeg -f alsa -ac 2 -ar 44100 -i hw:1,1 out.wav
Where:
Code: [Select]
$ aplay -l | grep Loopback
card 1: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
card 1: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]

Note that no ~/.asoundrc or graphics-KERNEL was required.
« Last Edit: February 15, 2018, 03:58:23 AM by Juanito »

Offline onelife

  • Jr. Member
  • **
  • Posts: 64
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #9 on: February 15, 2018, 08:21:02 AM »
AWESOME to hear you made some progress :) Thank you!

However, sorry - I'm not a guru at all. When you say you set xmms to use hw:2,0 what would this be?

xmms is you application I assume and the hw:2,0? How would I tell my application to use that hw or do I set that in Alsa config?

Sorry, maybe I missed a step, but something not right this side.

Thank you again!

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 9968
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #10 on: February 15, 2018, 09:56:24 PM »
I was using xmms to test on corepure64 and to check the file out.wav produced on an RPi3 using picore.

Did you try the commands listed after "Edit:" in the post above (these worked on the RPi3)?