WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline GNUser

  • Hero Member
  • *****
  • Posts: 884
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #15 on: August 03, 2022, 04:19:24 AM »
Hi, patrikg. I agree with your approach of separating video and audio to pinpoint the real problem. Video capture is working great. Audio capture using alsa's loopback device captures only silence.

I think the problem is that when I create the alsa loopback device, I continue to hear audio coming out of my speakers. For this project, I am not trying to send application audio to speakers and loopback concurrently (as in this thread: http://forum.tinycorelinux.net/index.php?topic=24910.15). I'm trying to send application audio only to loopback so that ffmpeg can capture it.

If you guys can help me figure out how to send all application audio to alsa's loopback device (so that I hear nothing coming out through speakers), then I should be able to figure out the rest.
« Last Edit: August 03, 2022, 04:30:11 AM by GNUser »

Offline GNUser

  • Hero Member
  • *****
  • Posts: 884
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #16 on: August 03, 2022, 05:04:16 AM »
If my laptop had a microphone input jack, I would be able to solve this by using a 3.5 mm male to male stereo audio cable and plugging in one end in headphone jack, other end in microphone jack.

Unfortunately, my laptop does not have a microphone input jack, so this simple hardware solution is not possible. I need to accomplish the same thing in software.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 10249
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #17 on: August 03, 2022, 06:08:09 AM »
Hi GNUser
... I think the problem is that when I create the alsa loopback device, I continue to hear audio coming out of my speakers. ...
A couple of thoughts. Maybe the ALSA mixer GUI (or pulse audio GUI) might be of some use.

Another possibility might be jack:
https://jackaudio.org/applications/
The  jack capture  program looks interesting:
Quote
a small program to capture whatever sound is going out to your speakers into a file.
Since everything in Linux is a file, maybe you can send the output to your loopback device. The link provided
for  jack capture  is no good, but I found it listed in github:
https://github.com/kmatheussen/jack_capture

Offline GNUser

  • Hero Member
  • *****
  • Posts: 884
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #18 on: August 03, 2022, 06:15:29 AM »
I figured it out :)
Code: [Select]
-> open a terminal emulator and enter these commands:
$ sudo modprobe snd-aloop pcm_substreams=1
$ echo 'pcm.!default { type plug slave.pcm "hw:Loopback,0,0" }' >$HOME/.asoundrc
$ ffmpeg -f alsa -ac 2 -ar 44100 -i hw:Loopback,1,0 -f x11grab -r 29.97 -s 1366x768 -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -crf 0 -threads 0 output.mkv
-> leave terminal open, run some application that produces audio and video
-> once done using the application, return to the terminal and press q for ffmpeg to stop recording
$ rm $HOME/.asoundrc
Now output.mkv contains video and audio streams (in sync) and plays back perfectly. Note that you must delete $HOME/.asoundrc for sound to come out through speakers again.

Thanks, patrikg and Rich! Rich, I will look into jackaudio. I had heard about it before and it sounds very promising.
« Last Edit: August 03, 2022, 06:20:05 AM by GNUser »

Offline GNUser

  • Hero Member
  • *****
  • Posts: 884
Re: ffmpeg rtmp stream of alsa / application sound
« Reply #19 on: August 03, 2022, 06:44:37 AM »
For posterity's sake: If you want to record your screen and your built-in microphone instead of system sound (e.g., to create a "screencast"), it is simpler to do. After a fresh boot, this should be sufficient:

Code: [Select]
$ ffmpeg -f alsa -ac 2 -ar 44100 -i hw:0 -f x11grab -r 29.97 -s 1366x768 -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -crf 0 -threads 0 output.mkv
When you are done recording, just press q in the terminal in which ffmpeg is running to make it stop recording. Note that my microphone is hw:0 but yours may be hw:1 (as Juanito's was--see Reply #7). If in doubt, try both or run "arecord -L" and take a look at the output.

I think this topic is solved ;D
« Last Edit: August 03, 2022, 06:49:14 AM by GNUser »