1.接口说明
视频变高清 API:上传视频文件或提供视频URL,异步对视频进行超分辨率增强,返回处理后的结果视频URL。
1.1主要功能
- 视频超分增强:
- 自动对低清视频进行细节增强与清晰化处理,提升画面质量。
- 指定输出尺寸:
- 通过 size 参数指定处理后视频的短边长度(像素)。
- 多输入方式:
- 支持上传视频文件(file)或提供视频URL(file_url)。
1.2接入场景
适用于老视频修复、低清素材增强、视频平台内容优化等需要对视频进行清晰化处理的场景。
2.请求信息
2.1请求地址(URL)
POST http(s)://api.shiliuai.com/api/video_super_resolution/v1
2.2请求方式
POST
2.3请求头(header)
| 参数 | 类型 | 说明 |
|---|---|---|
| APIKEY | string | 您的 API KEY 获取 |
2.4请求体(body)
编码方式:multipart/form-data
| 参数 | 是否必填 | 类型 | 说明 |
|---|---|---|---|
| 异步提交任务 | |||
| file | 二选一必填 | file | 视频文件,通过 files 参数上传,与 file_url 二选一,优先使用 file |
| file_url | string | 视频文件URL,与 file 二选一,优先使用 file | |
| size | 是 | int | 处理后视频短边长度(像素) |
| 异步获取结果 | |||
| file_id | 是 | string | 提交任务返回的 file_id |
3.返回信息
3.1返回类型
JSON
3.2返回信息
| 参数 | 返回类型 | 说明 |
|---|---|---|
| code | int | 错误码 |
| msg | string | 错误信息(英文) |
| msg_cn | string | 错误信息(中文) |
| request_id | string | 请求id |
| file_id | string | 视频id,可用于异步获取结果 |
| 异步模式通用 | ||
| status | string | 任务状态,added:已加入,processing:正在处理,done:处理完成,error:错误 |
| wait_time | float | 大概还需等待时间,例如:1.2(秒) |
| result_url | string | 结果视频URL,当 status 为 done 时,有该返回值,可以用该URL获取结果 |
| video_duration | float | 视频时长(秒),提交任务时有该返回值(私用) |
3.3返回示例
// 提交任务成功
{
"code": 0,
"msg": "OK",
"msg_cn": "成功",
"request_id": "a1b2c3d4e5f6...",
"file_id": "f7e8d9c0b1a2...",
"status": "added",
"wait_time": 1.2,
"video_duration": 15.5
}
// 轮询 - 处理完成
{
"code": 0,
"msg": "OK",
"msg_cn": "成功",
"request_id": "a1b2c3d4e5f6...",
"file_id": "f7e8d9c0b1a2...",
"status": "done",
"result_url": "https://cdn.shiliuai.com/result/xxx.mp4"
}
// 失败示例
{
"code": 4,
"msg": "Invalid parameter: file or file_url is required",
"msg_cn": "参数错误:file 或 file_url 必填其中之一"
}
3.4错误码
| 错误码 | 说明 |
|---|---|
| 0 | 成功 |
| 1 | 文件错误 |
| 2 | 处理错误 |
| 3 | 服务器繁忙 |
| 4 | 参数错误(具体错误看 msg 或 msg_cn) |
| 5 | 未知错误 |
| 101 | API-KEY 不正确 |
| 102 | 未知用户 |
| 103 | 积分已用完 |
| 104 | 扣除积分失败 |
4.示例代码
4.1 Python
# -*- coding: utf-8 -*-
import time
import requests
import json
import os
api_key = '******' # 你的API KEY
file_path = '...' # 视频路径
url = 'http(s)://api.shiliuai.com/api/video_super_resolution/v1'
headers = {'APIKEY': api_key}
data = {
"size": 1080 # 处理后视频短边长度(像素)
}
# 提交任务
with open(file_path, "rb") as file:
response = requests.post(url=url, headers=headers, files={"file": file}, data=data)
response = json.loads(response.content)
code = response.get('code')
if code == 0:
file_id = response.get('file_id')
# 轮询等待结果,处理完成后下载(同步等待)
while True:
wait_time = response.get('wait_time') or 1
time.sleep(wait_time)
response = requests.post(url=url, headers=headers, data={"file_id": file_id})
response = json.loads(response.content)
status = response.get('status')
if status == 'done':
result_url = response.get('result_url')
video = requests.get(url=result_url)
if video.status_code == 200:
filename = os.path.basename(result_url)
with open(filename, "wb") as f:
f.write(video.content)
print('视频变高清成功,已保存', filename)
else:
print('下载失败:', video.status_code)
break
else:
print('请求失败:', response.get('msg_cn', response.get('msg')))
# -*- coding: utf-8 -*-
import time
import requests
import json
import os
api_key = '******' # 你的API KEY
file_path = '...' # 视频路径
url = 'http(s)://api.shiliuai.com/api/video_super_resolution/v1'
headers = {'APIKEY': api_key}
data = {
"size": 1080 # 处理后视频短边长度(像素)
}
# 第1步:提交任务,拿到 file_id 与 wait_time 后即可返回(任务在服务端处理)
with open(file_path, "rb") as file:
response = requests.post(url=url, headers=headers, files={"file": file}, data=data)
response = json.loads(response.content)
file_id = response.get('file_id')
wait_time = response.get('wait_time') or 1
print('任务已提交 file_id:', file_id)
# 第2步:查询任务结果(可放入自己的定时任务/队列,按 wait_time 间隔轮询)
time.sleep(wait_time)
response = requests.post(url=url, headers=headers, data={"file_id": file_id})
response = json.loads(response.content)
status = response.get('status')
if status == 'done':
result_url = response.get('result_url')
video = requests.get(url=result_url)
if video.status_code == 200:
filename = os.path.basename(result_url)
with open(filename, "wb") as f:
f.write(video.content)
print('视频变高清成功,已保存', filename)
else:
print('处理中:', status)
4.2 PHP
<?php
$url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1";
$apikey = "******";
$header = array();
array_push($header, "APIKEY:" . $apikey);
$file_path = "...";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
// 提交任务
$post_data = array(
"file" => new CURLFile($file_path),
"size" => 1080
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($curl);
$response = json_decode($response, true);
if ($response['code'] == 0) {
$file_id = $response['file_id'];
// 轮询等待结果,处理完成后下载(同步等待)
while (true) {
$wait_time = isset($response['wait_time']) ? $response['wait_time'] : 1;
sleep((int)$wait_time);
$poll_data = array("file_id" => $file_id);
curl_setopt($curl, CURLOPT_POSTFIELDS, $poll_data);
$response = curl_exec($curl);
$response = json_decode($response, true);
if (isset($response['status']) && $response['status'] === 'done') {
$result_url = $response['result_url'];
$video_content = file_get_contents($result_url);
$filename = basename($result_url);
file_put_contents($filename, $video_content);
echo "视频变高清成功,已保存 " . $filename;
break;
}
}
}
var_dump($response);
<?php
$url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1";
$apikey = "******";
$header = array();
array_push($header, "APIKEY:" . $apikey);
$file_path = "...";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
// 第1步:提交任务,拿到 file_id 与 wait_time 后即可返回(任务在服务端处理)
$post_data = array(
"file" => new CURLFile($file_path),
"size" => 1080
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($curl);
$response = json_decode($response, true);
$file_id = $response['file_id'];
$wait_time = isset($response['wait_time']) ? $response['wait_time'] : 1;
echo "任务已提交 file_id:" . $file_id;
// 第2步:查询任务结果(可放入自己的定时任务,按 wait_time 间隔轮询)
sleep((int)$wait_time);
$poll_data = array("file_id" => $file_id);
curl_setopt($curl, CURLOPT_POSTFIELDS, $poll_data);
$response = curl_exec($curl);
$response = json_decode($response, true);
if (isset($response['status']) && $response['status'] === 'done') {
$result_url = $response['result_url'];
$video_content = file_get_contents($result_url);
$filename = basename($result_url);
file_put_contents($filename, $video_content);
echo "视频变高清成功,已保存 " . $filename;
}
var_dump($response);
4.3 Java
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import org.json.JSONObject;
public class VideoSuperResolutionApiExample {
public static void main(String[] args) {
String apiKey = "******";
String filePath = "...";
String apiUrl = "http(s)://api.shiliuai.com/api/video_super_resolution/v1";
try {
// 提交任务(multipart/form-data)
JSONObject response = submitTask(apiUrl, apiKey, filePath);
if (response.getInt("code") != 0) {
System.out.println("请求失败: " + response.optString("msg_cn", response.optString("msg")));
return;
}
String fileId = response.getString("file_id");
// 轮询等待结果,处理完成后下载(同步等待)
while (true) {
double waitTime = response.optDouble("wait_time", 1.0);
Thread.sleep((long) (waitTime * 1000));
response = fetchResult(apiUrl, apiKey, fileId);
if ("done".equals(response.optString("status"))) {
downloadResult(response.getString("result_url"));
System.out.println("视频变高清成功");
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
// 提交任务:multipart/form-data 上传视频文件
private static JSONObject submitTask(String apiUrl, String apiKey, String filePath) throws Exception {
String boundary = "----FormBoundary" + System.currentTimeMillis();
HttpURLConnection conn = openMultipartPost(apiUrl, apiKey, boundary);
try (OutputStream os = conn.getOutputStream()) {
os.write(("--" + boundary + "\r\n").getBytes());
os.write(("Content-Disposition: form-data; name=\"file\"; filename=\""
+ new File(filePath).getName() + "\"\r\n").getBytes());
os.write(("Content-Type: application/octet-stream\r\n\r\n").getBytes());
Files.copy(new File(filePath).toPath(), os);
os.write(("\r\n").getBytes());
os.write(("--" + boundary + "\r\n").getBytes());
os.write(("Content-Disposition: form-data; name=\"size\"\r\n\r\n").getBytes());
os.write(("1080\r\n").getBytes());
os.write(("--" + boundary + "--\r\n").getBytes());
}
return readJson(conn);
}
// 查询任务结果
private static JSONObject fetchResult(String apiUrl, String apiKey, String fileId) throws Exception {
String boundary = "----FormBoundary" + System.currentTimeMillis();
HttpURLConnection conn = openMultipartPost(apiUrl, apiKey, boundary);
try (OutputStream os = conn.getOutputStream()) {
os.write(("--" + boundary + "\r\n").getBytes());
os.write(("Content-Disposition: form-data; name=\"file_id\"\r\n\r\n").getBytes());
os.write((fileId + "\r\n").getBytes());
os.write(("--" + boundary + "--\r\n").getBytes());
}
return readJson(conn);
}
private static HttpURLConnection openMultipartPost(String apiUrl, String apiKey, String boundary)
throws Exception {
HttpURLConnection conn = (HttpURLConnection) new URL(apiUrl).openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("APIKEY", apiKey);
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
conn.setDoOutput(true);
return conn;
}
private static JSONObject readJson(HttpURLConnection conn) throws Exception {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "utf-8"))) {
String line;
while ((line = br.readLine()) != null) sb.append(line.trim());
}
return new JSONObject(sb.toString());
}
// 下载结果视频
private static void downloadResult(String resultUrl) throws Exception {
try (InputStream is = new URL(resultUrl).openStream();
FileOutputStream fos = new FileOutputStream(
new File(new URL(resultUrl).getPath()).getName())) {
byte[] buffer = new byte[4096];
int read;
while ((read = is.read(buffer)) != -1) {
fos.write(buffer, 0, read);
}
}
}
}
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import org.json.JSONObject;
public class VideoSuperResolutionApiExampleAsync {
public static void main(String[] args) {
String apiKey = "******";
String filePath = "...";
String apiUrl = "http(s)://api.shiliuai.com/api/video_super_resolution/v1";
try {
// 第1步:提交任务,拿到 file_id 后即可返回(任务在服务端处理)
JSONObject response = submitTask(apiUrl, apiKey, filePath);
String fileId = response.getString("file_id");
double waitTime = response.optDouble("wait_time", 1.0);
System.out.println("任务已提交 file_id: " + fileId);
// 第2步:查询任务结果(可放入自己的定时任务,按 wait_time 间隔轮询)
Thread.sleep((long) (waitTime * 1000));
response = fetchResult(apiUrl, apiKey, fileId);
if ("done".equals(response.optString("status"))) {
downloadResult(response.getString("result_url"));
System.out.println("视频变高清成功");
}
} catch (Exception e) {
e.printStackTrace();
}
}
// 提交任务:multipart/form-data 上传视频文件
private static JSONObject submitTask(String apiUrl, String apiKey, String filePath) throws Exception {
String boundary = "----FormBoundary" + System.currentTimeMillis();
HttpURLConnection conn = openMultipartPost(apiUrl, apiKey, boundary);
try (OutputStream os = conn.getOutputStream()) {
os.write(("--" + boundary + "\r\n").getBytes());
os.write(("Content-Disposition: form-data; name=\"file\"; filename=\""
+ new File(filePath).getName() + "\"\r\n").getBytes());
os.write(("Content-Type: application/octet-stream\r\n\r\n").getBytes());
Files.copy(new File(filePath).toPath(), os);
os.write(("\r\n").getBytes());
os.write(("--" + boundary + "\r\n").getBytes());
os.write(("Content-Disposition: form-data; name=\"size\"\r\n\r\n").getBytes());
os.write(("1080\r\n").getBytes());
os.write(("--" + boundary + "--\r\n").getBytes());
}
return readJson(conn);
}
// 查询任务结果
private static JSONObject fetchResult(String apiUrl, String apiKey, String fileId) throws Exception {
String boundary = "----FormBoundary" + System.currentTimeMillis();
HttpURLConnection conn = openMultipartPost(apiUrl, apiKey, boundary);
try (OutputStream os = conn.getOutputStream()) {
os.write(("--" + boundary + "\r\n").getBytes());
os.write(("Content-Disposition: form-data; name=\"file_id\"\r\n\r\n").getBytes());
os.write((fileId + "\r\n").getBytes());
os.write(("--" + boundary + "--\r\n").getBytes());
}
return readJson(conn);
}
private static HttpURLConnection openMultipartPost(String apiUrl, String apiKey, String boundary)
throws Exception {
HttpURLConnection conn = (HttpURLConnection) new URL(apiUrl).openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("APIKEY", apiKey);
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
conn.setDoOutput(true);
return conn;
}
private static JSONObject readJson(HttpURLConnection conn) throws Exception {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "utf-8"))) {
String line;
while ((line = br.readLine()) != null) sb.append(line.trim());
}
return new JSONObject(sb.toString());
}
// 下载结果视频
private static void downloadResult(String resultUrl) throws Exception {
try (InputStream is = new URL(resultUrl).openStream();
FileOutputStream fos = new FileOutputStream(
new File(new URL(resultUrl).getPath()).getName())) {
byte[] buffer = new byte[4096];
int read;
while ((read = is.read(buffer)) != -1) {
fos.write(buffer, 0, read);
}
}
}
}
4.4 JavaScript
const fs = require('fs');
const path = require('path');
const apiKey = '******';
const filePath = '...';
const apiUrl = 'http(s)://api.shiliuai.com/api/video_super_resolution/v1';
function sleep(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
async function main() {
// 提交任务(multipart/form-data)
const fileContent = fs.readFileSync(filePath);
const boundary = '----FormBoundary' + Date.now();
const body = [
`--${boundary}`,
'Content-Disposition: form-data; name="file"; filename="' + path.basename(filePath) + '"',
'Content-Type: application/octet-stream',
'',
fileContent,
`--${boundary}`,
'Content-Disposition: form-data; name="size"',
'',
'1080',
`--${boundary}--`,
].map(p => typeof p === 'string' ? Buffer.from(p + '\r\n', 'utf-8') : p);
let res = await fetch(apiUrl, {
method: 'POST',
headers: { APIKEY: apiKey, 'Content-Type': `multipart/form-data; boundary=${boundary}` },
body: Buffer.concat(body)
});
let data = await res.json();
if (data.code !== 0) {
console.error('请求失败:', data.msg_cn || data.msg);
return;
}
const fileId = data.file_id;
// 轮询等待结果,处理完成后下载(同步等待)
while (true) {
await sleep(data.wait_time || 1);
const pollBoundary = '----FormBoundary' + Date.now();
const pollBody = [
`--${pollBoundary}`,
'Content-Disposition: form-data; name="file_id"',
'',
fileId,
`--${pollBoundary}--`,
].map(p => typeof p === 'string' ? Buffer.from(p + '\r\n', 'utf-8') : p);
res = await fetch(apiUrl, {
method: 'POST',
headers: { APIKEY: apiKey, 'Content-Type': `multipart/form-data; boundary=${pollBoundary}` },
body: Buffer.concat(pollBody)
});
data = await res.json();
if (data.status === 'done') {
// 下载结果视频
const resultUrl = data.result_url;
const dlRes = await fetch(resultUrl);
if (dlRes.ok) {
const buffer = Buffer.from(await dlRes.arrayBuffer());
const filename = path.basename(resultUrl);
fs.writeFileSync(filename, buffer);
console.log('视频变高清成功,已保存', filename);
}
break;
}
}
}
main().catch(console.error);
const fs = require('fs');
const path = require('path');
const apiKey = '******';
const filePath = '...';
const apiUrl = 'http(s)://api.shiliuai.com/api/video_super_resolution/v1';
function sleep(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
async function main() {
// 第1步:提交任务,拿到 file_id 与 wait_time 后即可返回(任务在服务端处理)
const fileContent = fs.readFileSync(filePath);
const boundary = '----FormBoundary' + Date.now();
const body = [
`--${boundary}`,
'Content-Disposition: form-data; name="file"; filename="' + path.basename(filePath) + '"',
'Content-Type: application/octet-stream',
'',
fileContent,
`--${boundary}`,
'Content-Disposition: form-data; name="size"',
'',
'1080',
`--${boundary}--`,
].map(p => typeof p === 'string' ? Buffer.from(p + '\r\n', 'utf-8') : p);
let res = await fetch(apiUrl, {
method: 'POST',
headers: { APIKEY: apiKey, 'Content-Type': `multipart/form-data; boundary=${boundary}` },
body: Buffer.concat(body)
});
let data = await res.json();
const fileId = data.file_id;
console.log('任务已提交 file_id:', fileId);
// 第2步:查询任务结果(可放入自己的定时任务,按 wait_time 间隔轮询)
await sleep(data.wait_time || 1);
const pollBoundary = '----FormBoundary' + Date.now();
const pollBody = [
`--${pollBoundary}`,
'Content-Disposition: form-data; name="file_id"',
'',
fileId,
`--${pollBoundary}--`,
].map(p => typeof p === 'string' ? Buffer.from(p + '\r\n', 'utf-8') : p);
res = await fetch(apiUrl, {
method: 'POST',
headers: { APIKEY: apiKey, 'Content-Type': `multipart/form-data; boundary=${pollBoundary}` },
body: Buffer.concat(pollBody)
});
data = await res.json();
if (data.status === 'done') {
// 下载结果视频
const resultUrl = data.result_url;
const dlRes = await fetch(resultUrl);
if (dlRes.ok) {
const buffer = Buffer.from(await dlRes.arrayBuffer());
const filename = path.basename(resultUrl);
fs.writeFileSync(filename, buffer);
console.log('视频变高清成功,已保存', filename);
}
}
}
main().catch(console.error);
4.5 NodeJs
const fs = require('fs');
const path = require('path');
const FormData = require('form-data');
const apiKey = '******';
const filePath = '...';
const apiUrl = 'http(s)://api.shiliuai.com/api/video_super_resolution/v1';
function sleep(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
async function main() {
// 提交任务
let form = new FormData();
form.append('file', fs.createReadStream(filePath));
form.append('size', '1080');
let res = await fetch(apiUrl, {
method: 'POST',
headers: { APIKEY: apiKey, ...form.getHeaders() },
body: form
});
let data = await res.json();
if (data.code !== 0) {
console.error('请求失败:', data.msg_cn || data.msg);
return;
}
const fileId = data.file_id;
// 轮询等待结果,处理完成后下载(同步等待)
while (true) {
await sleep(data.wait_time || 1);
form = new FormData();
form.append('file_id', fileId);
res = await fetch(apiUrl, {
method: 'POST',
headers: { APIKEY: apiKey, ...form.getHeaders() },
body: form
});
data = await res.json();
if (data.status === 'done') {
// 下载结果视频
const resultUrl = data.result_url;
const dlRes = await fetch(resultUrl);
if (dlRes.ok) {
const buffer = Buffer.from(await dlRes.arrayBuffer());
const filename = path.basename(resultUrl);
fs.writeFileSync(filename, buffer);
console.log('视频变高清成功,已保存', filename);
}
break;
}
}
}
main().catch(console.error);
const fs = require('fs');
const path = require('path');
const FormData = require('form-data');
const apiKey = '******';
const filePath = '...';
const apiUrl = 'http(s)://api.shiliuai.com/api/video_super_resolution/v1';
function sleep(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
async function main() {
// 第1步:提交任务,拿到 file_id 与 wait_time 后即可返回(任务在服务端处理)
let form = new FormData();
form.append('file', fs.createReadStream(filePath));
form.append('size', '1080');
let res = await fetch(apiUrl, {
method: 'POST',
headers: { APIKEY: apiKey, ...form.getHeaders() },
body: form
});
let data = await res.json();
const fileId = data.file_id;
console.log('任务已提交 file_id:', fileId);
// 第2步:查询任务结果(可放入自己的定时任务,按 wait_time 间隔轮询)
await sleep(data.wait_time || 1);
form = new FormData();
form.append('file_id', fileId);
res = await fetch(apiUrl, {
method: 'POST',
headers: { APIKEY: apiKey, ...form.getHeaders() },
body: form
});
data = await res.json();
if (data.status === 'done') {
// 下载结果视频
const resultUrl = data.result_url;
const dlRes = await fetch(resultUrl);
if (dlRes.ok) {
const buffer = Buffer.from(await dlRes.arrayBuffer());
const filename = path.basename(resultUrl);
fs.writeFileSync(filename, buffer);
console.log('视频变高清成功,已保存', filename);
}
}
}
main().catch(console.error);
4.6 cURL
# 同步:提交任务后在本地轮询等待,直到处理完成再下载结果 # 1. 提交任务(返回 file_id 与 wait_time) curl -k 'http(s)://api.shiliuai.com/api/video_super_resolution/v1' \ -H 'APIKEY: 你的APIKEY' \ -F 'file=@/path/to/video.mp4' \ -F 'size=1080' # 2. 轮询结果:将 file_id 替换为上一步返回值,按 wait_time 间隔重复请求,直到 status 为 done curl -k 'http(s)://api.shiliuai.com/api/video_super_resolution/v1' \ -H 'APIKEY: 你的APIKEY' \ -F 'file_id=上一步返回的file_id' # 3. 下载结果视频(status 为 done 时,使用返回的 result_url) curl -k -O 'https://cdn.shiliuai.com/result/xxx.mp4'
# 异步:提交与获取结果分两步处理 # 1. 提交任务(仅提交,不等待处理完成,返回 file_id 后即可返回) curl -k 'http(s)://api.shiliuai.com/api/video_super_resolution/v1' \ -H 'APIKEY: 你的APIKEY' \ -F 'file=@/path/to/video.mp4' \ -F 'size=1080' # 2. 获取结果(在需要时查询,status 为 done 时返回 result_url) curl -k 'http(s)://api.shiliuai.com/api/video_super_resolution/v1' \ -H 'APIKEY: 你的APIKEY' \ -F 'file_id=上一步返回的file_id' # 3. 下载结果视频(status 为 done 时,使用返回的 result_url) curl -k -O 'https://cdn.shiliuai.com/result/xxx.mp4'
4.7 C#
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string apiKey = "******";
string filePath = "...";
string apiUrl = "http(s)://api.shiliuai.com/api/video_super_resolution/v1";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("APIKEY", apiKey);
// 提交任务(multipart/form-data)
string fileId;
double waitTime;
using (var content = new MultipartFormDataContent())
{
var fileBytes = await File.ReadAllBytesAsync(filePath);
var fileContent = new ByteArrayContent(fileBytes);
content.Add(fileContent, "file", Path.GetFileName(filePath));
content.Add(new StringContent("1080"), "size");
var response = await client.PostAsync(apiUrl, content);
var responseObject = JsonSerializer.Deserialize<JsonElement>(
await response.Content.ReadAsStringAsync());
if (responseObject.GetProperty("code").GetInt32() != 0)
{
Console.WriteLine("请求失败: " + responseObject.GetProperty("msg_cn").GetString());
return;
}
fileId = responseObject.GetProperty("file_id").GetString();
waitTime = responseObject.TryGetProperty("wait_time", out var wt) ? wt.GetDouble() : 1.0;
}
// 轮询等待结果,处理完成后下载(同步等待)
while (true)
{
await Task.Delay((int)(waitTime * 1000));
var pollContent = new MultipartFormDataContent();
pollContent.Add(new StringContent(fileId), "file_id");
var response = await client.PostAsync(apiUrl, pollContent);
var responseObject = JsonSerializer.Deserialize<JsonElement>(
await response.Content.ReadAsStringAsync());
if (responseObject.GetProperty("status").GetString() == "done")
{
string resultUrl = responseObject.GetProperty("result_url").GetString();
var videoBytes = await client.GetByteArrayAsync(resultUrl);
string filename = Path.GetFileName(new Uri(resultUrl).LocalPath);
await File.WriteAllBytesAsync(filename, videoBytes);
Console.WriteLine("视频变高清成功,已保存 " + filename);
break;
}
waitTime = responseObject.TryGetProperty("wait_time", out var wt2) ? wt2.GetDouble() : 1.0;
}
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string apiKey = "******";
string filePath = "...";
string apiUrl = "http(s)://api.shiliuai.com/api/video_super_resolution/v1";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("APIKEY", apiKey);
// 第1步:提交任务,拿到 file_id 与 wait_time 后即可返回(任务在服务端处理)
string fileId;
double waitTime;
using (var content = new MultipartFormDataContent())
{
var fileBytes = await File.ReadAllBytesAsync(filePath);
var fileContent = new ByteArrayContent(fileBytes);
content.Add(fileContent, "file", Path.GetFileName(filePath));
content.Add(new StringContent("1080"), "size");
var response = await client.PostAsync(apiUrl, content);
var responseObject = JsonSerializer.Deserialize<JsonElement>(
await response.Content.ReadAsStringAsync());
fileId = responseObject.GetProperty("file_id").GetString();
waitTime = responseObject.TryGetProperty("wait_time", out var wt) ? wt.GetDouble() : 1.0;
}
Console.WriteLine("任务已提交 file_id: " + fileId);
// 第2步:查询任务结果(可放入自己的定时任务,按 wait_time 间隔轮询)
await Task.Delay((int)(waitTime * 1000));
var pollContent = new MultipartFormDataContent();
pollContent.Add(new StringContent(fileId), "file_id");
var pollResponse = await client.PostAsync(apiUrl, pollContent);
var pollObject = JsonSerializer.Deserialize<JsonElement>(
await pollResponse.Content.ReadAsStringAsync());
if (pollObject.GetProperty("status").GetString() == "done")
{
string resultUrl = pollObject.GetProperty("result_url").GetString();
var videoBytes = await client.GetByteArrayAsync(resultUrl);
string filename = Path.GetFileName(new Uri(resultUrl).LocalPath);
await File.WriteAllBytesAsync(filename, videoBytes);
Console.WriteLine("视频变高清成功,已保存 " + filename);
}
}
}
}
4.8 易语言
版本 2
.支持库 spec
.支持库 dp1
.子方法 视频变高清_API_示例
.局部变量 局_网址, 文本型
.局部变量 局_提交协议头, 文本型
.局部变量 局_结果, 字节集
.局部变量 局_返回, 文本型
.局部变量 视频数据, 字节集
.局部变量 file_id, 文本型
.局部变量 wait_time, 小数型
视频数据 = 读入文件 ("你的视频路径.mp4")
局_网址 = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
局_提交协议头 = "APIKEY: 你的APIKEY"
' 提交任务
局_结果 = 网页_访问_对象 (局_网址, 1, , 视频数据, , 局_提交协议头, , , , , , , , , , , , , )
局_返回 = 到文本 (编码_编码转换对象 (局_结果, , , ))
' 轮询等待结果(同步等待),status 为 done 时下载 result_url
.判断循环 (真)
程序_延时 (wait_time × 1000, )
局_结果 = 网页_访问_对象 (局_网址, 1, "file_id=" + file_id, , , 局_提交协议头, , , , , , , , , , , , , )
局_返回 = 到文本 (编码_编码转换对象 (局_结果, , , ))
.判断循环结束 ()
返回 (局_返回)
版本 2
.支持库 spec
.支持库 dp1
.子方法 视频变高清_API_示例_异步
.局部变量 局_网址, 文本型
.局部变量 局_提交协议头, 文本型
.局部变量 局_结果, 字节集
.局部变量 局_返回, 文本型
.局部变量 视频数据, 字节集
.局部变量 file_id, 文本型
' 第1步:提交任务,拿到 file_id 后即可返回(任务在服务端处理)
视频数据 = 读入文件 ("你的视频路径.mp4")
局_网址 = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
局_提交协议头 = "APIKEY: 你的APIKEY"
局_结果 = 网页_访问_对象 (局_网址, 1, , 视频数据, , 局_提交协议头, , , , , , , , , , , , , )
局_返回 = 到文本 (编码_编码转换对象 (局_结果, , , ))
' 解析返回中的 file_id 并保存
' 第2步:查询任务结果(可按 wait_time 间隔重复查询,status 为 done 时获取 result_url)
局_结果 = 网页_访问_对象 (局_网址, 1, "file_id=" + file_id, , , 局_提交协议头, , , , , , , , , , , , , )
局_返回 = 到文本 (编码_编码转换对象 (局_结果, , , ))
返回 (局_返回)
4.9 天诺
public static string Api_VideoSuperResolution(string apiKey, string videoPath)
{
string url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1";
var headers = new Dictionary<string, string>
{
{"APIKEY", apiKey}
};
// 使用 multipart/form-data 上传视频文件
var files = new Dictionary<string, string>
{
{"file", videoPath}
};
var formData = new Dictionary<string, string>
{
{"size", "1080"}
};
// 提交任务并轮询等待结果(同步等待),status 为 done 时下载 result_url
string response = CustomHelp.HttpPostMultipart(url, files, formData, headers);
// 解析返回中的 file_id,按 wait_time 间隔循环查询
return response;
}
public static string Api_VideoSuperResolutionAsync(string apiKey, string videoPath)
{
string url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1";
var headers = new Dictionary<string, string>
{
{"APIKEY", apiKey}
};
// 第1步:提交任务,拿到 file_id 后即可返回(任务在服务端处理)
var files = new Dictionary<string, string>
{
{"file", videoPath}
};
var formData = new Dictionary<string, string>
{
{"size", "1080"}
};
string response = CustomHelp.HttpPostMultipart(url, files, formData, headers);
// 解析返回中的 file_id 并保存
// 第2步:查询任务结果(status 为 done 时获取 result_url)
var pollData = new Dictionary<string, string>
{
{"file_id", "上一步返回的file_id"}
};
response = CustomHelp.HttpPostMultipart(url, new Dictionary<string, string>(), pollData, headers);
return response;
}
4.10 按键精灵-电脑版
Import "Encrypt.dll"
VBSBegin
' 启用错误处理
On Error Resume Next
Function api_video_super_resolution(apiKey, videoPath)
' 先检查文件是否存在,避免后续错误
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(videoPath) Then
api_video_super_resolution = "ERROR: 视频文件不存在 - " & videoPath
Exit Function
End If
url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "POST", url, False
http.setRequestHeader "APIKEY", apiKey
' multipart/form-data 上传视频文件
Dim boundary : boundary = "------FormBoundary" & Timer
http.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & boundary
' 读取视频文件并构造 multipart body
Dim inFile : Set inFile = fso.GetFile(videoPath)
Dim ts : Set ts = inFile.OpenAsTextStream(1, -2)
Dim fileData : fileData = ts.Read(inFile.Size)
ts.Close
Dim body : body = "--" & boundary & vbCrLf
body = body & "Content-Disposition: form-data; name=""file""; filename=""" & inFile.Name & """" & vbCrLf
body = body & "Content-Type: application/octet-stream" & vbCrLf & vbCrLf
body = body & fileData & vbCrLf
body = body & "--" & boundary & vbCrLf
body = body & "Content-Disposition: form-data; name=""size""" & vbCrLf & vbCrLf
body = body & "1080" & vbCrLf
body = body & "--" & boundary & "--" & vbCrLf
' 发送请求
On Error Resume Next ' 再次确保捕获网络错误
http.send body
If Err.Number <> 0 Then
api_video_super_resolution = "HTTP发送错误: " & Err.Description
Err.Clear
Exit Function
End If
' 检查HTTP状态
If http.Status <> 200 Then
api_video_super_resolution = "HTTP状态异常: " & http.Status & " - " & http.statusText
Exit Function
End If
responseText = http.responseText
' 同步等待:解析 file_id 后循环轮询,status 为 done 时下载 result_url
Do
WScript.Sleep 1200
jsonBody = "{" & Chr(34) & "file_id" & Chr(34) & ":" & Chr(34) & "上一步返回的file_id" & Chr(34) & "}"
http.send jsonBody
responseText = http.responseText
' status 为 done 时结束循环
Loop
api_video_super_resolution = responseText
Set http = Nothing
Set ts = Nothing
Set inFile = Nothing
Set fso = Nothing
End Function
VBSEnd
' 主程序部分
apiKey = "你的APIKEY" ' 请替换为真实APIKEY
videoPath = "你的视频路径.mp4" ' 请替换为真实视频路径
res = api_video_super_resolution(apiKey, videoPath)
' 输出结果,如果出错则显示错误信息
If Left(res, 5) = "ERROR" Or Left(res, 6) = "HTTP状态" Or Left(res, 5) = "HTTP发" Then
TracePrint "【错误】" & res
Else
TracePrint "【响应】" & res
End If
Import "Encrypt.dll"
VBSBegin
' 启用错误处理
On Error Resume Next
Function api_video_super_resolution_async(apiKey, videoPath)
' 先检查文件是否存在,避免后续错误
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(videoPath) Then
api_video_super_resolution_async = "ERROR: 视频文件不存在 - " & videoPath
Exit Function
End If
url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "POST", url, False
http.setRequestHeader "APIKEY", apiKey
' multipart/form-data 上传视频文件
Dim boundary : boundary = "------FormBoundary" & Timer
http.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & boundary
' 读取视频文件并构造 multipart body
Dim inFile : Set inFile = fso.GetFile(videoPath)
Dim ts : Set ts = inFile.OpenAsTextStream(1, -2)
Dim fileData : fileData = ts.Read(inFile.Size)
ts.Close
Dim body : body = "--" & boundary & vbCrLf
body = body & "Content-Disposition: form-data; name=""file""; filename=""" & inFile.Name & """" & vbCrLf
body = body & "Content-Type: application/octet-stream" & vbCrLf & vbCrLf
body = body & fileData & vbCrLf
body = body & "--" & boundary & vbCrLf
body = body & "Content-Disposition: form-data; name=""size""" & vbCrLf & vbCrLf
body = body & "1080" & vbCrLf
body = body & "--" & boundary & "--" & vbCrLf
' 发送请求
On Error Resume Next ' 再次确保捕获网络错误
http.send body
If Err.Number <> 0 Then
api_video_super_resolution_async = "HTTP发送错误: " & Err.Description
Err.Clear
Exit Function
End If
' 检查HTTP状态
If http.Status <> 200 Then
api_video_super_resolution_async = "HTTP状态异常: " & http.Status & " - " & http.statusText
Exit Function
End If
responseText = http.responseText
' 第1步完成:解析返回中的 file_id 并保存,供后续查询
' 第2步:查询任务结果(status 为 done 时获取 result_url)
jsonBody = "{" & Chr(34) & "file_id" & Chr(34) & ":" & Chr(34) & "上一步返回的file_id" & Chr(34) & "}"
http.send jsonBody
api_video_super_resolution_async = http.responseText
Set http = Nothing
Set ts = Nothing
Set inFile = Nothing
Set fso = Nothing
End Function
VBSEnd
' 主程序部分
apiKey = "你的APIKEY" ' 请替换为真实APIKEY
videoPath = "你的视频路径.mp4" ' 请替换为真实视频路径
res = api_video_super_resolution_async(apiKey, videoPath)
' 输出结果,如果出错则显示错误信息
If Left(res, 5) = "ERROR" Or Left(res, 6) = "HTTP状态" Or Left(res, 5) = "HTTP发" Then
TracePrint "【错误】" & res
Else
TracePrint "【响应】" & res
End If
4.11 按键精灵-手机版
Import "yd.luae"
Import "zm.luae"
Dim videoPath = "/sdcard/Pictures/test.mp4"
' 同步:提交任务后轮询等待,处理完成后下载结果
Function api_video_super_resolution(apiKey, videoPath)
Dim url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
Dim headers = {null}
headers["APIKEY"] = apiKey
Dim body = "{""file_url"":""" & videoPath & """,""size"":1080}"
Dim res = yd.HttpPost(url, body, headers)
Dim data = yd.JsonDecode(res)
Dim fileId = data["file_id"]
' 轮询等待结果(同步等待),status 为 done 时下载 result_url
Do
Delay data["wait_time"] * 1000
Dim pollBody = "{""file_id"":""" & fileId & """}"
res = yd.HttpPost(url, pollBody, headers)
data = yd.JsonDecode(res)
Loop While data["status"] <> "done"
Dim resultUrl = data["result_url"]
yd.DownloadFile(resultUrl, "/sdcard/Pictures/result.mp4")
api_video_super_resolution = data
End Function
Dim apiKey = "你的APIKEY"
Dim res = api_video_super_resolution(apiKey, videoPath)
TracePrint res["code"]
Import "yd.luae"
Import "zm.luae"
Dim videoPath = "/sdcard/Pictures/test.mp4"
' 异步:提交与获取结果分两步处理
' 第1步:提交任务,拿到 file_id 后即可返回(任务在服务端处理)
Function api_video_super_resolution_submit(apiKey, videoPath)
Dim url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
Dim headers = {null}
headers["APIKEY"] = apiKey
Dim body = "{""file_url"":""" & videoPath & """,""size"":1080}"
Dim res = yd.HttpPost(url, body, headers)
api_video_super_resolution_submit = yd.JsonDecode(res)
End Function
' 第2步:查询任务结果(status 为 done 时获取 result_url)
Function api_video_super_resolution_fetch(apiKey, fileId)
Dim url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
Dim headers = {null}
headers["APIKEY"] = apiKey
Dim body = "{""file_id"":""" & fileId & """}"
Dim res = yd.HttpPost(url, body, headers)
api_video_super_resolution_fetch = yd.JsonDecode(res)
End Function
Dim apiKey = "你的APIKEY"
Dim data = api_video_super_resolution_submit(apiKey, videoPath)
TracePrint data["file_id"]
' 稍后查询结果(可按 wait_time 间隔重复查询)
Dim result = api_video_super_resolution_fetch(apiKey, data["file_id"])
TracePrint result["status"]
4.12 触动精灵
require("tsnet")
require "TSLib"
local ts = require("ts")
local json = ts.json
-- 同步:提交任务后轮询等待,处理完成后下载结果
function api_video_super_resolution(apiKey, videoPath)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local headers = {}
headers["APIKEY"] = apiKey
headers["Content-Type"] = "application/json"
local body = json.encode({ file_url = videoPath, size = 1080 })
local resp = httpPost(url, body, { headers = headers })
local data = json.decode(resp)
local fileId = data.file_id
-- 轮询等待结果(同步等待),status 为 done 时下载 result_url
while true do
mSleep((data.wait_time or 1) * 1000)
local pollBody = json.encode({ file_id = fileId })
local pollResp = httpPost(url, pollBody, { headers = headers })
data = json.decode(pollResp)
if data.status == "done" then
-- 下载结果视频
local resultUrl = data.result_url
local res = httpGet(resultUrl)
if res then
local filename = string.match(resultUrl, "([^/]+)$")
writeFile("/var/mobile/Media/" .. filename, res)
end
return data
end
end
end
local apiKey = "你的APIKEY"
local videoPath = "/var/mobile/Media/test.mp4"
local data = api_video_super_resolution(apiKey, videoPath)
require("tsnet")
require "TSLib"
local ts = require("ts")
local json = ts.json
-- 异步:提交与获取结果分两步处理
-- 第1步:提交任务,拿到 file_id 后即可返回(任务在服务端处理)
function api_video_super_resolution_submit(apiKey, videoPath)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local headers = {}
headers["APIKEY"] = apiKey
headers["Content-Type"] = "application/json"
local body = json.encode({ file_url = videoPath, size = 1080 })
local resp = httpPost(url, body, { headers = headers })
return json.decode(resp)
end
-- 第2步:查询任务结果(status 为 done 时获取 result_url)
function api_video_super_resolution_fetch(apiKey, fileId)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local headers = {}
headers["APIKEY"] = apiKey
headers["Content-Type"] = "application/json"
local body = json.encode({ file_id = fileId })
local resp = httpPost(url, body, { headers = headers })
return json.decode(resp)
end
local apiKey = "你的APIKEY"
local videoPath = "/var/mobile/Media/test.mp4"
local data = api_video_super_resolution_submit(apiKey, videoPath)
-- 稍后查询结果(可按 wait_time 间隔重复查询)
local result = api_video_super_resolution_fetch(apiKey, data.file_id)
if result.status == "done" then
local res = httpGet(result.result_url)
if res then
writeFile("/var/mobile/Media/result.mp4", res)
end
end
4.13 懒人精灵
-- 同步:提交任务后轮询等待,处理完成后下载结果
function api_video_super_resolution(apiKey, videoPath)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local headers = {}
headers["APIKEY"] = apiKey
headers["Content-Type"] = "application/json"
local body = jsonLib.encode({ file_url = videoPath, size = 1080 })
local resp = httpPost(url, body, { headers = headers })
local data = jsonLib.decode(resp)
local fileId = data.file_id
-- 轮询等待结果(同步等待),status 为 done 时下载 result_url
while true do
sleep((data.wait_time or 1) * 1000)
local pollBody = jsonLib.encode({ file_id = fileId })
local pollResp = httpPost(url, pollBody, { headers = { ["APIKEY"] = apiKey, ["Content-Type"] = "application/json" } })
data = jsonLib.decode(pollResp)
if data.status == "done" then
downloadFile(data.result_url, "/sdcard/Pictures/result.mp4")
return data
end
end
end
local apiKey = "你的APIKEY"
local videoPath = "/sdcard/Pictures/test.mp4"
local data = api_video_super_resolution(apiKey, videoPath)
-- 异步:提交与获取结果分两步处理
-- 第1步:提交任务,拿到 file_id 后即可返回(任务在服务端处理)
function api_video_super_resolution_submit(apiKey, videoPath)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local headers = {}
headers["APIKEY"] = apiKey
headers["Content-Type"] = "application/json"
local body = jsonLib.encode({ file_url = videoPath, size = 1080 })
local resp = httpPost(url, body, { headers = headers })
return jsonLib.decode(resp)
end
-- 第2步:查询任务结果(status 为 done 时获取 result_url)
function api_video_super_resolution_fetch(apiKey, fileId)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local headers = {}
headers["APIKEY"] = apiKey
headers["Content-Type"] = "application/json"
local body = jsonLib.encode({ file_id = fileId })
local resp = httpPost(url, body, { headers = headers })
return jsonLib.decode(resp)
end
local apiKey = "你的APIKEY"
local videoPath = "/sdcard/Pictures/test.mp4"
local data = api_video_super_resolution_submit(apiKey, videoPath)
-- 稍后查询结果(可按 wait_time 间隔重复查询)
local result = api_video_super_resolution_fetch(apiKey, data.file_id)
if result.status == "done" then
downloadFile(result.result_url, "/sdcard/Pictures/result.mp4")
end
4.14 EasyClick
-- 同步:提交任务后轮询等待,处理完成后下载结果
function api_video_super_resolution(apiKey, videoPath)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local headers = {
["APIKEY"] = apiKey,
["Content-Type"] = "application/json"
}
local body = JSON.stringify({ file_url = videoPath, size = 1080 })
local params = {
url = url,
method = "POST",
headers = headers,
requestBody = body
}
local res = http.request(params)
local data = JSON.parse(res.body)
local fileId = data.file_id
-- 轮询等待结果(同步等待),status 为 done 时下载 result_url
while true do
sleep((data.wait_time or 1) * 1000)
params.requestBody = JSON.stringify({ file_id = fileId })
res = http.request(params)
data = JSON.parse(res.body)
if data.status == "done" then
logd("视频变高清成功: " .. tostring(data.result_url))
return data
end
end
end
function main()
local apiKey = "你的APIKEY"
local videoPath = "/sdcard/Pictures/test.mp4"
local data = api_video_super_resolution(apiKey, videoPath)
if data then
logd(data.status)
end
end
main()
-- 异步:提交与获取结果分两步处理
-- 第1步:提交任务,拿到 file_id 后即可返回(任务在服务端处理)
function api_video_super_resolution_submit(apiKey, videoPath)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local headers = {
["APIKEY"] = apiKey,
["Content-Type"] = "application/json"
}
local body = JSON.stringify({ file_url = videoPath, size = 1080 })
local params = {
url = url,
method = "POST",
headers = headers,
requestBody = body
}
local res = http.request(params)
return JSON.parse(res.body)
end
-- 第2步:查询任务结果(status 为 done 时获取 result_url)
function api_video_super_resolution_fetch(apiKey, fileId)
local url = "http(s)://api.shiliuai.com/api/video_super_resolution/v1"
local params = {
url = url,
method = "POST",
headers = {
["APIKEY"] = apiKey,
["Content-Type"] = "application/json"
},
requestBody = JSON.stringify({ file_id = fileId })
}
local res = http.request(params)
return JSON.parse(res.body)
end
function main()
local apiKey = "你的APIKEY"
local videoPath = "/sdcard/Pictures/test.mp4"
local data = api_video_super_resolution_submit(apiKey, videoPath)
logd(data.file_id)
-- 稍后查询结果(可按 wait_time 间隔重复查询)
local result = api_video_super_resolution_fetch(apiKey, data.file_id)
logd(result.status)
end
main()