ffmpeg alsa recording multiple applications audio
The trick is using dmix on loopback device:
2 dmixers; one for regualr onboard audio; the other for loopback virtual device, then duplicates streams send to onboard audio card, so you can hear what is being sent to loopback device.
Need to load snd_aloop module first;
My first audio device is onboard soundcard; 2nd is HDMI card, so I put index=2 for Loopback device.
file for .asoundrc
ffmpeg command to capture onboard sound card's microphone input and running desktop application's audio:
turn on capture in alsamixer, default is muted.
note:
using buffer_time = 0 or period_time = 0 is optional for buggy card; using buffer/period_size or buffer/period_time; but not both. format S32_LE works great for my card.
Changes:
for my card, I have to use period_time and period_size to fine tune:
If you have problem with flash player hogs one cpu core;
1. test sample rate 48000 back to 44100.
or and
2. using export FLASH_ALSA_DEVICE=plug:dmix_onboard
Thanks for hints from
https://unix.stackexchange.com/quest...ugins-together
https://bbs.archlinux.org/viewtopic.php?id=181922
https://youtu.be/mEV2O8C272g
2 dmixers; one for regualr onboard audio; the other for loopback virtual device, then duplicates streams send to onboard audio card, so you can hear what is being sent to loopback device.
Need to load snd_aloop module first;
Code:
modprobe snd-aloop index=2 id=Loopback pcm_substreams=1 enable=1
file for .asoundrc
Code:
# .asoundrc # periods INT # when buffer_size or buffer_time is not specified #defaults.pcm.rate_converter "speexrate_medium" pcm.snd_onboard { type hw card 0 device 0 } pcm.snd_loopout { type hw card 2 device 0 channels 2 } pcm.snd_loopin { type hw card 2 device 1 channels 2 } pcm.!default { type plug slave.pcm "dual" } pcm.dual { type asym playback.pcm "looptoreal" capture.pcm "dsnooploop " } pcm.looptoreal { type plug slave.pcm { type multi slaves { a { channels 2 pcm "dmix_onboard" } b { channels 2 pcm "dmixloop" } } bindings { 0 { slave a channel 0 } 1 { slave a channel 1 } 2 { slave b channel 0 } 3 { slave b channel 1 } } } route_policy "default" #default; duplicate; and copy #Manual setting up ttable if you have problem of out sync audio with video in flash. # ttable.0.0 1 # ttable.1.1 1 # ttable.0.2 1 # ttable.1.3 1 # ttable [ [ 1 0 1 0 ] [ 0 1 0 1 ] ] #same as above } pcm.dmix_onboard { type dmix ipc_key 234567 ipc_key_add_uid false ipc_perm 0660 slave.pcm "snd_onboard" slave { rate 48000 channels 2 buffer_time 0 period_size 4096 buffer_size 8192 format S32_LE } bindings { 0 0 1 1 } } pcm.dmixloop { type dmix ipc_key 345678 ipc_key_add_uid false ipc_perm 0660 slave.pcm "snd_loopout" slave { rate 48000 channels 2 buffer_time 0 period_size 4096 buffer_size 8192 format S32_LE } bindings { 0 0 1 1 } } pcm.dsnooploop { type dsnoop ipc_key 456789 ipc_key_add_uid false ipc_perm 0660 slave.pcm "snd_loopin" slave { rate 48000 channels 2 buffer_time 0 period_size 4096 buffer_size 8192 format S32_LE } bindings { 0 0 1 1 } } pcm.duplexloop { type plug slave.pcm { type asym playback.pcm "dmixloop" capture.pcm "dsnooploop" } } pcm.card0 { type plug pcm "dual" } clt.snd_onboard { type hw card 0 } clt.!default { type hw card 2 } ctl.multiloop { type hw card 2 } ctl.mixloop { type hw card 2 } clt.dmixer { type hw card 0 } ctl.snd_loopout { type hw card 2 } ctl.snd_loopin { type hw card 2 } ctl.dsnooploop { type hw card 2 }
turn on capture in alsamixer, default is muted.
Code:
ffmpeg -f alsa -acodec pcm_s32le -ac 2 -ar 48000 -i hw:0,2 -f alsa -acodec pcm_s32le -ac 2 -ar 48000 -i duplexloop -filter_complex amix=inputs=2 -f x11grab -r 25 -s 1366x768 -i :0.0+0,0 -vcodec libx264 -preset veryfast -crf 18 -acodec libmp3lame -ar 48000 -pix_fmt yuv420p -y test.mkv
note:
using buffer_time = 0 or period_time = 0 is optional for buggy card; using buffer/period_size or buffer/period_time; but not both. format S32_LE works great for my card.
Changes:
for my card, I have to use period_time and period_size to fine tune:
If you have problem with flash player hogs one cpu core;
1. test sample rate 48000 back to 44100.
or and
2. using export FLASH_ALSA_DEVICE=plug:dmix_onboard
Code:
period_time=50000 #125000usecs. default period_size=2048 note: html5 audios problem period_time = 15625 #125000 / 8 period_size = 1024
https://unix.stackexchange.com/quest...ugins-together
https://bbs.archlinux.org/viewtopic.php?id=181922
https://youtu.be/mEV2O8C272g
Total Comments 0