ffmpeg录制窗口应用时叠加滤镜、混音等处理的问题求助
Let's get your overlay and audio processing sorted out—you can choose between a one-step corrected command or a two-step workflow (record first, then apply effects) depending on what feels easier to debug and use.
Why Your Complex Command Failed
Your original command had a few critical issues that broke it:
- You never referenced the captured desktop video stream (
[1:v]from thegdigrabinput) in your filter chain—right now you were only manipulating thefilter.mp4video, ignoring the app recording entirely. - Typos like
-b:30(should be-b:vfor video bitrate) and mixing output format (flv) with file extension (mp4) caused conflicts. - The audio filter chain only processed
filter.mp4's audio, not mixing it with your captured app audio.
Solution 1: One-Step Corrected Command
This fixes stream references, typos, and adds proper mixing of your captured audio with the processed filter audio:
ffmpeg -rtbufsize 1500M \ -f dshow -i audio="virtual-audio-capturer" \ -f gdigrab -framerate 30 -draw_mouse 0 -i title="Main" \ -stream_loop 999 -i "filter/filter.mp4" \ -loop 999 -i "filter/nds_bg.mp4" \ -filter_complex " # Crop and resize the captured app video to final output size [1:v]crop=850:480:156:100,scale=640:360[v_captured]; # Process filter.mp4 for overlay blending [2:v]scale=385:216,setdar=16/9[v1]; [2:v]scale=385:216,setdar=16/9[v2]; [v1][v2]blend=shortest=1:all_opacity=1[v3]; # Prepare the background overlay video [3:v]setpts=N/(FRAME_RATE*TB),scale=640:360[v4]; # Layer overlays onto the captured app video [v_captured][v4]overlay=shortest=1:x=20:y=130[v_temp]; [v_temp][v3]overlay=shortest=1[v_final]; # Process filter audio and mix with captured app audio [2:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,asetrate=8.5/10*44100,atempo=10/8.5,lowpass=f=2500,highpass=f=400,volume=3,bass=g=-30,equalizer=f=10.5:width_type=o:width=1:g=-30,equalizer=f=31.5:width_type=o:width=1:g=-30,equalizer=f=63:width_type=o:width=1:g=-10,equalizer=f=125:width_type=o:width=1:g=-20,equalizer=f=250:width_type=o:width=1:g=-1.5,equalizer=f=500:width_type=o:width=1:g=-20,equalizer=f=1000:width_type=o:width=1:g=-20,equalizer=f=8000:width_type=o:width=3:g=1,equalizer=f=16000:width_type=o:width=3:g=1[v_filter_a]; [0:a][v_filter_a]amix=inputs=2:duration=shortest[a_final] " \ -map "[v_final]" -map "[a_final]" \ -vcodec libx264 -pix_fmt yuv420p -r 26 -g 30 -b:v 800k \ -acodec libmp3lame -b:a 128k -ar 44100 \ -preset:v ultrafast -bufsize 3000k -s 640x360 \ -shortest -y out.mp4
Key fixes here:
- Explicitly references your captured app video (
[1:v]) and audio ([0:a]) in the filter chain - Separates each filter step for readability
- Adds proper audio mixing between your captured audio and processed filter audio
- Corrects typos and format mismatches
Solution 2: Two-Step Workflow (Record First, Process Later)
If you prefer to split recording and processing (great for debugging), follow these steps:
Step 1: Record the Raw App & Audio
Use your working simple command to capture the base video:
ffmpeg -rtbufsize 1500M -f dshow -i audio="virtual-audio-capturer" -f gdigrab -framerate 30 -draw_mouse 0 -i title="Main" -vf crop=850:480:156:100 -pix_fmt yuv420p -profile:v baseline -y raw_recording.mp4
Step 2: Apply Overlays & Audio Effects
Take the raw recording and add your overlays/audio processing:
ffmpeg -i raw_recording.mp4 \ -stream_loop 999 -i "filter/filter.mp4" \ -loop 999 -i "filter/nds_bg.mp4" \ -filter_complex " # Resize raw recording to final output size [0:v]scale=640:360[v_captured]; # Process filter.mp4 for overlay blending [1:v]scale=385:216,setdar=16/9[v1]; [1:v]scale=385:216,setdar=16/9[v2]; [v1][v2]blend=shortest=1:all_opacity=1[v3]; # Prepare background overlay video [2:v]setpts=N/(FRAME_RATE*TB),scale=640:360[v4]; # Layer overlays onto raw recording [v_captured][v4]overlay=shortest=1:x=20:y=130[v_temp]; [v_temp][v3]overlay=shortest=1[v_final]; # Process filter audio and mix with raw recording audio [1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,asetrate=8.5/10*44100,atempo=10/8.5,lowpass=f=2500,highpass=f=400,volume=3,bass=g=-30,equalizer=f=10.5:width_type=o:width=1:g=-30,equalizer=f=31.5:width_type=o:width=1:g=-30,equalizer=f=63:width_type=o:width=1:g=-10,equalizer=f=125:width_type=o:width=1:g=-20,equalizer=f=250:width_type=o:width=1:g=-1.5,equalizer=f=500:width_type=o:width=1:g=-20,equalizer=f=1000:width_type=o:width=1:g=-20,equalizer=f=8000:width_type=o:width=3:g=1,equalizer=f=16000:width_type=o:width=3:g=1[v_filter_a]; [0:a][v_filter_a]amix=inputs=2:duration=shortest[a_final] " \ -map "[v_final]" -map "[a_final]" \ -vcodec libx264 -pix_fmt yuv420p -r 26 -g 30 -b:v 800k \ -acodec libmp3lame -b:a 128k -ar 44100 \ -preset:v ultrafast -bufsize 3000k -s 640x360 \ -shortest -y out.mp4
This way you can verify the raw recording is correct before adding effects, making it easier to spot issues if something goes wrong.
内容的提问来源于stack exchange,提问作者user3181176

