FFmpeg滤镜组合语法咨询:为MP3+JPG生成的视频添加文字
Hey there! I see you've already nailed the core part of creating your audio waveform video with a JPG background—great job getting the colorkey and overlay working smoothly. The problem with your drawtext attempt is that you’re using two separate -filter_complex arguments, which FFmpeg doesn’t support. All complex filter operations need to live in a single chain, and you also need to make sure the text is applied after the overlay step so it appears on top of everything.
What Went Wrong
Your failed command tries to run two independent complex filter workflows: one for the waveform+overlay, and another for drawtext. FFmpeg can’t process these separately like that—you need to link all filter steps together in a sequential chain.
Corrected Command
Here’s a fixed version that integrates the drawtext filter properly into your existing setup:
ffmpeg -y -i 1.mp3 -loop 1 -i 1.jpg -filter_complex "[0:a]showwaves=s=1280x720:mode=cline,colorkey=0x000000:0.01:0.1,format=yuva420p[v_wave];[1:v][v_wave]overlay[v_overlay];[v_overlay]drawtext=text='My custom text test':fontcolor=White@0.5:fontsize=30:font=Arvo:x=(w-text_w)/5:y=(h-text_h)/5[v_final]" -map "[v_final]" -pix_fmt yuv420p -map 0:a -c:v libx264 -c:a copy -shortest output.mp4
Key Changes Explained
- Single
-filter_complexchain: All filter operations are now connected in one block, with named outputs ([v_wave],[v_overlay],[v_final]) to pass results between steps. - Drawtext applied after overlay: The text is added to the
[v_overlay]output (your JPG + waveform) instead of the raw waveform, ensuring it sits on top of the final frame. - Descriptive labeling: Using clear names for each filter output makes it easier to tweak or expand the workflow later.
Quick Troubleshooting Tip
If FFmpeg throws an error about the Arvo font not being found, specify the full path to the font file with the fontfile parameter:
drawtext=text='My custom text test':fontcolor=White@0.5:fontsize=30:fontfile=/full/path/to/Arvo.ttf:x=(w-text_w)/5:y=(h-text_h)/5[v_final]
You can adjust the x/y values to reposition the text, or modify the fontcolor alpha value (the @0.5 part) to make it more/less transparent.
内容的提问来源于stack exchange,提问作者shoku

