使用FFmpeg进行X11屏幕录制时出现Past duration过大等错误的求助
Let's break down what's going wrong and get you a working screen recording command tailored to your 1920x1080 display.
First, Fix the Syntax Error in Your Original Command
Your initial command has a critical typo: the -s (resolution) parameter uses a space between 1920 and 1080—FFmpeg interprets this as two separate invalid arguments. It should be 1920x1080 without spaces.
Address the "Not Enough Frames to Estimate Rate" Warning
This happens because FFmpeg needs more data to properly detect the stream's rate. Add these two parameters to give it enough buffer:
probesize 100M: Increases the amount of data FFmpeg reads to probe the streamanalyzeduration 100M: Gives FFmpeg more time to analyze the stream before starting encoding
Fix "Past Duration Too Large" Warnings & Slow Recording Speed (0.382x)
These issues stem from slow encoding performance. By default, FFmpeg might use a slow encoder preset that can't keep up with your 30fps capture. Switch to the ultrafast preset for libx264 (the most efficient H.264 encoder) to boost speed, and set a reasonable CRF (Constant Rate Factor) for balanced quality and file size.
The Final Working Command
ffmpeg -f x11grab -framerate 30 -probesize 100M -analyzeduration 100M -s 1920x1080 -i :0 -c:v libx264 -preset ultrafast -crf 23 -threads 0 /tmp/capture.mp4
Let's walk through the key parameters:
-framerate 30: Locks in your desired capture frame rate-c:v libx264: Uses the widely supported H.264 video encoder-preset ultrafast: Prioritizes encoding speed over file size (you can tweak this tofastormediumlater if you want smaller files and don't mind slower recording)-crf 23: Balances quality and file size (lower values = better quality, higher = smaller files; 23 is a reliable default)-threads 0: Lets FFmpeg use all available CPU cores for faster processing
Optional: Add Audio Capture
If you want to include system audio, add the ALSA input (use arecord -l to list your audio devices if default doesn't work):
ffmpeg -f x11grab -framerate 30 -probesize 100M -analyzeduration 100M -s 1920x1080 -i :0 -f alsa -ac 2 -i default -c:v libx264 -preset ultrafast -crf 23 -c:a aac -b:a 192k -threads 0 /tmp/capture_with_audio.mp4
内容的提问来源于stack exchange,提问作者showkey

