ffmpeg screen capturing: ALSA - pulseaudio sound problems

Hi,
i am currently trying to unterstand how screen capturing with ffmpet works, i found some commands to use but i do not understand what most of the details actually do, but at the moment i have a problem getting the sound capturing to work.
I tried this command:

ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1920x1200 -i :0.0+1680,0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -crf 0 -threads 0 testout.mkv

BTW: for testing the -i :0.0+1680,0 can be replaced by -i :0.0
but i need the first option because of my monitor setup.

This results in this error:

ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s 1920x1200 -i :0.0+1680,0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -crf 0 -threads 0 testout.mkv
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (SUSE Linux)
  configuration: --shlibdir=/usr/lib64 --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib64 --enable-shared --disable-static --enable-debug --disable-stripping --extra-cflags='-fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g' --enable-pic --optflags='-fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g' --enable-gpl --enable-x11grab --enable-version3 --enable-pthreads --datadir=/usr/share/ffmpeg --enable-avfilter --enable-libpulse --enable-libwebp --enable-libvpx --enable-libopus --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libxvid --enable-libx264 --enable-libx265 --enable-libschroedinger --enable-libgsm --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-postproc --enable-libdc1394 --enable-librtmp --enable-libfreetype --enable-avresample --enable-libtwolame --enable-libvo-aacenc --enable-gnutls --enable-libass --enable-frei0r --enable-libcelt --enable-libcdio --enable-ladspa
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM pulse
[alsa @ 0x74ba00] cannot open audio device pulse (No such file or directory)
pulse: Input/output error

So it seems pulse is not recognized, so i tried another option i found, replacing pulse by hw:0

this kind of works, but i only get the video and no audio!

Whats the problem here, what audio option can i use, is there a way to find a list of them?
What i am trying to achieve is to capture the system audio (browser, music player and such) not my microphone!

try this:

ffmpeg -f alsa -ac 2 -i default -f x11grab -r 30 -s 1920x1200 -i  :0.0+1680,0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -crf 0  -threads 0 testout.mkv

Nominally pulse audio should be your default record device.

After launching ffmpeg with that, you may also need to go to pavucontrol and in the “recording tab” next to "ALSA plug-in [ffmpeg] : ALSA capture from " select your recording device. Else you may only get static.

" -i default " works for me, albeit the remainder of my ffmpeg line is different from yours, and I did not check out the rest of your ffmpeg line.

Yes this kind of worked, i had to change the device in pavucontrol though as you said.
I am not sure but it could be that there are some slowdown or slow motion effects, i need to investigate this further.

What does this error/warning means:


No pixel format specified, yuv444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.                       
[libx264 @ 0x19e8a20] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x19e8a20] profile High 4:4:4 Predictive, level 5.0, 4:4:4 8-bit
[libx264 @ 0x19e8a20] 64 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to 'nop.mkv':
  Metadata:
    encoder         : Lavf56.36.100
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv444p, 1920x1200, q=-1--1, 30 fps, 1k tbn, 30 tbc
    Metadata:
      encoder         : Lavc56.41.100 libx264
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc56.41.100 pcm_s16le
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, ?] for help
[x11grab @ 0x19df400] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
[alsa @ 0x19c8a00] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame= 1583 fps= 32 q=-1.0 Lsize=   78427kB time=00:00:52.76 bitrate=12175.6kbits/s    
video:68375kB audio:9772kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.357776%
[libx264 @ 0x19e8a20] frame I:7     Avg QP: 0.00  size:1380498
[libx264 @ 0x19e8a20] frame P:1576  Avg QP: 0.00  size: 38294
[libx264 @ 0x19e8a20] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x19e8a20] mb P  I16..4: 25.2%  0.0%  0.0%  P16..4:  1.4%  0.0%  0.0%  0.0%  0.0%    skip:73.4%
[libx264 @ 0x19e8a20] coded y,u,v intra: 7.9% 5.9% 6.3% inter: 1.6% 1.2% 1.3%
[libx264 @ 0x19e8a20] i16 v,h,dc,p: 93%  6%  0%  0%
[libx264 @ 0x19e8a20] kb/s:10615.04
Received signal 2: terminating.

Iam talking about the “Thread message queue blocking; consider raising the thread_queue_size option”

is there something i can do about this?

Why ? Is it a problem ?

I have read “-thread_queue_size 512” as a parameter gets rid of that message if it causes one some annoyance, but whether that makes things better or worse I can not say.

I do not now what it means, thats it.
Additionally i am sure now that there is a problem with the capturing, i am not sure if this effects the video two but the sound is kind of wobbly!
I thought that this could be related to the thread size message (which i was not able to change btw. i added it to the command but that did not had any effect), or could this be audio codec related?

Try capturing at a slower frame rate. ie intead of 30 fps


-r 30

try 15 fps


-r 15

That eases the load on your PCs CPU and with less of a load, maybe it will help in the audio capture.

I tried 15 fps but the wobbly (not stuttering!) audio is still there, and btw i have i pretty good cpu i think, it is a Intep Core i7-980X (6 cores (12 with HT)) and running ffmpeg barely shows any cpus usage.

But instead of the “pcm_s16le” acodec i tried “libvorbis” (with 30 fps) this time the audio was perfect i think, but there way one irritating warning at the beginning:

[libvorbis @ 0x176d900] Queue input is backward in time

and a lot of warnings of this type (about 50):


[matroska @ 0x176b3c0] Non-monotonous DTS in output stream 0:1; previous: 0, current: -1822; changing to 0. This may result in incorrect timestamps in the output file.

I am not sure if there is any delay or if the video/audio is asynchronous but these warnings irritate me.

Are there any other tips on how to investigate whats the reason for the audio problems i described?

Your questions are very ffmpeg specific. May I suggest you follow up on a communications channel that is specific to ffmpeg ? Possibly this link will offer some venues to follow up this question on : https://ffmpeg.org/contact.html