视频超分:输出 720p 或 1080p
本页目录
接入预告 · 待上线。以下为计划兼容的请求格式。请在 UiUiAPI 为你的令牌开放对应模型、并标明支持本页接口后再调用;实际上线的模型名、限制和价格以平台为准。
将已有影片提升到目标分辨率。提交时提供源视频地址和输出型号。
准备源文件
使用有有效时长的 MP4 或 MOV,预期限制为不超过 128 MiB、时长不超过 3,600 秒。源文件应可直接下载;签名链接的有效期要覆盖排队和读取时间。
提交任务
先在终端设置环境变量 UIUI_API_KEY。以下示例使用主站的 JSON 接口。含 example.com 的素材地址需要换成服务器能读取的 HTTPS 文件地址。
curl -sS --fail-with-body 'https://api.uiuihao.com/v1/videos' \
-H "Authorization: Bearer $UIUI_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary '{
"model": "火山-超分-1080p",
"videos": [
"https://example.com/source.mp4"
],
"resolution": "1080p",
"fps": 30
}'
设置输出
videos 数组只放一个源文件。720p 选 火山-超分-720p,1080p 选 火山-超分-1080p;显式设定 resolution 时需与型号匹配。fps 的参考档位为 30、60、120、240。提交前可能读取文件以核实时长,可预留至少 180 秒请求超时。
费用与轮询
超分通常按处理时长计量。上线后请用 UiUiAPI 所选分组的单价估算费用。长视频可以每 10 秒查一次;获取任务 ID 后即可退出提交步骤。
查询进度与保存视频
从提交响应读取 id 或 task_id。在终端设置 TASK_ID 为返回的原值,再查询状态。
curl -sS --fail-with-body "https://api.uiuihao.com/v1/videos/$TASK_ID" \
-H "Authorization: Bearer $UIUI_API_KEY"
排队或生成中时隔几秒再查询;收到 429 时按 Retry-After 延长间隔。遇到 failed / FAILURE 时停止轮询并查看错误。成功状态如 completed / SUCCESS 出现后,可用同一任务 ID 保存成片。
curl -fSL "https://api.uiuihao.com/v1/videos/$TASK_ID/content" \
-H "Authorization: Bearer $UIUI_API_KEY" -o output.mp4
若返回临时成片链接,及时保存。向外部存储下载时无需附带 UiUiAPI 密钥。超时先查任务记录,避免重复生成。
Python:提交一次并分块保存
设置 SOURCE_VIDEO_URL 为源视频直链。此示例需要 requests,会等待最多 180 轮。
import os, pathlib, time
import requests
host = "https://api.uiuihao.com/v1/videos"
headers = {"Authorization": "Bearer " + os.environ["UIUI_API_KEY"]}
job = requests.post(host, headers=headers, timeout=180, json={
"model": "火山-超分-1080p", "videos": [os.environ["SOURCE_VIDEO_URL"]], "fps": 30
})
job.raise_for_status()
created = job.json()
task_id = created.get("id") or created["task_id"]
print("任务 ID:", task_id, flush=True)
for _ in range(180):
time.sleep(10)
response = requests.get(f"{host}/{task_id}", headers=headers, timeout=30)
if response.status_code == 429:
time.sleep(20)
continue
response.raise_for_status()
result = response.json()
state = str(result.get("status", "")).lower()
if state in {"failed", "failure", "error", "cancelled", "canceled"}:
raise RuntimeError(result.get("fail_reason") or state)
if state in {"success", "succeeded", "completed"}:
with requests.get(f"{host}/{task_id}/content", headers=headers, stream=True, timeout=180) as data:
data.raise_for_status()
with pathlib.Path("upscaled.mp4").open("wb") as output:
for chunk in data.iter_content(1024 * 1024):
if chunk:
output.write(chunk)
break
else:
print("等待超时,保存任务 ID 并稍后继续查询。")