'Arecord->FFMPEG works but FFMPEG w/ ALSA stutters?
I am trying to stream audio from my Pi Zero and my I2s MEMS mic. I would like to stream using FFMPEG and ALSA (which I have already compiled) but I'm running into stuttering issues.
FFMPEG + ALSA
~/special/ffmpeg/ffmpeg -report -f alsa -ar 48000 -ac 2 -acodec pcm_s32le -i mic_sv -f lavfi -i testsrc -c:v h264_omx -c:a aac -ab 32k -bufsize 32k -f flv rtmp://209.85.230.23/live2/KEY
This results in constant stuttering and choppiness.
Arecord piped directly to FFMPEG
arecord -Dmic_sv -c2 -r48000 -fS32_LE | ~/special/ffmpeg/ffmpeg -report -acodec pcm_s32le -i - -f lavfi -i testsrc -c:v h264_omx -acodec aac -ab 32k -bufsize 32k -f flv rtmp://209.85.230.23/live2/KEY
This results in a coherent audio stream, but with skipping every 5 seconds or so.
Arecord recorded to a wav file, piped into FFMPEG
arecord -Dmic_sv -c2 -r48000 -fS32_LE -twav temp.v & ~/special/ffmpeg/ffmpeg -report -re -i temp.v -f lavfi -i testsrc -c:v h264_omx -ac 2 -acodec aac -ab 32k -bufsize 32k -async 2 -f flv rtmp://209.85.230.23/live2/KEY
This results in a perfect audio stream.
I don't know why #3 works but #2 and #1 cause problems. Any suggestions?
Solution 1:[1]
Well well off we go to my every first Stackoverflow post :)
So you probably experience a message saying [alsa buffer run] or similar. The reason for this is indeed because the buffer fills up faster than it can be processed. The only real mitigation I found was to change the sampling rate to 22050hz
here is some code that should work:
ffmpeg -re -v verbose -hide_banner -f v4l2 -thread_queue_size 1024 -re -i temp.v -ar 11025 -f alsa -ac 1 -thread_queue_size 1024 -i default -b:a 64k -c:v libx264 -preset ultrafast -strict experimental -f flv -g 20 -keyint_min 20 -maxrate 2M -bufsize 6M -acodec aac rtmp://209.85.230.23/live2/KEY
p.s. Sorry for the late reply.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tom Smith |
