You are not logged in.

#1 2013-06-01 17:30:44

tdc
Member
Registered: 2013-05-07
Posts: 9

[SOLVED] Capture microphone and pc sound with ffmpeg

Hi,
I'm currently trying to capture my microphone and my pc sound with ffmpeg. When I'm simply using:

ffmpeg -f alsa -i pulse out.wav

It just records the microphone.

As solution I most articles/sites describe an audio loop, but if I set it up with:

#!/bin/bash
pactl load-module module-null-sink sink_name=mix 
pactl load-module module-loopback sink=mix
pactl load-module module-loopback sink=mix

And the settings in pavucontrol it works fine for some time. But after around 40 seconds to one minute I get the output:

Press [q] to stop, [?] for help
st:0 PTS: 3903486 DTS: 3903486 < 3903489 invalid, clipping
st:0 PTS: 4403071 DTS: 4403071 < 4403074 invalid, clipping

And after one of these messages appear the sound quality becomes really bad.

Is there a way to fix this or is there a better solution to mix two audio streams with pulseaudio?

Last edited by tdc (2013-06-08 14:54:14)

Offline

#2 2013-06-01 17:40:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] Capture microphone and pc sound with ffmpeg

I'm not sure why you're trying to use a video tool for audio.  I'd suggest sox, this is what is made for.

man sox wrote:

SoX  reads  and  writes audio files in most popular formats and can optionally apply effects to them. It can combine multiple input sources, synthesise audio,
       and, on many systems, act as a general purpose audio player or a multi-track audio recorder. It also has limited ability to split the input into multiple out‐
       put files


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2013-06-01 18:13:43

tdc
Member
Registered: 2013-05-07
Posts: 9

Re: [SOLVED] Capture microphone and pc sound with ffmpeg

The problem is that I have to combine it with video later. I just removed the video capturing parts of the script to make it simpler.

Offline

#4 2013-06-01 20:25:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [SOLVED] Capture microphone and pc sound with ffmpeg

Later meaning in a different part of the script, or later as in at some later point you're going to add that to the same command?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2013-06-01 20:38:43

tdc
Member
Registered: 2013-05-07
Posts: 9

Re: [SOLVED] Capture microphone and pc sound with ffmpeg

Up until now I captured audio and video in the same command.

Last edited by tdc (2013-06-01 20:38:52)

Offline

#6 2013-06-04 12:37:19

tdc
Member
Registered: 2013-05-07
Posts: 9

Re: [SOLVED] Capture microphone and pc sound with ffmpeg

I took another look into it and this article uses amix to mix the two streams. The problem I got there is that it seems like pulseaudio is blocking alsa because if I try to use e.g.:

ffmpeg -f alsa -i hw:0,0 out.wav

I get:

[alsa @ 0xdc6f80] cannot open audio device hw:0,0 (Device or resource busy)
hw:0,0: Input/output error

How can I still use alsa when I have pulseaudio running on my System?

Offline

#7 2013-06-04 17:50:06

DrZaius
Member
Registered: 2008-01-02
Posts: 193

Re: [SOLVED] Capture microphone and pc sound with ffmpeg

Does your audio system contain a hardware loopback device? You can see in alsamixer and it would likely have the word "mix" in its name such as "Stereo Mix" or "Wave out mix". Seems to be a rare thing these days, but if you do then ffmpeg can use that directly. If not then you can look into dmix and/or dsnoop.

Offline

#8 2013-06-04 20:43:50

tdc
Member
Registered: 2013-05-07
Posts: 9

Re: [SOLVED] Capture microphone and pc sound with ffmpeg

My alsamixer shows just two bars "Master" and "Capture"... the problem is I don't know how to use amix or dmix because usually you give them the alsa input sources. It seems like for me pulseaudio blocks these sources. (see my last reply)
I could shutdown pulseaudio but some applications I use need it. Is there a way to use the alsa input sources while pulseaudio is running?


Edit: Seems like I solved it. First I had to close all applications using pulseaudio so that the "Device or resource busy" message doesn't appear anymore. Then I had to activate both capture-switches in alsamixer and mix hw:0,0 und hw:0,2 with amix.

Last edited by tdc (2013-06-08 14:51:18)

Offline

Board footer

Powered by FluxBB