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

如何通过FFmpeg脚本在指定时间点按固定增量调整drawtext的y坐标?

Solution for Stepped Y-Coordinate Adjustment in FFmpeg Drawtext

Absolutely! You can implement this stepped Y-position change for your text using FFmpeg's built-in expression support in the drawtext filter. The core idea is to use conditional logic based on the video's timestamp to set the Y value at each specified interval.

Step-by-Step Explanation

FFmpeg allows you to use mathematical and conditional expressions (like gte for "greater than or equal") to dynamically calculate filter parameters. For your requirement, we'll build a nested if expression that checks the current video time t (in seconds) and sets the Y coordinate accordingly:

  • From 00:00:00 to 00:00:10 (and up to just before 00:00:11): Y = 0
  • From 00:00:11 to just before 00:00:43: Y = 10
  • From 00:00:43 to just before 00:10:44: Y = 20
  • From 00:10:44 onwards: Y = 30

Final Command

First, convert your timecodes to total seconds for easier calculation:

  • 00:10:44 = 10*60 + 44 = 644 seconds
  • 00:00:43 = 43 seconds
  • 00:00:11 = 11 seconds

Here's the working command (adjust for your OS):

Linux/macOS:

ffmpeg -i input.mp4 -vf 'drawtext=textfile=textfile.txt:x=0:y=if(gte(t,644),30,if(gte(t,43),20,if(gte(t,11),10,0))):fontsize=30:fontcolor=white:borderw=3:bordercolor=black:box=0' output.mp4

Windows:

ffmpeg -i input.mp4 -vf "drawtext=textfile=textfile.txt:x=0:y=if(gte(t,644),30,if(gte(t,43),20,if(gte(t,11),10,0))):fontsize=30:fontcolor=white:borderw=3:bordercolor=black:box=0" output.mp4

How the Expression Works

The nested if statements evaluate from the largest time downwards:

  1. gte(t,644): Checks if the current time is ≥ 10:44. If true, Y=30.
  2. If not, gte(t,43) checks if time is ≥ 00:43. If true, Y=20.
  3. If not, gte(t,11) checks if time is ≥ 00:11. If true, Y=10.
  4. The final 0 is the default value for all times before 00:11 (including 00:10 exactly).

This ensures the text jumps to the correct Y position exactly at your specified time points, with no smooth transition—just the hard step you need.

内容的提问来源于stack exchange,提问作者distro.obs

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 04:01:29