You are not logged in.

#1 2013-03-07 19:20:47

HitomiTenshi
Member
Registered: 2013-03-07
Posts: 3

[Solved] ffmpeg records no sound

I use the following string to record a video with ffmpeg:

ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -threads 8 output.mkv

I only have alsa, no PulseAudio or OSS stuff.

I've been trying everything I managed to find through google but nothing seems to work. General sound output works, I can listen to music and do all my stuff like I'm used to, I just can't get ffmpeg to record my sound.

Here are logs from aplay and arecord:

aplay -L

null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=PCH
    HDA Intel PCH, ALC898 Analog
    Default Audio Device
sysdefault:CARD=PCH
    HDA Intel PCH, ALC898 Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    Front speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=PCH,DEV=0
    HDA Intel PCH, ALC898 Digital
    IEC958 (S/PDIF) Digital Audio Output
hdmi:CARD=NVidia,DEV=0
    HDA NVidia, HDMI 0
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=1
    HDA NVidia, HDMI 1
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=2
    HDA NVidia, HDMI 2
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 3
    HDMI Audio Output

aplay -l

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC898 Analog [ALC898 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: ALC898 Digital [ALC898 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

arecord -l

**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC898 Analog [ALC898 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 2: ALC898 Analog [ALC898 Analog]
  Subdevices: 2/2
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1

I'm using the latest ffmpeg-git with x264-git. (I compiled it correctly, so I don't think it's a build issue.)
I tried using -i default, -i sysdefault and -i plughw:0,0 instead of -i hw:0,0. I also tried various hw:0,1 etc. combinations, because I was fustrated and didn't know how to continue. I also tried recording only the sound, without the video, but nothing works at all.
Only the video runs perfectly fine. Please help.

Last edited by HitomiTenshi (2013-03-09 17:59:20)

Offline

#2 2013-03-08 16:45:51

HitomiTenshi
Member
Registered: 2013-03-07
Posts: 3

Re: [Solved] ffmpeg records no sound

Recording sound directly while playing something works with the following .asoundrc script:

pcm.!default
{
    type file
    slave.pcm
    {
          type plug
          slave.pcm
          {
                type hw
                card 0
                device 0
                subdevice -1
          }
    }
    file /dev/shm/audio.raw
    format raw
}

I then convert the raw file with ffmpeg from RAM. This is extremely annoying though, because the audio file isn't synced to the video. But IT WORKS. I want a solution with ffmpeg though, I have gathered more information, if somebody is interested:

amixer -c 0 contents

numid=42,iface=CARD,name='Front Headphone Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off

numid=44,iface=CARD,name='Front Mic Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off

numid=45,iface=CARD,name='Line Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off

numid=40,iface=CARD,name='Line Out CLFE Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off

numid=38,iface=CARD,name='Line Out Front Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=on

numid=41,iface=CARD,name='Line Out Side Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off

numid=39,iface=CARD,name='Line Out Surround Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off

numid=43,iface=CARD,name='Rear Mic Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=off

numid=46,iface=CARD,name='SPDIF Phantom Jack'
  ; type=BOOLEAN,access=r-------,values=1
  : values=on

numid=47,iface=CARD,name='SPDIF Phantom Jack',index=1
  ; type=BOOLEAN,access=r-------,values=1
  : values=on

numid=37,iface=MIXER,name='Master Playback Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on

numid=36,iface=MIXER,name='Master Playback Volume'
  ; type=INTEGER,access=rw---R--,values=1,min=0,max=87,step=0
  : values=70
  | dBscale-min=-65.25dB,step=0.75dB,mute=0

numid=12,iface=MIXER,name='Headphone Playback Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

numid=11,iface=MIXER,name='Headphone Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=87,step=0
  : values=87,87
  | dBscale-min=-65.25dB,step=0.75dB,mute=0

numid=53,iface=MIXER,name='PCM Playback Volume'
  ; type=INTEGER,access=rw---RW-,values=2,min=0,max=255,step=0
  : values=255,255
  | dBscale-min=-51.00dB,step=0.20dB,mute=0

numid=21,iface=MIXER,name='Front Mic Boost Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=3,step=0
  : values=0,0
  | dBscale-min=0.00dB,step=10.00dB,mute=0

numid=16,iface=MIXER,name='Front Mic Playback Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

numid=15,iface=MIXER,name='Front Mic Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=31,step=0
  : values=23,23
  | dBscale-min=-34.50dB,step=1.50dB,mute=0

numid=2,iface=MIXER,name='Front Playback Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

numid=1,iface=MIXER,name='Front Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=87,step=0
  : values=87,87
  | dBscale-min=-65.25dB,step=0.75dB,mute=0

numid=4,iface=MIXER,name='Surround Playback Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

numid=3,iface=MIXER,name='Surround Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=87,step=0
  : values=87,87
  | dBscale-min=-65.25dB,step=0.75dB,mute=0

numid=7,iface=MIXER,name='Center Playback Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on

numid=5,iface=MIXER,name='Center Playback Volume'
  ; type=INTEGER,access=rw---R--,values=1,min=0,max=87,step=0
  : values=87
  | dBscale-min=-65.25dB,step=0.75dB,mute=0

numid=8,iface=MIXER,name='LFE Playback Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on

numid=6,iface=MIXER,name='LFE Playback Volume'
  ; type=INTEGER,access=rw---R--,values=1,min=0,max=87,step=0
  : values=87
  | dBscale-min=-65.25dB,step=0.75dB,mute=0

numid=18,iface=MIXER,name='Line Playback Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

numid=17,iface=MIXER,name='Line Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=31,step=0
  : values=23,23
  | dBscale-min=-34.50dB,step=1.50dB,mute=0

numid=22,iface=MIXER,name='Capture Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

numid=23,iface=MIXER,name='Capture Switch',index=1
  ; type=BOOLEAN,access=rw------,values=2
  : values=off,off

numid=24,iface=MIXER,name='Capture Switch',index=2
  ; type=BOOLEAN,access=rw------,values=2
  : values=off,off

numid=25,iface=MIXER,name='Capture Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=63,step=0
  : values=63,63
  | dBscale-min=-17.25dB,step=0.75dB,mute=0

numid=26,iface=MIXER,name='Capture Volume',index=1
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=63,step=0
  : values=63,63
  | dBscale-min=-17.25dB,step=0.75dB,mute=0

numid=27,iface=MIXER,name='Capture Volume',index=2
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=63,step=0
  : values=63,63
  | dBscale-min=-17.25dB,step=0.75dB,mute=0

numid=35,iface=MIXER,name='IEC958 Default PCM Playback Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on

numid=31,iface=MIXER,name='IEC958 Playback Con Mask'
  ; type=IEC958,access=r-------,values=1
  : values=[AES0=0x0f AES1=0xff AES2=0x00 AES3=0x00]

numid=32,iface=MIXER,name='IEC958 Playback Pro Mask'
  ; type=IEC958,access=r-------,values=1
  : values=[AES0=0x0f AES1=0x00 AES2=0x00 AES3=0x00]

numid=33,iface=MIXER,name='IEC958 Playback Default'
  ; type=IEC958,access=rw------,values=1
  : values=[AES0=0x04 AES1=0x00 AES2=0x00 AES3=0x00]

numid=34,iface=MIXER,name='IEC958 Playback Switch'
  ; type=BOOLEAN,access=rw------,values=1
  : values=on

numid=19,iface=MIXER,name='Auto-Mute Mode'
  ; type=ENUMERATED,access=rw------,values=1,items=2
  ; Item #0 'Disabled'
  ; Item #1 'Enabled'
  : values=0

numid=54,iface=MIXER,name='Digital Capture Volume'
  ; type=INTEGER,access=rw---RW-,values=2,min=0,max=120,step=0
  : values=60,60
  | dBscale-min=-30.00dB,step=0.50dB,mute=0

numid=28,iface=MIXER,name='Input Source'
  ; type=ENUMERATED,access=rw------,values=1,items=3
  ; Item #0 'Rear Mic'
  ; Item #1 'Front Mic'
  ; Item #2 'Line'
  : values=2

numid=29,iface=MIXER,name='Input Source',index=1
  ; type=ENUMERATED,access=rw------,values=1,items=3
  ; Item #0 'Rear Mic'
  ; Item #1 'Front Mic'
  ; Item #2 'Line'
  : values=2

numid=30,iface=MIXER,name='Input Source',index=2
  ; type=ENUMERATED,access=rw------,values=1,items=3
  ; Item #0 'Rear Mic'
  ; Item #1 'Front Mic'
  ; Item #2 'Line'
  : values=2

numid=20,iface=MIXER,name='Rear Mic Boost Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=3,step=0
  : values=0,0
  | dBscale-min=0.00dB,step=10.00dB,mute=0

numid=14,iface=MIXER,name='Rear Mic Playback Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

numid=13,iface=MIXER,name='Rear Mic Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=31,step=0
  : values=23,23
  | dBscale-min=-34.50dB,step=1.50dB,mute=0

numid=10,iface=MIXER,name='Side Playback Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

numid=9,iface=MIXER,name='Side Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=87,step=0
  : values=87,87
  | dBscale-min=-65.25dB,step=0.75dB,mute=0

numid=49,iface=PCM,name='Capture Channel Map'
  ; type=INTEGER,access=r----R--,values=2,min=0,max=27,step=0
  : values=0,0
  |     | TLV size error (257, 8, 0)!

numid=48,iface=PCM,name='Playback Channel Map'
  ; type=INTEGER,access=r----R--,values=8,min=0,max=27,step=0
  : values=3,4,0,0,0,0,0,0
  |     | TLV size error (257, 8, 0)!

numid=50,iface=PCM,name='Playback Channel Map',device=1
  ; type=INTEGER,access=r----R--,values=2,min=0,max=27,step=0
  : values=0,0
  |     | TLV size error (257, 8, 0)!

numid=51,iface=PCM,name='Capture Channel Map',device=2
  ; type=INTEGER,access=r----R--,values=2,min=0,max=27,step=0
  : values=0,0
  |     | TLV size error (257, 8, 0)!

numid=52,iface=PCM,name='Capture Channel Map',index=1,device=2
  ; type=INTEGER,access=r----R--,values=2,min=0,max=27,step=0
  : values=0,0
  |     | TLV size error (257, 8, 0)!

Is there any way to add Item 'IEC958 Default PCM' to numid=28,iface=MIXER,name='Input Source'? I tried recording from 'Line' but it doesn't work.
Am I doing something wrong? I'm still digging mad for a solution, and only the .asoundrc script works this far.

Last edited by HitomiTenshi (2013-03-09 16:54:16)

Offline

#3 2013-03-09 14:47:29

bademaister
Member
From: Germany
Registered: 2011-05-31
Posts: 15

Re: [Solved] ffmpeg records no sound

Hey

you could try the .asoundrc from post #4

https://bbs.archlinux.org/viewtopic.php?id=147852

I could then record sound with audacity at least.


Bye

Paul

Offline

#4 2013-03-09 15:11:14

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 13,437

Re: [Solved] ffmpeg records no sound

Moderator comment:
HitomiTenshi:
Welcome to Arch Linux.  Thank you for using BBCode tags, but you should use [code ] [/code ] tags for program output and file dumps.  They provide scroll bars, and use an M-quad (monospace) font so that the columns line up.

Thanks.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
You assume people are rational and influenced by evidence.  You must not work with the public much. -- Trilby
----
How to Ask Questions the Smart Way

Offline

#5 2013-03-09 17:29:04

HitomiTenshi
Member
Registered: 2013-03-07
Posts: 3

Re: [Solved] ffmpeg records no sound

bademaister:
Thanks for your help! Recording sound works with the .asound script you showed me. I have to use the hw:2,1 device (card: Loopback, device: 1) for recording. There is a small drawback with this method though, there is a 1 sec delay in recording. If someone knows how to reduce this delay, please tell me. (probably changing period_size and buffer_size would reduce it, but I'm no expert in audio to be able to do that on my own)
For now I just remove the delay on the audio with a audio editing software. Thanks again bademaister!

Offline

Board footer

Powered by FluxBB