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

FFmpeg生成视频报错:无法找到'is'的合适输出格式求助

问题解决:FFmpeg报错「Unable to find a suitable output format for 'is'」

核心原因

你的quote变量包含空格(比如示例里的"This is a quote"),但构造FFmpeg命令时,drawtext滤镜的text参数没加引号包裹,空格被Shell当成命令分隔符,FFmpeg误把"is"当成了输出目标,所以抛出格式不匹配的错误。另外输出路径里的空格(Billionare livestyle文件夹)也没处理,同样可能引发解析问题。

修复方案

修改FFmpeg命令的构造逻辑,处理引号嵌套和空格路径:

关键代码修正

把drawtext的text内容用单引号包裹,同时给所有带空格的文件路径加双引号:

command = f'ffmpeg -loop 1 -t {video_duration} -i "{background_picture}" -i "{music_file}" -vf "drawtext=fontfile={font}:text=\'{quote}\':fontcolor={font_color}:fontsize={font_size}:x={quote_position[0]}:y={quote_position[1]}" -shortest -c:v libx264 -c:a aac "{output_file}"'

完整修复后的代码

import os
import cv2

def calculate_quote_position(quote, max_length, video_width, video_height):
    if len(quote) > max_length:
        print("引用内容过长,无法适配视频。")
        return
    
    # 计算文本尺寸与位置
    font = cv2.FONT_HERSHEY_SIMPLEX
    font_scale = 1.0
    thickness = 2
    (text_width, text_height), _ = cv2.getTextSize(quote, font, font_scale, thickness)
    
    x = int((video_width - text_width) / 2)
    y = int((video_height + text_height) / 2)
    
    return (x, y, text_width, text_height)

def create_video_from_audio_quote_picture(music_file, quote, font, font_size, font_color, background_picture, output_file, video_duration, video_width, video_height, max_length):
    quote_position = calculate_quote_position(quote, max_length, video_width, video_height)
    if not quote_position:
        print("引用内容过长,无法适配视频。")
        return
    # 修正后的FFmpeg命令,处理空格和引号嵌套
    command = f'ffmpeg -loop 1 -t {video_duration} -i "{background_picture}" -i "{music_file}" -vf "drawtext=fontfile={font}:text=\'{quote}\':fontcolor={font_color}:fontsize={font_size}:x={quote_position[0]}:y={quote_position[1]}" -shortest -c:v libx264 -c:a aac "{output_file}"'

    os.system(command)

# 参数配置
music_file = "music.mp3"
quote = "This is a quote"
font = "Raleway-Bold.ttf"
font_size = 20
font_color = "white"
background_picture = "nature.png"
output_file = r"C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\output.mp4"
video_duration = 30
video_width = 1920
video_height = 1080
max_length = 30

create_video_from_audio_quote_picture(music_file, quote, font, font_size, font_color, background_picture, output_file, video_duration, video_width, video_height, max_length)

额外注意事项

  • 如果字体文件路径包含空格,需要给fontfile的值也加引号,比如fontfile='Raleway Bold.ttf'(注意滤镜内部的引号嵌套规则)。
  • 尽量避免在文件路径或文本内容里使用特殊字符,若必须使用,也要用引号完整包裹对应参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 16:55:14