現時点では、この状況は 2 つのレイヤーに分けて考えられます:モデル自体が動画に対応しているか、そして Dify のフロントエンド / API が動画ファイル形式を受け付けるかどうかです。
まず、ファイルアップロードが可能かどうかは、features の設定で files 配下にある video のファイルタイプが有効になっているかを確認する必要があります。
次に、GLM については、公式マニュアル によれば、サンプルコードは以下の通りです:
# Video understanding example, upload video URL
from zhipuai import ZhipuAI
client = ZhipuAI(api_key="YOUR API KEY") # Fill in your own API key
response = client.chat.completions.create(
model="glm-4v-plus-0111", # Fill in the model name to call
messages=[
{
"role": "user",
"content": [
{
"type": "video_url",
"video_url": {
"url" : "https://sfile.chatglm.cn/testpath/video/xxxxx.mp4"
}
},
{
"type": "text",
"text": "Please describe this video in detail."
}
]
}
]
)
print(response.choices[0].message)
このことから、GLM 系のモデルでは、ユーザーは正しい動画 URL を渡すだけで動画解析を行えることが分かります。
また、Qwen 系のモデルを使う場合、公式の Qwen API ドキュメントによれば、以下の説明があります:
Qwen-VL は、動画からフレーム列を抽出して内容を解析します。抽出頻度は解析の精細度を左右します。SDK によって抽出頻度のデフォルトが異なり、モデルは
fpsパラメータで抽出頻度を制御できます(1/fps秒ごとに 1 フレームを抽出、範囲は[0.1, 10]、デフォルトは2.0)。高速な動きがあるシーンでは高めのfps、静的なシーンや長尺動画では低めのfpsを推奨します。
import dashscope
import os
# The following is the Singapore region base_url. If using the Virginia region model,
# change base_url to https://dashscope-us.aliyuncs.com/api/v1
# If using the Beijing region model, change base_url to: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
messages = [
{"role": "user",
"content": [
# fps can control the video frame extraction frequency, meaning one frame is extracted every 1/fps seconds.
# Full usage: https://www.alibabacloud.com/help/en/model-studio/use-qwen-by-calling-api?#2ed5ee7377fum
{"video": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241115/cqqkru/1.mp4","fps":2},
{"text": "What is this video about?"}
]
}
]
response = dashscope.MultiModalConversation.call(
# API keys differ by region. Get an API key:
# https://www.alibabacloud.com/help/en/model-studio/get-api-key
# If you don't have environment variables configured, replace the next line with: api_key="sk-xxx"
api_key=os.getenv('DASHSCOPE_API_KEY'),
model='qwen3-vl-plus',
messages=messages
)
print(response.output.choices[0].message.content[0]["text"])
Alibaba の公式マニュアルに基づく別の書き方もあります:
import os
# dashscope version must be >= 1.20.10
import dashscope
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
messages = [{"role": "user",
"content": [
# If the model belongs to the Qwen2.5-VL series and an image list is provided,
# you can set fps to indicate that the image list was extracted from the original video every 1/fps seconds.
{"video": ["https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"],
"fps": 2},
{"text": "Describe the detailed process shown in this video."}]}]
response = dashscope.MultiModalConversation.call(
# If you don't have environment variables configured, replace the next line with: api_key="sk-xxx"
# API keys differ for Singapore/Virginia and Beijing regions. Get an API key:
# https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
model='qwen2.5-vl-72b-instruct', # Example model; replace as needed. Model list:
# https://www.alibabacloud.com/help/en/model-studio/models
messages=messages
)
print(response["output"]["choices"][0]["message"].content[0]["text"])
スクリーンショットから分かるポイントは、ユーザーが GLM 系か Qwen 系かを使っているかではなく、ユーザーが SiliconFlow plugin を使っている点です。SiliconFlow の公式ドキュメントによると、同社の視覚入力の扱いは次のようになっています:
2. Usage
VLM モデルの場合、
/chat/completionsエンドポイントを呼び出し、画像 URL もしくは base64 エンコードした画像を含む message を構成して実行できます。detailパラメータを用いて画像の前処理モードを制御します。2.1 Detail parameter
SiliconFlow は
detailにlow/high/autoの 3 つの選択肢を提供しています。現在サポートされているモデルでは、detailを指定しない、またはhighを指定した場合は high(高解像度) モードが使われ、lowまたはautoを指定した場合は low(低解像度) モードが使われます。
4. Billing for visual inputs
画像などの視覚入力は tokens に変換され、テキストと同様にコンテキストとして一緒に課金対象になります。モデルごとに視覚コンテンツの変換方法が異なり、以下は現時点の変換ルールです。
4.1 Qwen series
ルール:
Qwen がサポートする最大ピクセルは 3584 × 3584 = 12,845,056、最小ピクセルは 56 × 56 = 3,136 です。各画像はまず長辺・短辺ともに 28 の倍数となるようにリサイズされ、すなわち (h * 28) × (w * 28) となります。最小〜最大ピクセルの範囲外であれば、さらにその範囲に収まるよう等比で縮放されます。
detail=lowの場合、すべての画像が 448 × 448 にリサイズされ、最終的に 256 tokens に対応します。detail=highの場合、等比で縮放されます。まず縦横を最も近い 28 の倍数へ切り上げ、その後ピクセル範囲 (3136, 12845056) に収まるよう等比で調整し、かつ縦横が 28 の倍数になるよう保証します。例:
- 画像サイズが 224 × 448、1024 × 1024、3172 × 4096 の場合、
detail=lowを選ぶといずれも 256 tokens を消費します。- 224 × 448 を
detail=highにすると:ピクセル範囲内で、かつ縦横が 28 の倍数なので、消費は (224/28) × (448/28) = 8 × 16 = 128 tokens です。- 1024 × 1024 を
detail=highにすると:28 の倍数へ切り上げて 1036 × 1036 とし(※原文に従う)、範囲内なので (1036/28) × (1036/28) = 1369 tokens を消費します。- 3172 × 4096 を
detail=highにすると:切り上げて 3192 × 4116 となり、最大ピクセルを超えるため、等比で 3136 × 4060 に縮小され、(3136/28) × (4060/28) = 16240 tokens を消費します。公式 API ドキュメントに動画の取り扱いが記載されていないことから、ボトルネックは Dify ではなく、SiliconFlow 自体が動画処理に対応していない点にあります。これにより、ユーザーが「手動で抽フレ(フレーム抽出)をした」と述べている点とも整合します。
解決策
- SiliconFlow が公式に動画 / ストリーム入力へ対応するのを待ち、Dify のメンテナ(および SiliconFlow Plugin の作者)に対してプラグイン更新を促す。
- あるいは、Dify の Tongyi plugin に切り替え、Alibaba Cloud Bailian(Model Studio)の API Key を使用する。
