LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   ffmpeg can't record desktop + sound (https://www.linuxquestions.org/questions/linux-desktop-74/ffmpeg-cant-record-desktop-sound-4175412130/)

lord_didger 06-18-2012 04:19 PM

ffmpeg can't record desktop + sound
 
Sound in linux is obscure to me. I try to record my desktop + sound from applications running. So far I found I should use something like this
Code:

ffmpeg -f x11grab -s "1920x1080" -r "24" -i :0.0+0,0 -f alsa -ac 2 -i hw:0 -acodec libmp3lame -ab 64 -threads 8 -qscale 5 -b 1024 -ar 44100 -f flv test.out
looks like it records all I need
Code:

ffmpeg version 0.8.3-6:0.8.3-1, Copyright (c) 2000-2012 the Libav developers
  built on Jun  9 2012 13:36:42 with gcc 4.7.0
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[x11grab @ 0x2474320] device: :0.0+0,0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x2474320] shared memory extension  found
[x11grab @ 0x2474320] Estimating duration from bitrate, this may be inaccurate
Input #0, x11grab, from ':0.0+0,0':
  Duration: N/A, start: 1340053863.559315, bitrate: 1592524 kb/s
    Stream #0.0: Video: rawvideo, bgra, 1920x1080, 1592524 kb/s, 24 tbr, 1000k tbn, 24 tbc
[alsa @ 0x24873a0] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'hw:0':
  Duration: N/A, start: 3868.378728, bitrate: N/A
    Stream #1.0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
File 'test.out' already exists. Overwrite ? [y/N] y
Incompatible pixel format 'bgra' for codec 'flv', auto-selecting format 'yuv420p'
[buffer @ 0x2497600] w:1920 h:1080 pixfmt:bgra
[avsink @ 0x24977a0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x249b260] w:1920 h:1080 fmt:bgra -> w:1920 h:1080 fmt:yuv420p flags:0x4
Output #0, flv, to 'test.out':
  Metadata:
    encoder        : Lavf53.21.0
    Stream #0.0: Video: flv, yuv420p, 1920x1080, q=2-31, 1 kb/s, 1k tbn, 24 tbc
    Stream #0.1: Audio: libmp3lame, 44100 Hz, 2 channels, s16, 1 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #1.0 -> #0.1
Press ctrl-c to stop encoding
[alsa @ 0x24873a0] ALSA buffer xrun.
^Cframe=  94 fps= 24 q=5.0 Lsize=    3930kB time=3.87 bitrate=8328.4kbits/s dup=0 drop=9   
video:3911kB audio:15kB global headers:0kB muxing overhead 0.104241%
Received signal 2: terminating.

but in the end there is no sound in the output. I have pulse installed to test if it helps ('-i pulse'); no succeed. I have no loopbacks set cause I don't know if I need one and how to do that.

Any hint'd be appreciated

teckk 06-18-2012 09:30 PM

Code:

-f alsa -ac 2 -i hw:0
Are sure that's the correct alsa device?
Have you checked to see if your sound card has capturing output disabled in the hardware? Some sound devices like Intels and Nvidias have that disabled. You can get around it by jumping a cable from output to line in.

Code:

-ab 64
That should be 64k.

Code:

-qscale 5 -b 1024
You are doing q scale and then specifying a fixed bitrate. Either qscale 5 or -b 1024k

Code:

Stream #0.0: Video: flv, yuv420p, 1920x1080, q=2-31, 1 kb/s, 1k tbn, 24 tbc
    Stream #0.1: Audio: libmp3lame, 44100 Hz, 2 channels, s16, 1 kb/s

1kb/s might not be enough to hear anything.

lord_didger 06-19-2012 04:10 AM

Quote:

Are sure that's the correct alsa device?
I believe yes.
Code:

$ cat /proc/asound/cards
 0 [Intel          ]: HDA-Intel - HDA Intel
                      HDA Intel at 0xf7ff8000 irq 50
 1 [NVidia        ]: HDA-Intel - HDA NVidia
                      HDA NVidia at 0xfbe7c000 irq 17
$ cat /proc/asound/pcm
00-00: VT1828S Analog : VT1828S Analog : playback 1 : capture 2
00-01: VT1828S Digital : VT1828S Digital : playback 1 : capture 1
00-02: VT1828S HP : VT1828S HP : playback 1
01-03: HDMI 0 : HDMI 0 : playback 1
01-07: HDMI 0 : HDMI 0 : playback 1
01-08: HDMI 0 : HDMI 0 : playback 1
01-09: HDMI 0 : HDMI 0 : playback 1

I followed your suggestions concerning -ab -qscale. Presence of -qscale seems have no impact on sound. I added 'k' to -ab and -b and sound is better.

Although sound is present, it is low quality (bassless) and very silent. It look like I didn't hear the sound yesterday cause I worked with my headphones.

To record I use now
Code:

$ ffmpeg -f x11grab -s 1920x1080 -r 24 -i :0.0+0,0 -f alsa -ac 2 -i hw:0 -acodec libmp3lame -ab 192k -threads 8 -b 4096k -ar 44100 -f flv test.out
ffmpeg version 0.8.3-6:0.8.3-1, Copyright (c) 2000-2012 the Libav developers
  built on Jun  9 2012 13:36:42 with gcc 4.7.0
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
[x11grab @ 0x2641320] device: :0.0+0,0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x2641320] shared memory extension  found
[x11grab @ 0x2641320] Estimating duration from bitrate, this may be inaccurate
Input #0, x11grab, from ':0.0+0,0':
  Duration: N/A, start: 1340096864.961893, bitrate: 1592524 kb/s
    Stream #0.0: Video: rawvideo, bgra, 1920x1080, 1592524 kb/s, 24 tbr, 1000k tbn, 24 tbc
[alsa @ 0x26543a0] Estimating duration from bitrate, this may be inaccurate
Input #1, alsa, from 'hw:0':
  Duration: N/A, start: 4518.767438, bitrate: N/A
    Stream #1.0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
Incompatible pixel format 'bgra' for codec 'flv', auto-selecting format 'yuv420p'
[buffer @ 0x2664600] w:1920 h:1080 pixfmt:bgra
[avsink @ 0x26647a0] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x266a540] w:1920 h:1080 fmt:bgra -> w:1920 h:1080 fmt:yuv420p flags:0x4
Output #0, flv, to 'test.out':
  Metadata:
    encoder        : Lavf53.21.0
    Stream #0.0: Video: flv, yuv420p, 1920x1080, q=2-31, 4096 kb/s, 1k tbn, 24 tbc
    Stream #0.1: Audio: libmp3lame, 44100 Hz, 2 channels, s16, 4096 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #1.0 -> #0.1
Press ctrl-c to stop encoding
^Cframe=  375 fps= 24 q=31.0 Lsize=    8995kB time=15.73 bitrate=4685.6kbits/s dup=0 drop=1   
video:8365kB audio:614kB global headers:0kB muxing overhead 0.173481%
Received signal 2: terminating.

What can I do to improve the sound?

414N 06-19-2012 04:21 AM

I would record in an uncompressed format first, then reencode compressing video+audio.
You can try ffv1 as uncompressed video codec and pcm_s16le as uncompressed audio codec using avi as container.
After the recording finishes, you can recompress everything using your favorite formats.

lord_didger 06-19-2012 05:19 AM

FUCK!!! I realized why now there is any sound at all and yesterday there wasn't. My microphone within headphones recorded the audio!!!

In fact recording audio from my desktop doesn't work. The problem remains. What shell I do?


All times are GMT -5. The time now is 02:26 AM.