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

使用FFmpeg为视频添加文字时出错:无空格文字可正常添加

Fixing FFmpeg Drawtext Error with Spaces in Text Content

Hey there! This is such a common pitfall when working with FFmpeg's drawtext filter—let's get this sorted out quickly.

The Root Cause

When you include spaces in your text without proper quoting or escaping, your shell (like bash, zsh, or Windows Command Prompt) treats the space as a parameter separator. That means FFmpeg sees something like Hello as the value for text=, and then World gets interpreted as an unexpected extra parameter for the filter, which triggers the error.

Solutions

Here are the two most reliable ways to fix this:

  1. Wrap the text value in single quotes (preferred for Linux/macOS)
    Enclose the entire text string inside single quotes within the drawtext filter's argument. This tells the shell to pass the whole string as a single value.
    Example correct command:

    ffmpeg -i input.mp4 -vf "drawtext=text='Hello World':fontsize=24:x=50:y=50" output.mp4
    
  2. Escape spaces with a backslash
    If you prefer not to use quotes, you can add a backslash before each space to tell the shell to treat it as part of the string instead of a separator.
    Example:

    ffmpeg -i input.mp4 -vf "drawtext=text=Hello\ World:fontsize=24:x=50:y=50" output.mp4
    
  3. Double quotes for Windows Command Prompt/PowerShell
    On Windows, single quotes might not work as expected—use double quotes instead for the text value (note the double double-quotes to escape inner quotes for the shell):

    ffmpeg -i input.mp4 -vf "drawtext=text=""Hello World"":fontsize=24:x=50:y=50" output.mp4
    

Script Variable Tip

If you're using variables in a script (like a bash script), make sure you quote the variable when passing it to drawtext too. For example:

MY_TEXT="Hello Stack Overflow"
ffmpeg -i input.mp4 -vf "drawtext=text='$MY_TEXT':fontsize=24" output.mp4

This ensures that even if the variable has spaces, it's passed as a single, intact value to the filter.

内容的提问来源于stack exchange,提问作者robert tamunoemi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 07:19:33