You are not logged in.

#1 2014-09-02 07:12:24

balthamaisteri
Member
Registered: 2014-09-02
Posts: 26

FFMPEG recording sound quality

Hi,

I have problems with ffmpeg and audio quality when streaming to twitch, video quality is ok.

ffmpeg -i pulse records only microphone, but quality is pretty much good as it can get. However when streaming games, it would be cool to record game sounds as well.
ffmpeg -i hw:0 (hw:0,0) records desktop and gamesounds, but quality is really poor. Sounds are there, but volume is something like 50% with lots of static back noise.

Example: https://www.youtube.com/watch?v=qBUhpEgGRv0

Any ideas how I could fix this?

Offline

#2 2014-09-02 10:18:56

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: FFMPEG recording sound quality

I suspect you are recording sound coming out of the speakers through the microphone, when using ffmpeg in that manner with alsa, which would/should/could result in that kind of behaviour. You would have to look into pulseaudios configuration how to get a virtual microphone/mix input/output streams.
http://askubuntu.com/questions/257992/h … over-skype
Something in that direction.

Should my suspicion be incorrect, look at controls of a[lsa]mixer by simply running 'amixer' for the appropriate card.

Offline

#3 2014-09-03 14:25:42

balthamaisteri
Member
Registered: 2014-09-02
Posts: 26

Re: FFMPEG recording sound quality

That really sounds like recording speakers trough microphone, but that is not the case. I was using headphones and I was making sounds while playing, so microphone was not recording.

I will look into that link, thanks.

Offline

#4 2014-09-03 14:33:20

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: FFMPEG recording sound quality

Also read this, which suggests using something along those lines:

ffmpeg -f alsa -ac 1 -ar 44100 -i default:CARD=ICH5 -t 30 out.wav
# so in your case I would try
ffmpeg -f alsa -ac 1 -ar 48000 -i default:CARD=0 out.wav
# or simply
ffmpeg -f alsa -ac 1 -ar 48000 -i default out.wav

The 'default' runtime argument will ensure the sound card will not be blocked, since it refers to pcm.dmix and pcm.dsnoop. I would advise usnig the correct sample rate and resolution should ffmpeg accept it.

Edit: Added examples.

Last edited by emeres (2014-09-03 14:35:52)

Offline

#5 2014-09-03 17:34:04

balthamaisteri
Member
Registered: 2014-09-02
Posts: 26

Re: FFMPEG recording sound quality

default is pulse, so only microphone was recorded.

I got -i hw:0 somewhat bearable, by mixing with alsamixer. Had to mute line and adjust front mic boosts and recordings to be just fine. Static noise is almost gone but voice quality is still quite awful.

Here is my current settings: http://i.imgur.com/ZYY3RQq.png

I have no idea what happens when I restart my computer.

Offline

#6 2014-09-03 17:37:55

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: FFMPEG recording sound quality

That tells me nothing. Post instead:

arecord -lL;
cat /proc/asound/modules;
for i in /proc/asound/card[0-9]*; do echo "--- $i ---";amixer -c $(cat $i/id); done;

Edit: How is your PA set up? Does it use dmix and dsnoop as default sink and source? DOes it run when recording with ffmpeg?

Last edited by emeres (2014-09-03 17:41:32)

Offline

#7 2014-09-04 15:10:48

balthamaisteri
Member
Registered: 2014-09-02
Posts: 26

Re: FFMPEG recording sound quality

[ajnieminen@ceres ~]$ arecord -lL;
null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
default
    Default ALSA Output (currently PulseAudio Sound Server)
sysdefault:CARD=PCH
    HDA Intel PCH, ALC887-VD Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC887-VD Analog
    Front speakers
surround21:CARD=PCH,DEV=0
    HDA Intel PCH, ALC887-VD Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC887-VD Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC887-VD Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC887-VD Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC887-VD Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC887-VD Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
sysdefault:CARD=camera
    USB camera, USB Audio
    Default Audio Device
front:CARD=camera,DEV=0
    USB camera, USB Audio
    Front speakers
surround21:CARD=camera,DEV=0
    USB camera, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=camera,DEV=0
    USB camera, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=camera,DEV=0
    USB camera, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=camera,DEV=0
    USB camera, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=camera,DEV=0
    USB camera, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=camera,DEV=0
    USB camera, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=camera,DEV=0
    USB camera, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC887-VD Analog [ALC887-VD Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 2: ALC887-VD Alt Analog [ALC887-VD Alt Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: camera [USB camera], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

[ajnieminen@ceres ~]$ cat /proc/asound/modules;
 0 snd_hda_intel
 1 snd_hda_intel
 2 snd_usb_audio

[ajnieminen@ceres ~]$ for i in /proc/asound/card[0-9]*; do echo "--- $i ---";amixer -c $(cat $i/id); done;
--- /proc/asound/card0 ---
Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 64
  Mono: Playback 0 [0%] [-64.00dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 64
  Mono:
  Front Left: Playback 64 [100%] [0.00dB] [on]
  Front Right: Playback 64 [100%] [0.00dB] [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 0 [0%] [-51.00dB]
  Front Right: Playback 0 [0%] [-51.00dB]
Simple mixer control 'Front',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 64
  Mono:
  Front Left: Playback 0 [0%] [-64.00dB] [on]
  Front Right: Playback 0 [0%] [-64.00dB] [on]
Simple mixer control 'Front Mic',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 31 [100%] [12.00dB] [off]
  Front Right: Playback 31 [100%] [12.00dB] [off]
Simple mixer control 'Front Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]
Simple mixer control 'Surround',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 64
  Mono:
  Front Left: Playback 0 [0%] [-64.00dB] [on]
  Front Right: Playback 0 [0%] [-64.00dB] [on]
Simple mixer control 'Center',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 64
  Mono: Playback 0 [0%] [-64.00dB] [on]
Simple mixer control 'LFE',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 64
  Mono: Playback 0 [0%] [-64.00dB] [on]
Simple mixer control 'Line',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Line Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]
Simple mixer control 'IEC958 Default PCM',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 46
  Front Left: Capture 34 [74%] [18.00dB] [on]
  Front Right: Capture 34 [74%] [18.00dB] [on]
Simple mixer control 'Capture',1
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 46
  Front Left: Capture 36 [78%] [20.00dB] [off]
  Front Right: Capture 36 [78%] [20.00dB] [off]
Simple mixer control 'Auto-Mute Mode',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'Channel Mode',0
  Capabilities: enum
  Items: '2ch' '4ch' '6ch'
  Item0: '2ch'
Simple mixer control 'Digital',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 120
  Front Left: Capture 98 [82%] [19.00dB]
  Front Right: Capture 98 [82%] [19.00dB]
Simple mixer control 'Input Source',0
  Capabilities: cenum
  Items: 'Front Mic' 'Rear Mic' 'Line'
  Item0: 'Line'
Simple mixer control 'Input Source',1
  Capabilities: cenum
  Items: 'Front Mic' 'Rear Mic' 'Line'
  Item0: 'Front Mic'
Simple mixer control 'Rear Mic',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Rear Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]
--- /proc/asound/card1 ---
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',1
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',2
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',3
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
--- /proc/asound/card2 ---
Simple mixer control 'Mic',0
  Capabilities: cvolume cvolume-joined cswitch cswitch-joined
  Capture channels: Mono
  Limits: Capture 0 - 24
  Mono: Capture 24 [100%] [24.00dB] [on]
Simple mixer control 'Auto Gain Control',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]

I'm sorry, what is PA?

Offline

#8 2014-09-04 15:55:13

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: FFMPEG recording sound quality

PA=PulseAudio. You have capture/gain volumes at +20 dB, so the signal is amplified by [factor] 10 [V/V]. The front mic playback is at +12 dB and boost at 0 dB. Depending on hardware this might produce severe distortions, which could be perceived as poor quality. I would set capture gain/volume at 0 dB and try again. Use boost gain settings first, when adjusting the levels afterwards. But any sound processing could be done by software. There should be a possibility to do that on the fly with ffmpeg, try volume switch.
 You did not present the actual command you are using, am I supposed to guess all the time? You may also wan to disable 'IEC958 Default PCM' with `amixer -c 0 sset 'IEC958 Default PCM' off`.

Edit: Provide a little bit more information how PA is set up. Check the logs, especially the sampling frequency for capture devices. What PA does, should be also possible with alsa directly, maybe with little help from other applications.

Last edited by emeres (2014-09-04 15:57:56)

Offline

#9 2014-09-04 18:40:41

balthamaisteri
Member
Registered: 2014-09-02
Posts: 26

Re: FFMPEG recording sound quality

Sorry to keep you quessing, I know next to nothing about linux sound settings and configurations, so try to bear with me.

I will probably need to study a bit more about these things, I am afraid that I am not very userful for you.

This is my script to record my desktop, same goes for streaming (in .bashrc):

recording() {
     INRES="1920x1080" # input resolution
     OUTRES="1280x780" # output resolution
     FPS="30" # target FPS
     GOP="60" # i-frame interval, should be double of FPS, 
     GOPMIN="30" # min i-frame interval, should be equal to fps, 
     THREADS="4" # max 6
     CBR="1000k" # constant bitrate (should be between 1000k - 3000k)
     QUALITY="medium"  # one of the many FFMPEG preset
     AUDIO_RATE="44100"
     DATE=$(date +"%Y-%m-%d-%H-%M")
     
     ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 -f alsa -i hw:0 -f flv -ac 2 -ar $AUDIO_RATE -ab 128k \
       -vcodec libx264 -g $GOP -keyint_min $GOPMIN -b $CBR -minrate $CBR -maxrate $CBR -pix_fmt yuv420p\
       -s $OUTRES -preset $QUALITY -tune film -acodec libmp3lame -threads $THREADS -strict normal \
       -bufsize $CBR /home/user/recording_$DATE.mp4
 }

And sample record, sound is really weak (but doable) and seems to be coming more from left: https://www.youtube.com/watch?v=yEtH7qFOHVU

I had some problems with Wine and pulseaudio, then I tried all sorts of things that might be causing this. But I cannot be sure. I am pretty much a newb in these kind of things.

I will try to provide you with some logs and more information.

Offline

#10 2014-09-04 18:58:31

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: FFMPEG recording sound quality

 I think you want an additional space here, even though it apparently works:

-pix_fmt yuv420p \

I will take a look and report back, maybe there is part of the ffmpeg function that needs correction/mechanism that does that.
 Just to make sure, you want to record microphone and playback? Maybe you could simply add/replicate playback in PA and record those channels also, but alsa only approach is also possible. I remember having at least two thread about hardware loopback, this is one of those.

Edit: If PA is grabbing the sound device it might be reason. Run 'fuser -v /dev/snd/*' just before recording.

Last edited by emeres (2014-09-04 19:00:47)

Offline

#11 2014-12-05 16:27:20

balthamaisteri
Member
Registered: 2014-09-02
Posts: 26

Re: FFMPEG recording sound quality

Hi again, I finally found a solution.

Pavucontrol was the thing I really needed.

I started streaming with -f alsa -i pulse, and the changed input source with pavucontrol.

Thanks for you help guys!

Edit:

Now, If any one of you have any ideas how to also record mic, that would be great!

Maybe I should just wait that OBS is ready.

Last edited by balthamaisteri (2014-12-06 09:37:51)

Offline

Board footer

Powered by FluxBB