'Crackling sound when recording audio with ffmpeg

I'm trying to record from a microphone and webcam on MacOS with the following command:

ffmpeg -f avfoundation -framerate 30 -i "0:0" ~/recorded.mp4

My result has crackling in the audio.

I'm familiar with this problem when you use a DAW: you solve it by increasing the sample buffer. The idea is that audio samples coming from your interface/mic are not coming in a consistent or fast enough rate, so the missing samples being filled with zeroes causes the crackling sound. To avoid missing samples you want the recording software to wait longer for samples accumulating in a buffer before they're processed.

How can you configure such buffer for ffmpeg?



Solution 1:[1]

Version 4.3 seems to have this issue. Try with 4.2.

Solution 2:[2]

It seems to me that giving the -aq 0 audio quality parameter reduces this issue.

ffmpeg -f avfoundation -i 0:0 -acodec pcm_f32le -ar 48000 -aq 0 output.wav

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 Devin Roth
Solution 2 Chris Spiegl