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

ffmpeg-python视频分片拼接报错:TypeError类型不匹配求助

Hey, I’ve dealt with this exact ffmpeg-python quirk before—let’s break down what’s causing the error and how to fix it quickly.

What’s Going Wrong?

That TypeError spells out the core issue clearly: the ffmpeg.concat() function doesn’t accept a list of streams as input. It expects individual FilterableStream objects passed as separate arguments, not a single list containing those streams. When you pass your list directly, ffmpeg-python treats the entire list as one invalid input type instead of recognizing each stream inside the list as a separate source to concatenate.

The Fix

Use Python’s unpacking operator (*) to expand your stream list into individual arguments that ffmpeg.concat() understands. Here’s how to adjust your code:

Example Corrected Code

import ffmpeg

# Read the input video
input_vid = ffmpeg.input('test.mp4')

# Your 30-frame splitting logic (adjust as needed for your exact implementation)
stream_chunks = []
# First, get total frames to loop through
total_frames = int(ffmpeg.probe('test.mp4')['streams'][0]['nb_frames'])

for start in range(0, total_frames, 30):
    end = min(start + 30, total_frames)
    # Trim the chunk and reset timestamps (critical for smooth concatenation)
    chunk = input_vid.trim(start_frame=start, end_frame=end).setpts('PTS-STARTPTS')
    stream_chunks.append(chunk)

# ❌ Old (broken) way: passing the list directly
# ffmpeg.concat(stream_chunks).output('merged.mp4').run()

# ✅ New (fixed) way: unpack the list into individual arguments
ffmpeg.concat(*stream_chunks).output('merged.mp4').run()

A Quick Heads-Up

When using the concat filter, make sure all your stream chunks have matching properties (resolution, frame rate, codec, etc.). If they don’t, you’ll hit other errors—you can add a scale or fps filter to standardize chunks if needed.

内容的提问来源于stack exchange,提问作者李良全

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 19:02:29