enhance_video_sync
Synchronously enhances video quality by upscaling to a chosen resolution. Supports video input via URL or local file path.
Instructions
同步增强视频(阻塞等待完成)
支持两种上传方式:
URL 上传:提供视频 URL
本地上传:提供本地文件路径,MCP Server 自动上传到 TOS 对象存储
参数说明:
video_source: 视频 URL 或本地文件路径
type: "url" 或 "local"
resolution: 目标分辨率
poll_interval: 轮询间隔(秒)
timeout: 超时时间(秒)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| video_source | Yes | 视频URL地址或本地文件路径 | |
| type | No | 上传类型:url=网络视频,local=本地文件 | url |
| resolution | No | 目标分辨率,默认720p | 720p |
| poll_interval | No | 轮询间隔(秒),默认5 | |
| timeout | No | 超时时间(秒),默认600 |
Implementation Reference
- src/server.ts:376-415 (handler)The `enhanceVideoSync` private method that contains the core logic: creates a task, then polls for status completion (or failure), with timeout handling. This is the main implementation of the tool.
private async enhanceVideoSync( videoSource: string, sourceType: string, resolution: string, pollInterval: number, timeout: number ): Promise<any> { // 创建任务 const createResult = await this.createTask(videoSource, sourceType, resolution); if (!createResult.success) { return createResult; } const taskId = createResult.task_id; // 轮询等待完成 const startTime = Date.now(); while (true) { const status = await this.getTaskStatus(taskId); if (!status.success) { return status; } if (status.status === 'completed' || status.status === 'failed') { return status; } const elapsed = (Date.now() - startTime) / 1000; if (elapsed >= timeout) { return { success: false, error: `任务超时: ${taskId}`, task_id: taskId, }; } await this.sleep(pollInterval * 1000); } } - src/server.ts:49-55 (schema)Zod schema for input validation of the enhance_video_sync tool, defining video_source, type, resolution, poll_interval, and timeout fields.
const EnhanceVideoSyncSchema = z.object({ video_source: z.string().describe('视频URL地址或本地文件路径'), type: z.enum(['url', 'local']).default('url').describe('上传类型:url=网络视频,local=本地文件'), resolution: z.enum(['480p', '540p', '720p', '1080p', '2k']).default('720p').describe('目标分辨率,默认720p'), poll_interval: z.number().default(5).describe('轮询间隔(秒),默认5'), timeout: z.number().default(600).describe('超时时间(秒),默认600'), }); - src/server.ts:163-208 (registration)Registration of the 'enhance_video_sync' tool via `this.server.tool()`, binding the schema and the async handler that calls `this.enhanceVideoSync()`. Called within `setupTools()`.
// enhance_video_sync tool this.server.tool( 'enhance_video_sync', `同步增强视频(阻塞等待完成) 支持两种上传方式: 1. URL 上传:提供视频 URL 2. 本地上传:提供本地文件路径,MCP Server 自动上传到 TOS 对象存储 参数说明: - video_source: 视频 URL 或本地文件路径 - type: "url" 或 "local" - resolution: 目标分辨率 - poll_interval: 轮询间隔(秒) - timeout: 超时时间(秒)`, EnhanceVideoSyncSchema.shape, async (args) => { try { const result = await this.enhanceVideoSync( args.video_source, args.type, args.resolution, args.poll_interval, args.timeout ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: errorMessage }, null, 2), }, ], }; } } ); - src/server.ts:417-419 (helper)The `sleep` helper utility used by the polling loop to wait between status checks.
private sleep(ms: number): Promise<void> { return new Promise((resolve) => setTimeout(resolve, ms)); } - src/server.ts:307-351 (helper)The `createTask` private method called by `enhanceVideoSync` to initiate the video enhancement task (handles both URL and local file upload via TOS).
private async createTask( videoSource: string, sourceType: string, resolution: string ): Promise<any> { let contentItem: any; if (sourceType === 'local') { // 本地上传:检查文件、获取 TOS 签名、直传文件 const fileInfo = this.checkLocalFile(videoSource); const signatureData = await this.getTosSignature(fileInfo.fileName); await this.uploadToTos(videoSource, signatureData); const fileId = this.parseFileIdFromUrl(signatureData.url); contentItem = { type: 'video_file', file_id: fileId, file_name: fileInfo.fileName, }; } else { // URL 上传 contentItem = { type: 'video_url', video_url: { url: videoSource }, }; } const payload = { model: 'avc-enhance', content: [contentItem], resolution, }; const response = await this.client.post('/api/v3/contents/generations/tasks', payload); const data = response.data; if (data.code !== 0 && data.code !== 200) { return { success: false, error: data.message }; } return { success: true, task_id: data.data.task_id, status: data.data.status, }; }