You are not logged in.

#1 2022-01-04 21:35:44

computernoob
Member
Registered: 2021-12-07
Posts: 10

Ffmpeg out of sync when adding audio input (Non-monotonous DTS)

Hi!

For the past 2 days I've been trying to figure out how to get ffmpeg to record my screen, desktop audio, and microphone at once. I'd like to have two commands, one that mix the two inputs into 1, and another with two tracks.

Recording just the X screen with "-f x11grab -r 30 -s 1920x1080 -i :0.0+1920,0" works great. Starts/stops immediately. When I add audio however the command takes a few seconds to start/stop. Watching the output, the video is paused for 4s~ before updating while audio works from the start. If I also add the desktop audio it will be quiet, but suddenly raise to full volume (also out of sync).

This is the message ffmpeg outputs while recording with the following command:

ffmpeg \
-f pulse -ac 2 -ar 48000 -i alsa_input.usb-BLUE_MICROPHONE_Blue_Snowball_201709-00.analog-stereo \
-f pulse -ac 2 -ar 48000 -i alsa_output.pci-0000_0a_00.4.analog-stereo.monitor \
-filter_complex amix=inputs=2 \
-f x11grab -r 30 -s 1920x1080 -i :0.0+1920,0 \
-c:v libx264 -c:a libmp3lame \
~/videos/output.mkv

[libmp3lame @ 0x55ac859ed3c0] Queue input is backward in timeitrate=   3.4kbits/s speed=0.457x
[matroska @ 0x55ac859ebfc0] Non-monotonous DTS in output stream 0:0; previous: 1969, current: 1954; changing to 1969. This may
result in incorrect timestamps in the output file.

The same message appears when doing:

ffmpeg -f pulse -i alsa_input.usb-BLUE_MICROPHONE_Blue_Snowball_201709-00.analog-stereo ~/videos/output.mkv

Same command as above but with "alsa_output.pci-0000_0a_00.4.analog-stereo.monitor" as input I only get the "Queue input is backward in time=" message.

My second command looks like this, as expected same results, except for the separate audio tracks and video seems to be playing on 3 fps:

ffmpeg \
-f x11grab -r 30 -s 1920x1080 -i :0.0+1920,0 \
-f pulse -ac 2 -i alsa_input.pci-0000_0a_00.4.analog-stereo.monitor \
-f pulse -ac 2 -i alsa_card.usb-BLUE_MICROPHONE_Blue_Snowball_201709-00.analog-stereo \
-map 0 -map 1 -map 2 \
-c:v libx264 -c:a libmp3lame \
~/videos/output.mkv

Seeing how recording just he X screen gives no errors it has two do with the audio devices. I'm not sure what it can be since replacing pulse with alsa gives me an input/output error. And the devices names are correct afaik seeing how other applications use the same and they work perfectly. One being audio-recorder, I can record the desktop and microphone audio with this application and the command it uses is:

gst-launch-1.0 -e  audiomixer name=mixer \
! level \
! audioresample ! audioconvert \
! audio/x-raw,rate=44100,channels=2 ! vorbisenc name=enc quality=0.5 ! oggmux \
! filesink location=test.ogg \
 pulsesrc device=alsa_input.usb-BLUE_MICROPHONE_Blue_Snowball_201709-00.analog-stereo ! queue ! mixer. \
 pulsesrc device=alsa_output.pci-0000_0a_00.4.analog-stereo.monitor ! queue ! mixer.

As seen here the device name is the same I had in my ffmpeg command. I also installed obs-studio (which I didn't want to do), just to make sure, and yes video and both audio inputs are synced correctly. I'm using pipewire as my sound server with wireplumber, I have pipewire-alsa and pipewire-pulse installed. What am I missing with my ffmpeg command? Thanks for reading!

$ pactl list | grep -A3 'Source #'
Source #149
        State: SUSPENDED
        Name: alsa_input.usb-BLUE_MICROPHONE_Blue_Snowball_201709-00.analog-stereo
        Description: Blue Snowball Analog Stereo
--
Source #65690
        State: SUSPENDED
        Name: alsa_output.pci-0000_08_00.1.pro-output-3.monitor
        Description: Monitor of GP104 High Definition Audio Controller Pro
--
Source #65692
        State: SUSPENDED
        Name: alsa_output.pci-0000_08_00.1.pro-output-7.monitor
        Description: Monitor of GP104 High Definition Audio Controller Pro 7
--
Source #65697
        State: SUSPENDED
        Name: alsa_output.pci-0000_08_00.1.pro-output-8.monitor
        Description: Monitor of GP104 High Definition Audio Controller Pro 8
--
Source #65691
        State: SUSPENDED
        Name: alsa_output.pci-0000_08_00.1.pro-output-9.monitor
        Description: Monitor of GP104 High Definition Audio Controller Pro 9
--
Source #65693
        State: SUSPENDED
        Name: alsa_output.pci-0000_08_00.1.pro-output-10.monitor
        Description: Monitor of GP104 High Definition Audio Controller Pro 10
--
Source #65696
        State: SUSPENDED
        Name: alsa_output.pci-0000_08_00.1.pro-output-11.monitor
        Description: Monitor of GP104 High Definition Audio Controller Pro 11
--
Source #65684
        State: SUSPENDED
        Name: alsa_output.pci-0000_08_00.1.pro-output-12.monitor
        Description: Monitor of GP104 High Definition Audio Controller Pro 12
--
Source #65689
        State: IDLE
        Name: alsa_output.pci-0000_0a_00.4.analog-stereo.monitor
        Description: Monitor of Starship/Matisse HD Audio Controller Analog Stereo
--
Source #150
        State: SUSPENDED
        Name: alsa_input.pci-0000_0a_00.4.analog-stereo
        Description: Starship/Matisse HD Audio Controller Analog Stereo

$ pw-cli dump short Node
28: s="suspended" n="Dummy-Driver"
29: s="suspended" n="Freewheel-Driver"
35: s="suspended" i=1/256 o=1/256 n="Midi-Bridge"
148: s="suspended" i=8/64 n="alsa_output.pci-0000_08_00.1.pro-output-12" p="alsa:pcm:0:hw:0,12:playback"
149: s="suspended" o=2/64 n="alsa_input.usb-BLUE_MICROPHONE_Blue_Snowball_201709-00.analog-stereo" p="alsa:pcm:2:front:2:capture"
150: s="suspended" o=2/64 n="alsa_input.pci-0000_0a_00.4.analog-stereo" p="alsa:pcm:1:front:1:capture"
153: s="suspended" i=2/64 n="alsa_output.pci-0000_0a_00.4.analog-stereo" p="alsa:pcm:1:front:1:playback"
154: s="suspended" i=8/64 n="alsa_output.pci-0000_08_00.1.pro-output-3" p="alsa:pcm:0:hw:0,3:playback"
155: s="suspended" i=8/64 n="alsa_output.pci-0000_08_00.1.pro-output-9" p="alsa:pcm:0:hw:0,9:playback"
156: s="suspended" i=2/64 n="alsa_output.pci-0000_08_00.1.pro-output-7" p="alsa:pcm:0:hw:0,7:playback"
157: s="suspended" i=8/64 n="alsa_output.pci-0000_08_00.1.pro-output-10" p="alsa:pcm:0:hw:0,10:playback"
160: s="suspended" i=8/64 n="alsa_output.pci-0000_08_00.1.pro-output-11" p="alsa:pcm:0:hw:0,11:playback"
161: s="suspended" i=2/64 n="alsa_output.pci-0000_08_00.1.pro-output-8" p="alsa:pcm:0:hw:0,8:playback"

$ cat /proc/asound/modules
 0 snd_hda_intel
 1 snd_hda_intel
 2 snd_usb_audio

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 11: HDMI 5 [HDMI 5]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: NVidia [HDA NVidia], device 12: HDMI 6 [HDMI 6]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic [HD-Audio Generic], device 0: ALCS1200A Analog [ALCS1200A Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Generic [HD-Audio Generic], device 1: ALCS1200A Digital [ALCS1200A Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

If something is missing just ask and I'll add it, I am a bit concerned of the suspend state not sure if it matters.

Offline

Board footer

Powered by FluxBB