[FFmpeg-user] ALSA buffer xrun. (ALSA_BUFFER_SIZE_MAX overflow)

Johann Rekowski johann.rekowski at googlemail.com
Sun Mar 17 15:17:25 CET 2013


Hello again dear ffmpeg developers,
I might have a clue why these ALSA buffer xruns happen when I record my 
stuff. I have changed:
*
libavdevice/alsa-audio.h*
from/#define ALSA_BUFFER_SIZE_MAX 65536/ (standard setting)
to///#define ALSA_BUFFER_SIZE_MAX 131072/

I'm trying to record a game with x11grab.
This is what I use to record my desktop & game:
/ffmpeg -f alsa -ac 2 -i hw:2,1 -f x11grab -r 30 -s 1920x1080 -i :0.0 
-acodec pcm_s16le -vcodec huffyuv -threads 8 output.avi/ (Using huffyuv 
now, because it drains less CPU than ffv1.3)

With the standard setting on the *ALSA_BUFFER_SIZE_MAX* I had buffer 
xruns happening at around this frame:
frame= 2488 fps= 30 q=0.0 size= 6853401kB time=00:01:22.93 
bitrate=676966.2kbits

I kinda made a routine to test for errors on that subject so it's almost 
always happening around the same frame.

After changing the *ALSA_BUFFER_SIZE_MAX* to a higher value (I just 
doubled the standard value) the video went on smooth without buffer 
xruns for a longer period of time, though buffer xruns still happened, 
just at a later frame:
frame= 4677 fps= 30 q=0.0 size=13727448kB time=00:02:35.90 
bitrate=721329.4kbits
ALSA buffer xrun.

After that frame, buffer xruns come on mass:
frame= 4692 fps= 30 q=0.0 size=13781424kB time=00:02:38.66 
bitrate=711565.1kbits
frame= 4707 fps= 30 q=0.0 size=13832176kB time=00:02:38.66 
bitrate=714185.5kbits
frame= 4722 fps= 29 q=0.0 size=13882906kB time=00:02:38.66 
bitrate=716804.9kbits
frame= 4737 fps= 29 q=0.0 size=13933639kB time=00:02:38.66 
bitrate=719424.3kbits
frame= 4752 fps= 29 q=0.0 size=13984366kB time=00:02:38.66 
bitrate=722043.5kbits
ALSA buffer xrun.
frame= 4767 fps= 29 q=0.0 size=14035112kB time=00:02:41.54 
bitrate=711725.9kbits
frame= 4782 fps= 29 q=0.0 size=14085854kB time=00:02:41.54 
bitrate=714299.1kbits
frame= 4797 fps= 29 q=0.0 size=14135082kB time=00:02:41.54 
bitrate=716795.5kbits
frame= 4813 fps= 29 q=0.0 size=14183865kB time=00:02:41.54 
bitrate=719269.3kbits
frame= 4829 fps= 29 q=0.0 size=14232106kB time=00:02:41.54 
bitrate=721715.6kbits
frame= 4845 fps= 29 q=0.0 size=14279003kB time=00:02:41.54 
bitrate=724093.7kbits
ALSA buffer xrun.
frame= 4861 fps= 30 q=0.0 size=14326897kB time=00:02:44.43 
bitrate=713743.1kbits
frame= 4876 fps= 30 q=0.0 size=14374458kB time=00:02:44.43 
bitrate=716112.5kbits
frame= 4891 fps= 30 q=0.0 size=14421272kB time=00:02:44.43 
bitrate=718444.7kbits
frame= 4908 fps= 30 q=0.0 size=14470500kB time=00:02:44.43 
bitrate=720897.2kbits
frame= 4925 fps= 30 q=0.0 size=14519139kB time=00:02:44.43 
bitrate=723320.3kbits
ALSA buffer xrun.
etc.

One buffer xrun ruins the whole audio that comes after it and makes my 
game lag horribly so it has to stop and never happen at all.
My clue is that there is some buffer overflow going on in the background 
with the audio. I'd be ready to post a backtrace or anything like that 
if needed, though it'll be a pretty huge time consuming process.

- Johann Rekowski


More information about the ffmpeg-user mailing list