You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何简化FFmpeg脚本并添加带定时淡入淡出效果的文字

Simplified FFmpeg Script with Text Fade In/Out

Got it, let’s streamline your FFmpeg script while adding smooth text transitions with proper timing. The original split filter was unnecessary here—we can directly generate a transparent text layer and overlay it onto your video, making the code cleaner and easier to tweak.

Streamlined Script

ffmpeg -y -i video.mp4 -filter_complex "
# Create text layer with initial transparency, then add fade effects
drawtext=fontfile=gvr.otf:text='Which of these is not an event listener adapter defined in the java.awt.event package?':fontcolor=white:fontsize=40:x=100:y=200:alpha=0,
fade=t=in:st=1:d=1:alpha=1,  # Fade in starting at 1s, taking 1s to complete
fade=t=out:st=8:d=1:alpha=1[text_overlay];
# Overlay the text layer onto the original video
[0][text_overlay]overlay" output.mp4

Key Improvements & Customization Tips

  • Removed redundant split filter: We don’t need to duplicate the video stream—generating the text layer separately and overlaying it is more efficient and easier to follow.
  • Controlled timing:
    • Text starts fading in at 1 second (st=1) and finishes fading in after 1 second (d=1), so it’s fully visible from 2s to 8s.
    • Fade-out starts at 8 seconds (st=8) and takes 1 second (d=1), so the text disappears completely by 9s.
  • Easy tweaks for your needs:
    • To center the text automatically (works for any video resolution), replace x=100:y=200 with x=(w-text_w)/2:y=(h-text_h)/2.
    • Adjust fade speed: Change d=1 to d=0.5 for a faster 0.5s transition, or d=2 for a slower, more subtle fade.
    • Extend text display time: If you want the text to stay visible longer, set the fade-out start time (st=8) to a later value (e.g., st=12 for 10s of total visible time including fades).
    • Boost text readability: Add a soft shadow with shadowcolor=black:shadowx=2:shadowy=2 inside the drawtext filter.

Quick Note

Ensure your source video is at least as long as the total text timeline (in the example, the video needs to be 9s or longer to avoid errors). If your video is shorter, adjust the fade-out start time (st=8) to match the video’s duration minus the fade-out time (e.g., st=5 for a 6s video with 1s fade-out).

内容的提问来源于stack exchange,提问作者Pravesh Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:21:45