[FFmpeg-user] Read from pulseaudio - latency - how to fix!
Ferdi Scholten
ferdi at sttc-nlp.nl
Fri Sep 2 00:15:04 EEST 2022
On 01-09-2022 17:06, Thomas Seilund via ffmpeg-user wrote:
> Dear All
>
> I do live streaming and I need to pick up the audio from a microphone.
>
> I test latency like this:
>
> ffplay -f pulse -i
> "alsa_input.usb-Remo_Tech_Co.__Ltd._OBSBOT_Tiny-02.analog-mono"
>
> ffplay -f alsa -i default
>
> After running one of the commands I can hear my own voice in my
> headphones. I am happy.
>
> But the first command gives a delay of 3 sec. The other command gives
> close to no delay.
>
> How can I fix the first command to get close to no delay?
>
> Both command records from the same microphone and output to the same
> headphones.
>
> What I see is that the black screen from ffplay takes about 3 sec to
> display with the first command but shows up close to instantly with
> the second command.
>
> Here is output from the two commands:
>
> ffplay -f pulse -acodec pcm_s16le -i
> "alsa_input.usb-Remo_Tech_Co.__Ltd._OBSBOT_Tiny-02.analog-mono"
>
> ffplay version N-104384-g374f2ac370 Copyright (c) 2003-2021 the FFmpeg
> developers
>
> built with gcc 8 (Debian 8.3.0-6)
>
> configuration: --enable-libfreetype --enable-libx264 --enable-gpl
> --enable-libvorbis --enable-libvpx --enable-libmp3lame --enable-libzmq
> --enable-libpulse
>
> libavutil 57. 7.100 / 57. 7.100
>
> libavcodec 59. 12.100 / 59. 12.100
>
> libavformat 59. 6.100 / 59. 6.100
>
> libavdevice 59. 0.101 / 59. 0.101
>
> libavfilter 8. 14.100 / 8. 14.100
>
> libswscale 6. 1.100 / 6. 1.100
>
> libswresample 4. 0.100 / 4. 0.100
>
> libpostproc 56. 0.100 / 56. 0.100
>
> Input #0, pulse, from
> 'alsa_input.usb-Remo_Tech_Co.__Ltd._OBSBOT_Tiny-02.analog-mono':
>
> Duration: N/A, start: 1662044141.069410, bitrate: 1536 kb/s
>
> Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
>
> 1662044142.91 M-A: -0.000 fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0
>
>
> ffplay -f alsa -i default
>
> ffplay version N-104384-g374f2ac370 Copyright (c) 2003-2021 the FFmpeg
> developers
>
> built with gcc 8 (Debian 8.3.0-6)
>
> configuration: --enable-libfreetype --enable-libx264 --enable-gpl
> --enable-libvorbis --enable-libvpx --enable-libmp3lame --enable-libzmq
> --enable-libpulse
>
> libavutil 57. 7.100 / 57. 7.100
>
> libavcodec 59. 12.100 / 59. 12.100
>
> libavformat 59. 6.100 / 59. 6.100
>
> libavdevice 59. 0.101 / 59. 0.101
>
> libavfilter 8. 14.100 / 8. 14.100
>
> libswscale 6. 1.100 / 6. 1.100
>
> libswresample 4. 0.100 / 4. 0.100
>
> libpostproc 56. 0.100 / 56. 0.100
>
> Input #0, alsa, from 'default': 0KB vq= 0KB sq= 0B f=0/0
>
> Duration: N/A, start: 1662044161.792616, bitrate: 1536 kb/s
>
> Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
>
> 1662044163.53 M-A: 0.000 fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0
>
> Regards
>
> Thomas S
Simple, the first command uses pulseaudio which is userspace to read
from alsa which is in kernelspace.
The second command bypasses userspace to read directly from alsa
therefor has less latency.
Pulseaudio is not known for its low latency, if you need to use a sound
server in userspace with low latency use jack.
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-user
mailing list