diff --git a/packages/cli/src/commands.ts b/packages/cli/src/commands.ts index 0de5e76f..d090ea19 100644 --- a/packages/cli/src/commands.ts +++ b/packages/cli/src/commands.ts @@ -21,6 +21,8 @@ import { videoGenerate, videoEdit, videoRef, + videoRetalk, + videoStyle, videoTaskGet, videoDownload, visionDescribe, @@ -414,6 +416,8 @@ export const commands: Record = { "video generate": videoGenerate, "video edit": videoEdit, "video ref": videoRef, + "video retalk": videoRetalk, + "video style": videoStyle, "video task get": videoTaskGet, "video download": videoDownload, "vision describe": visionDescribe, diff --git a/packages/commands/src/commands/shared/dashscope-task.ts b/packages/commands/src/commands/shared/dashscope-task.ts index 1a8bdfbc..775c5b0c 100644 --- a/packages/commands/src/commands/shared/dashscope-task.ts +++ b/packages/commands/src/commands/shared/dashscope-task.ts @@ -33,6 +33,26 @@ function isTimeoutLikeError(error: unknown): boolean { return false; } +function joinHints(...parts: Array): string | undefined { + const joined = parts + .map((part) => part?.trim()) + .filter((part): part is string => Boolean(part)) + .join(" "); + return joined.length > 0 ? joined : undefined; +} + +/** + * Terminal FAILED/CANCELED/UNKNOWN thrown from load() set api without httpStatus. + * HTTP failures from the poll GET go through mapApiError and set api.httpStatus. + */ +function isTerminalTaskStatusError(error: BailianError): boolean { + return ( + error.exitCode === ExitCode.GENERAL && + error.api !== undefined && + error.api.httpStatus === undefined + ); +} + /** Poll a DashScope async task until SUCCEEDED, FAILED, CANCELED, or UNKNOWN. */ export async function pollDashScopeTask( ctx: { @@ -48,6 +68,15 @@ export async function pollDashScopeTask( extraCheck?: (data: DashScopeTaskResponse) => void; }, ): Promise { + const pollInterruptHint = ctx.localize({ + "en-US": `Task may still be running. Query or re-download with task_id ${taskId}; do not resubmit.`, + "zh-CN": `任务可能仍在执行。请用 task_id ${taskId} 查询或重新下载,勿重新提交。`, + }); + const terminalHint = ctx.localize({ + "en-US": `Inspect with task_id ${taskId}.`, + "zh-CN": `可用 task_id ${taskId} 查询任务。`, + }); + try { return await poll(ctx.client, { output: ctx.output, @@ -93,22 +122,42 @@ export async function pollDashScopeTask( getStatus: (data) => (data as DashScopeTaskResponse).output.task_status, }); } catch (error) { - // Include submitted task_id for both poll-loop TIMEOUT and hung single GETs (AbortError). + // Keep messages intact for AEM; put task_id only in hint (timeout / interrupt / terminal). if (isTimeoutLikeError(error)) { throw new BailianError( ctx.localize({ - "en-US": `Polling timed out. task_id=${taskId}`, - "zh-CN": `轮询超时。task_id=${taskId}`, + "en-US": "Polling timed out.", + "zh-CN": "轮询超时。", }), ExitCode.TIMEOUT, - ctx.localize({ - "en-US": `Try increasing --timeout, or query the task with id ${taskId}.`, - "zh-CN": `可增大 --timeout,或用 task_id ${taskId} 查询任务状态。`, - }), + joinHints( + ctx.localize({ + "en-US": `Try increasing --timeout, or query the task with id ${taskId}.`, + "zh-CN": `可增大 --timeout,或用 task_id ${taskId} 查询任务状态。`, + }), + pollInterruptHint, + ), { cause: error }, ); } - throw error; + if (error instanceof BailianError) { + if (isTerminalTaskStatusError(error)) { + throw new BailianError(error.message, error.exitCode, joinHints(error.hint, terminalHint), { + cause: error.cause ?? error, + api: error.api, + rawResponse: error.rawResponse, + }); + } + // Poll interrupt: preserve message; append do-not-resubmit hint (includes task_id). + throw new BailianError( + error.message, + error.exitCode, + joinHints(error.hint, pollInterruptHint), + { cause: error.cause ?? error, api: error.api, rawResponse: error.rawResponse }, + ); + } + const originalMessage = error instanceof Error ? error.message : String(error); + throw new BailianError(originalMessage, ExitCode.GENERAL, pollInterruptHint, { cause: error }); } } diff --git a/packages/commands/src/commands/video/download.ts b/packages/commands/src/commands/video/download.ts index 9ceaa316..407d03c8 100644 --- a/packages/commands/src/commands/video/download.ts +++ b/packages/commands/src/commands/video/download.ts @@ -62,7 +62,9 @@ export default defineCommand({ } const downloadUrl = - taskInfo.output.video_url || (taskInfo.output.results && taskInfo.output.results[0]?.url); + taskInfo.output.video_url || + taskInfo.output.output_video_url || + (taskInfo.output.results && taskInfo.output.results[0]?.url); if (!downloadUrl) { throw new BailianError("No download URL available for this task.", ExitCode.GENERAL); diff --git a/packages/commands/src/commands/video/edit.ts b/packages/commands/src/commands/video/edit.ts index 87c022de..0b4764b8 100644 --- a/packages/commands/src/commands/video/edit.ts +++ b/packages/commands/src/commands/video/edit.ts @@ -21,8 +21,9 @@ import { BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT, BOOL_FLAG_WATERMARK } from "bailia export default defineCommand({ description: { "en-US": - "Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.)", - "zh-CN": "使用 happyhorse-1.0-video-edit 编辑视频(风格转换、对象替换等)", + "Edit a video with happyhorse-1.0-video-edit (prompt-based style/object edits; preset comic/ink restyle → video style)", + "zh-CN": + "使用 happyhorse-1.0-video-edit 编辑视频(基于提示词的风格/对象编辑;预设漫画/水墨重绘请用 video style)", }, auth: "apiKey", usageArgs: "--video --prompt [flags]", diff --git a/packages/commands/src/commands/video/retalk.ts b/packages/commands/src/commands/video/retalk.ts new file mode 100644 index 00000000..6da39679 --- /dev/null +++ b/packages/commands/src/commands/video/retalk.ts @@ -0,0 +1,175 @@ +import { + defineCommand, + image2videoPath, + stripUndefined, + type DashScopeVideoRetalkRequest, + type FlagsDef, +} from "bailian-cli-core"; +import { + extractVideoUrlField, + mediaInputError, + previewMediaUrl, + resolveMediaUrl, + runSpecializedVideoLifecycle, + SPECIALIZED_VIDEO_SHARED_FLAGS, + specializedLifecycleFlagError, +} from "./specialized-shared.ts"; + +const MODEL = "videoretalk"; + +const RETALK_FLAGS = { + video: { + type: "string", + valueHint: "", + description: { + "en-US": "Input video URL or local file (mp4/avi/mov)", + "zh-CN": "输入视频 URL 或本地文件(mp4/avi/mov)", + }, + required: true, + }, + audio: { + type: "string", + valueHint: "", + description: { + "en-US": "Driving audio URL or local file (wav/mp3/aac)", + "zh-CN": "驱动音频 URL 或本地文件(wav/mp3/aac)", + }, + required: true, + }, + refImage: { + type: "string", + valueHint: "", + description: { + "en-US": "Optional reference face image when the video has multiple people", + "zh-CN": "多人视频中可选的参考人脸图", + }, + }, + videoExtension: { + type: "boolean", + valueHint: "", + description: { + "en-US": + "Extend video by alternating reverse/forward playback when audio is longer (default: false)", + "zh-CN": "音频长于视频时是否倒放/正放交替延展(默认 false)", + }, + }, + faceThreshold: { + type: "number", + valueHint: "", + description: { + "en-US": "Face match threshold 120–200 (default: 170; only with --ref-image)", + "zh-CN": "人脸匹配阈值 120–200(默认 170;仅与 --ref-image 联用)", + }, + }, + ...SPECIALIZED_VIDEO_SHARED_FLAGS, +} satisfies FlagsDef; + +export default defineCommand({ + description: { + "en-US": "Drive a talking-head video with audio (VideoRetalk)", + "zh-CN": "用音频驱动人像口型视频(VideoRetalk)", + }, + auth: "apiKey", + usageArgs: "--video --audio [flags]", + flags: RETALK_FLAGS, + exampleArgs: [ + { + "en-US": + "--video https://example.com/face.mp4 --audio https://example.com/speech.wav --download out.mp4", + "zh-CN": + "--video https://example.com/face.mp4 --audio https://example.com/speech.wav --download out.mp4", + }, + { + "en-US": + "--video ./face.mp4 --audio ./speech.wav --ref-image ./person.jpg --face-threshold 170", + "zh-CN": + "--video ./face.mp4 --audio ./speech.wav --ref-image ./person.jpg --face-threshold 170", + }, + ], + notes: [ + { + "en-US": + "Fixed model videoretalk (Beijing only). Wait-mode polling uses at least 600s (--timeout lower values are raised).", + "zh-CN": + "固定模型 videoretalk(仅北京)。等待模式轮询至少 600 秒(更小的 --timeout 会被抬高)。", + }, + ], + validate: (flags) => { + const sharedError = specializedLifecycleFlagError(flags); + if (sharedError) return sharedError; + if (flags.faceThreshold !== undefined) { + if ( + !Number.isInteger(flags.faceThreshold) || + flags.faceThreshold < 120 || + flags.faceThreshold > 200 + ) { + return { + "en-US": "--face-threshold must be an integer between 120 and 200.", + "zh-CN": "--face-threshold 必须是 120–200 的整数。", + }; + } + if (!flags.refImage) { + return { + "en-US": "--face-threshold requires --ref-image.", + "zh-CN": "--face-threshold 需要同时提供 --ref-image。", + }; + } + } + const videoError = mediaInputError(flags.video, "--video", { allowLocal: true }); + if (videoError) return videoError; + const audioError = mediaInputError(flags.audio, "--audio", { allowLocal: true }); + if (audioError) return audioError; + if (flags.refImage !== undefined) { + const refError = mediaInputError(flags.refImage, "--ref-image", { allowLocal: true }); + if (refError) return refError; + } + return undefined; + }, + async run(ctx) { + const { flags } = ctx; + + function buildRequest(media: { + videoUrl: string; + audioUrl: string; + refImageUrl?: string; + }): DashScopeVideoRetalkRequest { + const parameters = stripUndefined({ + video_extension: flags.videoExtension, + query_face_threshold: flags.faceThreshold, + }); + return { + model: MODEL, + input: stripUndefined({ + video_url: media.videoUrl, + audio_url: media.audioUrl, + ref_image_url: media.refImageUrl, + }) as DashScopeVideoRetalkRequest["input"], + parameters: Object.keys(parameters).length > 0 ? parameters : undefined, + }; + } + + const previewRequest = buildRequest({ + videoUrl: previewMediaUrl(flags.video), + audioUrl: previewMediaUrl(flags.audio), + refImageUrl: flags.refImage !== undefined ? previewMediaUrl(flags.refImage) : undefined, + }); + + await runSpecializedVideoLifecycle(ctx, { + endpointPath: image2videoPath(), + previewRequest, + resolveLiveRequest: async () => { + const videoUrl = await resolveMediaUrl(ctx.client, flags.video, MODEL); + const audioUrl = await resolveMediaUrl(ctx.client, flags.audio, MODEL); + const refImageUrl = + flags.refImage !== undefined + ? await resolveMediaUrl(ctx.client, flags.refImage, MODEL) + : undefined; + return buildRequest({ videoUrl, audioUrl, refImageUrl }); + }, + extractVideoUrl: extractVideoUrlField, + pollInterval: flags.pollInterval, + download: flags.download, + async: flags.async, + }); + }, +}); diff --git a/packages/commands/src/commands/video/specialized-shared.ts b/packages/commands/src/commands/video/specialized-shared.ts new file mode 100644 index 00000000..58dadc91 --- /dev/null +++ b/packages/commands/src/commands/video/specialized-shared.ts @@ -0,0 +1,315 @@ +import { + BailianError, + ExitCode, + REGIONS, + resolveOutputDir, + ASYNC_FLAG, + type Client, + type CommandContext, + type DashScopeAsyncResponse, + type DashScopeTaskResponse, + type FlagsDef, + type LocalizedText, +} from "bailian-cli-core"; +import { dirname, join } from "path"; +import { accessSync, constants, existsSync, lstatSync, statSync } from "fs"; +import { downloadDashScopeTaskResult, pollDashScopeTask } from "../shared/dashscope-task.ts"; +import { isHttpUrl } from "../shared/translation.ts"; + +/** Floor aligned with video edit/ref long-running tasks. */ +export const SPECIALIZED_VIDEO_TIMEOUT_FLOOR_SEC = 600; + +const BEIJING_ONLY_MESSAGE: LocalizedText = { + "en-US": + "This model is available only in China (Beijing). Use the Beijing base URL (https://dashscope.aliyuncs.com) and a Beijing-region API Key.", + "zh-CN": + "该模型仅支持华北 2(北京)地域。请使用北京地域 base URL(https://dashscope.aliyuncs.com)和北京地域 API Key。", +}; + +export const SPECIALIZED_VIDEO_SHARED_FLAGS = { + download: { + type: "string", + valueHint: "", + description: { + "en-US": "Save video to this file on completion (default: /videos/.mp4)", + "zh-CN": "完成后将视频保存到此文件(默认:/videos/.mp4)", + }, + }, + ...ASYNC_FLAG, + pollInterval: { + type: "number", + valueHint: "", + description: { + "en-US": "Polling interval when waiting (default: 15)", + "zh-CN": "等待任务时的轮询间隔(默认:15 秒)", + }, + }, +} satisfies FlagsDef; + +export function pendingUploadMarker(localPath: string): string { + return ``; +} + +export function previewMediaUrl(value: string): string { + if (isHttpUrl(value) || value.startsWith("oss://")) return value; + return pendingUploadMarker(value); +} + +function isOssUrl(value: string): boolean { + return value.startsWith("oss://"); +} + +/** Usage error for media flags; safe for command.validate (auth-independent). */ +export function mediaInputError( + value: string | undefined, + flagName: string, + options?: { allowLocal?: boolean }, +): LocalizedText | undefined { + if (value === undefined || value === "") { + return { + "en-US": `${flagName} must not be empty.`, + "zh-CN": `${flagName} 不能为空。`, + }; + } + // Pass http(s) through as-is (including non-ASCII); no encodeURI. + if (isHttpUrl(value)) return undefined; + if (isOssUrl(value)) { + if (options?.allowLocal === false) { + return { + "en-US": `${flagName} must be a public http(s) URL (oss:// and local paths are not supported in v1).`, + "zh-CN": `${flagName} 必须是公网 http(s) URL(v1 不支持 oss:// 与本地路径)。`, + }; + } + return undefined; + } + if (options?.allowLocal === false) { + return { + "en-US": `${flagName} must be a public http(s) URL (local paths are not supported in v1).`, + "zh-CN": `${flagName} 必须是公网 http(s) URL(v1 不支持本地路径)。`, + }; + } + if (!existsSync(value)) { + return { + "en-US": `File not found: ${value}`, + "zh-CN": `文件不存在:${value}`, + }; + } + if (!statSync(value).isFile()) { + return { + "en-US": `Not a file: ${value}`, + "zh-CN": `不是文件:${value}`, + }; + } + return undefined; +} + +/** Validate --download before submitting a billable task. */ +export function downloadPathError(downloadPath: string | undefined): LocalizedText | undefined { + if (downloadPath === undefined || downloadPath === "") return undefined; + try { + const entry = lstatSync(downloadPath); + const targetStats = entry.isSymbolicLink() ? statSync(downloadPath) : entry; + if (!targetStats.isFile()) { + return { + "en-US": `--download must be a regular file path (not a directory): ${downloadPath}`, + "zh-CN": `--download 必须是普通文件路径(不能是目录):${downloadPath}`, + }; + } + } catch (error) { + if ((error as NodeJS.ErrnoException).code !== "ENOENT") { + return { + "en-US": `Cannot access --download path: ${downloadPath}`, + "zh-CN": `无法访问 --download 路径:${downloadPath}`, + }; + } + } + + const parentDir = dirname(downloadPath); + if (!existsSync(parentDir)) return undefined; + try { + accessSync(parentDir, constants.W_OK); + } catch { + return { + "en-US": `--download parent directory is not writable: ${parentDir}`, + "zh-CN": `--download 父目录不可写:${parentDir}`, + }; + } + return undefined; +} + +/** Shared validate for --async / --download / --poll-interval. */ +export function specializedLifecycleFlagError(flags: { + async?: boolean; + download?: string; + pollInterval?: number; +}): LocalizedText | undefined { + if ( + flags.pollInterval !== undefined && + (!(flags.pollInterval > 0) || !Number.isFinite(flags.pollInterval)) + ) { + return { + "en-US": "--poll-interval must be a positive number.", + "zh-CN": "--poll-interval 必须为正数。", + }; + } + if (flags.async) { + if (flags.download !== undefined) { + return { + "en-US": "--async cannot be combined with --download.", + "zh-CN": "--async 不能与 --download 同时使用。", + }; + } + if (flags.pollInterval !== undefined) { + return { + "en-US": "--async cannot be combined with --poll-interval.", + "zh-CN": "--async 不能与 --poll-interval 同时使用。", + }; + } + } + return downloadPathError(flags.download); +} + +export async function resolveMediaUrl( + client: Client, + value: string, + model: string, +): Promise { + if (isHttpUrl(value) || isOssUrl(value)) return value; + return client.uploadFile(value, model); +} + +/** Reject known non-Beijing official DashScope hosts before submitting. */ +export function assertBeijingDashScopeEndpoint( + endpointUrl: string, + localize: (text: LocalizedText) => string, +): void { + let hostname: string; + try { + hostname = new URL(endpointUrl).hostname; + } catch { + return; + } + const beijingHost = new URL(REGIONS.cn).hostname; + if (hostname === beijingHost) return; + if (hostname.endsWith(".cn-beijing.maas.aliyuncs.com")) return; + + const intlHost = new URL(REGIONS.intl).hostname; + const usHost = new URL(REGIONS.us).hostname; + const isKnownNonBeijing = + hostname === intlHost || + hostname === usHost || + hostname.includes("dashscope-intl") || + hostname.includes("dashscope-us") || + hostname.includes("ap-southeast-1") || + hostname.includes("us-east-1"); + if (!isKnownNonBeijing) return; + + throw new BailianError(localize(BEIJING_ONLY_MESSAGE), ExitCode.USAGE); +} + +export type SpecializedVideoUrlExtractor = (task: DashScopeTaskResponse) => string | undefined; + +export function extractVideoUrlField(task: DashScopeTaskResponse): string | undefined { + return task.output.video_url || task.output.results?.[0]?.url; +} + +export function extractStyleOutputVideoUrl(task: DashScopeTaskResponse): string | undefined { + return task.output.output_video_url || extractVideoUrlField(task); +} + +type SpecializedLifecycleOptions = { + endpointPath: string; + previewRequest: unknown; + /** Build the live body after any uploads; skipped on dry-run. */ + resolveLiveRequest: () => Promise; + extractVideoUrl: SpecializedVideoUrlExtractor; + pollInterval?: number; + download?: string; + async?: boolean; +}; + +/** Submit / poll / download lifecycle shared by retalk and style. */ +export async function runSpecializedVideoLifecycle( + ctx: CommandContext, + options: SpecializedLifecycleOptions, +): Promise { + const { settings } = ctx; + const localize = ctx.localize; + const endpoint = ctx.client.url(options.endpointPath); + + if (settings.dryRun) { + try { + assertBeijingDashScopeEndpoint(endpoint, localize); + } catch (error) { + if (error instanceof BailianError) { + ctx.output.progress({ + "en-US": `Warning: ${error.message}`, + "zh-CN": `警告:${error.message}`, + }); + } + } + ctx.output.result({ endpoint, request: options.previewRequest }); + return; + } + + assertBeijingDashScopeEndpoint(endpoint, localize); + + const liveRequest = await options.resolveLiveRequest(); + const submitted = await ctx.client.requestJson({ + path: options.endpointPath, + method: "POST", + body: liveRequest, + async: true, + }); + + const taskId = submitted.output.task_id; + ctx.output.progress({ + "en-US": `Submitted. task_id=${taskId}`, + "zh-CN": `已提交。task_id=${taskId}`, + }); + + if (options.async) { + ctx.output.result({ task_id: taskId, request_id: submitted.request_id }); + return; + } + + const pollIntervalSec = options.pollInterval ?? 15; + // Avoid racing the first task lookup right after submit (UNKNOWN can mean "not visible yet"). + await new Promise((resolve) => setTimeout(resolve, pollIntervalSec * 1000)); + + const pollTimeoutSec = Math.max(settings.timeout, SPECIALIZED_VIDEO_TIMEOUT_FLOOR_SEC); + const taskResponse = await pollDashScopeTask( + { + ...ctx, + settings: { ...settings, timeout: pollTimeoutSec }, + }, + taskId, + { pollInterval: pollIntervalSec }, + ); + + const videoUrl = options.extractVideoUrl(taskResponse); + if (!videoUrl) { + throw new BailianError( + localize({ + "en-US": `Task succeeded but no video URL was returned. task_id=${taskId}`, + "zh-CN": `任务成功但未返回视频 URL。task_id=${taskId}`, + }), + ExitCode.GENERAL, + localize({ + "en-US": `Query or re-download with task_id ${taskId}; do not resubmit.`, + "zh-CN": `请用 task_id ${taskId} 查询或重新下载,勿重新提交。`, + }), + ); + } + + const destPath = + options.download || join(resolveOutputDir(settings, { subDir: "videos" }), `${taskId}.mp4`); + await downloadDashScopeTaskResult(ctx, taskId, videoUrl, destPath); + + ctx.output.result({ + ...taskResponse, + task_id: taskId, + video_url: videoUrl, + saved: destPath, + }); +} diff --git a/packages/commands/src/commands/video/style.ts b/packages/commands/src/commands/video/style.ts new file mode 100644 index 00000000..0e3decf8 --- /dev/null +++ b/packages/commands/src/commands/video/style.ts @@ -0,0 +1,157 @@ +import { + defineCommand, + videoGeneratePath, + stripUndefined, + type DashScopeVideoStyleTransformRequest, + type FlagsDef, +} from "bailian-cli-core"; +import { + extractStyleOutputVideoUrl, + mediaInputError, + runSpecializedVideoLifecycle, + SPECIALIZED_VIDEO_SHARED_FLAGS, + specializedLifecycleFlagError, +} from "./specialized-shared.ts"; + +const MODEL = "video-style-transform"; + +const STYLE_FLAGS = { + video: { + type: "string", + valueHint: "", + description: { + "en-US": "Input video public URL (local paths not supported in v1)", + "zh-CN": "输入视频公网 URL(v1 不支持本地路径)", + }, + required: true, + }, + style: { + type: "number", + valueHint: "", + description: { + "en-US": + "Style ID 0–7 (default: 0). 0 Japanese comic, 1 American comic, 2 fresh comic, 3 3D cartoon, 4 Chinese cartoon, 5 paper art, 6 simple illustration, 7 Chinese ink", + "zh-CN": + "风格编号 0–7(默认 0)。0 日式漫画、1 美式漫画、2 清新漫画、3 3D 卡通、4 国风卡通、5 纸艺、6 简易插画、7 国风水墨", + }, + }, + fps: { + type: "number", + valueHint: "", + description: { + "en-US": "Output video FPS 15–25 (default: 15; maps to video_fps)", + "zh-CN": "输出视频帧率 15–25(默认 15;映射为 video_fps)", + }, + }, + animateEmotion: { + type: "boolean", + valueHint: "", + description: { + "en-US": "Animate facial emotion (server default: true)", + "zh-CN": "是否动画化表情(服务端默认 true)", + }, + }, + minLen: { + type: "number", + valueHint: "", + description: { + "en-US": "Short-side length 540 or 720 (server default: 720; 720P costs more than 540P)", + "zh-CN": "短边长度 540 或 720(服务端默认 720;720P 比 540P 更贵)", + }, + }, + superResolution: { + type: "boolean", + valueHint: "", + description: { + "en-US": + "Enable super-resolution (maps to use_SR; server default: false; with min_len=540 outputs 1080P billed as 540P)", + "zh-CN": + "是否启用超分(映射为 use_SR;服务端默认 false;min_len=540 时输出 1080P 仍按 540P 计费)", + }, + }, + ...SPECIALIZED_VIDEO_SHARED_FLAGS, +} satisfies FlagsDef; + +export default defineCommand({ + description: { + "en-US": + "Restyle a video with 8 presets (video-style-transform); for prompt-based edit use video edit", + "zh-CN": "按 8 种预设风格重绘视频(video-style-transform);基于提示词的编辑请用 video edit", + }, + auth: "apiKey", + usageArgs: "--video [flags]", + flags: STYLE_FLAGS, + exampleArgs: [ + { + "en-US": "--video https://example.com/clip.mp4 --style 0 --download styled.mp4", + "zh-CN": "--video https://example.com/clip.mp4 --style 0 --download styled.mp4", + }, + { + "en-US": + "--video https://example.com/clip.mp4 --style 4 --fps 15 --min-len 540 --super-resolution true", + "zh-CN": + "--video https://example.com/clip.mp4 --style 4 --fps 15 --min-len 540 --super-resolution true", + }, + ], + notes: [ + { + "en-US": + "Fixed model video-style-transform (Beijing only). Wait-mode polling uses at least 600s (--timeout lower values are raised).", + "zh-CN": + "固定模型 video-style-transform(仅北京)。等待模式轮询至少 600 秒(更小的 --timeout 会被抬高)。", + }, + ], + validate: (flags) => { + const sharedError = specializedLifecycleFlagError(flags); + if (sharedError) return sharedError; + if (flags.style !== undefined) { + if (!Number.isInteger(flags.style) || flags.style < 0 || flags.style > 7) { + return { + "en-US": "--style must be an integer between 0 and 7.", + "zh-CN": "--style 必须是 0–7 的整数。", + }; + } + } + if (flags.fps !== undefined) { + if (!Number.isInteger(flags.fps) || flags.fps < 15 || flags.fps > 25) { + return { + "en-US": "--fps must be an integer between 15 and 25.", + "zh-CN": "--fps 必须是 15–25 的整数。", + }; + } + } + if (flags.minLen !== undefined && flags.minLen !== 540 && flags.minLen !== 720) { + return { + "en-US": "--min-len must be 540 or 720.", + "zh-CN": "--min-len 必须是 540 或 720。", + }; + } + return mediaInputError(flags.video, "--video", { allowLocal: false }); + }, + async run(ctx) { + const { flags } = ctx; + + const parameters = stripUndefined({ + style: flags.style, + video_fps: flags.fps, + animate_emotion: flags.animateEmotion, + min_len: flags.minLen, + use_SR: flags.superResolution, + }); + const request: DashScopeVideoStyleTransformRequest = { + model: MODEL, + input: { video_url: flags.video }, + parameters: Object.keys(parameters).length > 0 ? parameters : undefined, + }; + + await runSpecializedVideoLifecycle(ctx, { + endpointPath: videoGeneratePath(), + previewRequest: request, + resolveLiveRequest: async () => request, + extractVideoUrl: extractStyleOutputVideoUrl, + pollInterval: flags.pollInterval, + download: flags.download, + async: flags.async, + }); + }, +}); diff --git a/packages/commands/src/commands/video/task-get.ts b/packages/commands/src/commands/video/task-get.ts index 513a795f..a20d9c0a 100644 --- a/packages/commands/src/commands/video/task-get.ts +++ b/packages/commands/src/commands/video/task-get.ts @@ -40,6 +40,7 @@ export default defineCommand({ task_id: response.output.task_id, task_status: response.output.task_status, video_url: response.output.video_url, + output_video_url: response.output.output_video_url, image_url: response.output.image_url, results: response.output.results, Success: response.output.Success, diff --git a/packages/commands/src/index.ts b/packages/commands/src/index.ts index e6f26885..77ebee74 100644 --- a/packages/commands/src/index.ts +++ b/packages/commands/src/index.ts @@ -23,6 +23,8 @@ export { default as imageTranslate } from "./commands/image/translate.ts"; export { default as videoGenerate } from "./commands/video/generate.ts"; export { default as videoEdit } from "./commands/video/edit.ts"; export { default as videoRef } from "./commands/video/ref.ts"; +export { default as videoRetalk } from "./commands/video/retalk.ts"; +export { default as videoStyle } from "./commands/video/style.ts"; export { default as videoTaskGet } from "./commands/video/task-get.ts"; export { default as videoDownload } from "./commands/video/download.ts"; export { default as visionDescribe } from "./commands/vision/describe.ts"; diff --git a/packages/commands/tests/e2e/topic-routes.ts b/packages/commands/tests/e2e/topic-routes.ts index a70c8e6e..5f7557da 100644 --- a/packages/commands/tests/e2e/topic-routes.ts +++ b/packages/commands/tests/e2e/topic-routes.ts @@ -135,11 +135,25 @@ export const VIDEO_ROUTES: E2eRouteExports = { "video generate": "videoGenerate", "video edit": "videoEdit", "video ref": "videoRef", + "video retalk": "videoRetalk", + "video style": "videoStyle", "video task get": "videoTaskGet", "video download": "videoDownload", "speech synthesize": "speechSynthesize", }; +export const VIDEO_RETALK_ROUTES: E2eRouteExports = { + "video retalk": "videoRetalk", + "video task get": "videoTaskGet", + "video download": "videoDownload", +}; + +export const VIDEO_STYLE_ROUTES: E2eRouteExports = { + "video style": "videoStyle", + "video task get": "videoTaskGet", + "video download": "videoDownload", +}; + export const VISION_ROUTES: E2eRouteExports = { "vision describe": "visionDescribe", }; diff --git a/packages/commands/tests/e2e/video-retalk.e2e.test.ts b/packages/commands/tests/e2e/video-retalk.e2e.test.ts new file mode 100644 index 00000000..fd3a6b99 --- /dev/null +++ b/packages/commands/tests/e2e/video-retalk.e2e.test.ts @@ -0,0 +1,461 @@ +import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http"; +import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { afterEach, describe, expect, test } from "vite-plus/test"; +import { + isBailianE2EVideoEnabled, + isDashScopeE2EReady, + makeE2eOutputDir, + parseStdoutJson, + runCommandHelp, + runCommandE2e, + runCommandInProcess, +} from "./helpers.ts"; +import { VIDEO_RETALK_ROUTES } from "./topic-routes.ts"; + +const servers: Server[] = []; +const tempDirs: string[] = []; + +afterEach(async () => { + await Promise.all( + servers.splice(0).map( + (server) => + new Promise((resolve, reject) => { + server.close((error) => (error ? reject(error) : resolve())); + }), + ), + ); + for (const tempDir of tempDirs.splice(0)) { + rmSync(tempDir, { recursive: true, force: true }); + } +}); + +async function startServer( + handler: (request: IncomingMessage, response: ServerResponse, body: string) => void, +): Promise<{ + origin: string; + requests: Array<{ + method?: string; + path: string; + headers: IncomingMessage["headers"]; + body: string; + }>; +}> { + const requests: Array<{ + method?: string; + path: string; + headers: IncomingMessage["headers"]; + body: string; + }> = []; + const server = createServer((request, response) => { + const chunks: Buffer[] = []; + request.on("data", (chunk) => chunks.push(chunk)); + request.on("end", () => { + const body = Buffer.concat(chunks).toString("utf8"); + const url = new URL(request.url ?? "/", "http://127.0.0.1"); + requests.push({ + method: request.method, + path: url.pathname, + headers: request.headers, + body, + }); + handler(request, response, body); + }); + }); + await new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(0, "127.0.0.1", resolve); + }); + servers.push(server); + const address = server.address(); + if (!address || typeof address === "string") throw new Error("Expected TCP address"); + return { origin: `http://127.0.0.1:${address.port}`, requests }; +} + +describe("e2e: video retalk", () => { + test("help shows bilingual flags and fixed model", async () => { + const { stderr, exitCode } = await runCommandHelp(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--video/); + expect(stderr).toMatch(/--audio/); + expect(stderr).toMatch(/face|阈值|170/); + expect(stderr).toMatch(/videoretalk/); + expect(stderr).not.toMatch(/--model/); + expect(stderr).not.toMatch(/--concurrent/); + }); + + test("missing required flags → 2", async () => { + const missingVideo = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--audio", + "https://example.com/a.wav", + ]); + expect(missingVideo.exitCode).toBe(2); + expect(missingVideo.stderr).toMatch(/--video/i); + + const missingAudio = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--video", + "https://example.com/v.mp4", + ]); + expect(missingAudio.exitCode).toBe(2); + expect(missingAudio.stderr).toMatch(/--audio/i); + }); + + test("face-threshold without ref-image → 2", async () => { + const { stderr, exitCode } = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--video", + "https://example.com/v.mp4", + "--audio", + "https://example.com/a.wav", + "--face-threshold", + "170", + ]); + expect(exitCode).toBe(2); + expect(stderr).toMatch(/face-threshold|ref-image/i); + }); + + test("non-ASCII public URL passes through on dry-run", async () => { + const videoUrl = "https://example.com/视频.mp4"; + const { stdout, stderr, exitCode } = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--video", + videoUrl, + "--audio", + "https://example.com/a.wav", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ request?: { input?: { video_url?: string } } }>(stdout); + expect(body.request?.input?.video_url).toBe(videoUrl); + }); + + test("async+download / download-dir / intl base-url → 2", async () => { + const asyncDownload = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--video", + "https://example.com/v.mp4", + "--audio", + "https://example.com/a.wav", + "--async", + "--download", + "out.mp4", + ]); + expect(asyncDownload.exitCode).toBe(2); + expect(asyncDownload.stderr).toMatch(/--async|--download/i); + + const outDir = makeE2eOutputDir("video-retalk-download-dir"); + tempDirs.push(outDir); + mkdirSync(outDir, { recursive: true }); + const dirAsDownload = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--video", + "https://example.com/v.mp4", + "--audio", + "https://example.com/a.wav", + "--download", + outDir, + ]); + expect(dirAsDownload.exitCode).toBe(2); + expect(dirAsDownload.stderr).toMatch(/regular file|普通文件|directory|目录/i); + + const intl = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--base-url", + "https://dashscope-intl.aliyuncs.com", + "--api-key", + "sk-test", + "--video", + "https://example.com/v.mp4", + "--audio", + "https://example.com/a.wav", + "--output", + "json", + ]); + expect(intl.exitCode).toBe(2); + expect(intl.stderr).toMatch(/Beijing|北京/i); + }); + + test("oss:// media accepted in dry-run", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--video", + "oss://bucket/video.mp4", + "--audio", + "oss://bucket/audio.wav", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ + request?: { input?: { video_url?: string; audio_url?: string } }; + }>(stdout); + expect(body.request?.input?.video_url).toBe("oss://bucket/video.mp4"); + expect(body.request?.input?.audio_url).toBe("oss://bucket/audio.wav"); + }); + + test("dry-run builds image2video body with pending local markers", async () => { + const fixtureDir = makeE2eOutputDir("video-retalk-dry"); + tempDirs.push(fixtureDir); + const videoPath = join(fixtureDir, "face.mp4"); + const audioPath = join(fixtureDir, "speech.wav"); + writeFileSync(videoPath, "fake-video"); + writeFileSync(audioPath, "fake-audio"); + + const { stdout, stderr, exitCode } = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--video", + videoPath, + "--audio", + audioPath, + "--video-extension", + "false", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ + endpoint?: string; + request?: { + model?: string; + input?: { video_url?: string; audio_url?: string }; + parameters?: { video_extension?: boolean; query_face_threshold?: number }; + }; + }>(stdout); + expect(body.endpoint).toMatch(/\/api\/v1\/services\/aigc\/image2video\/video-synthesis$/); + expect(body.request?.model).toBe("videoretalk"); + expect(body.request?.input?.video_url).toContain("pending-upload"); + expect(body.request?.input?.audio_url).toContain("pending-upload"); + expect(body.request?.parameters?.video_extension).toBe(false); + expect(body.request?.parameters?.query_face_threshold).toBeUndefined(); + }); + + test("async loopback posts Bearer async enable on image2video", async () => { + const { origin, requests } = await startServer((_request, response) => { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { task_id: "task-retalk-1", task_status: "PENDING" }, + request_id: "req-retalk-1", + }), + ); + }); + + const { stdout, stderr, exitCode } = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--base-url", + origin, + "--api-key", + "sk-test", + "--video", + "https://example.com/v.mp4", + "--audio", + "https://example.com/a.wav", + "--async", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ task_id?: string; request_id?: string }>(stdout); + expect(body.task_id).toBe("task-retalk-1"); + expect(body.request_id).toBe("req-retalk-1"); + expect(requests).toHaveLength(1); + expect(requests[0]?.method).toBe("POST"); + expect(requests[0]?.path).toBe("/api/v1/services/aigc/image2video/video-synthesis"); + expect(requests[0]?.headers["x-dashscope-async"]).toBe("enable"); + expect(requests[0]?.headers.authorization).toMatch(/^Bearer /); + }); + + test("wait mode continues through PRE-PROCESSING then downloads", async () => { + let pollCount = 0; + const mp4Bytes = Buffer.from("fake-mp4-bytes"); + const { origin } = await startServer((request, response) => { + const url = new URL(request.url ?? "/", "http://127.0.0.1"); + if (request.method === "POST") { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { task_id: "task-retalk-2", task_status: "PENDING" }, + request_id: "req-2", + }), + ); + return; + } + if (url.pathname === "/api/v1/tasks/task-retalk-2") { + pollCount += 1; + if (pollCount === 1) { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { task_id: "task-retalk-2", task_status: "PRE-PROCESSING" }, + request_id: "req-2", + }), + ); + return; + } + if (pollCount === 2) { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { task_id: "task-retalk-2", task_status: "POST-PROCESSING" }, + request_id: "req-2", + }), + ); + return; + } + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { + task_id: "task-retalk-2", + task_status: "SUCCEEDED", + video_url: `${origin}/out.mp4`, + }, + request_id: "req-2", + }), + ); + return; + } + if (url.pathname === "/out.mp4") { + response.writeHead(200, { "content-type": "video/mp4" }); + response.end(mp4Bytes); + return; + } + response.writeHead(404); + response.end(); + }); + + const outDir = makeE2eOutputDir("video-retalk-wait"); + tempDirs.push(outDir); + const dest = join(outDir, "retalk.mp4"); + + const { stdout, stderr, exitCode } = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--base-url", + origin, + "--api-key", + "sk-test", + "--video", + "https://example.com/v.mp4", + "--audio", + "https://example.com/a.wav", + "--poll-interval", + "0.05", + "--timeout", + "10", + "--download", + dest, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ task_id?: string; video_url?: string; saved?: string }>(stdout); + expect(body.task_id).toBe("task-retalk-2"); + expect(body.video_url).toMatch(/out\.mp4$/); + expect(body.saved).toBe(dest); + expect(readFileSync(dest).equals(mp4Bytes)).toBe(true); + }); + + test("FAILED returns server message without Task failed prefix", async () => { + const { origin } = await startServer((request, response) => { + const url = new URL(request.url ?? "/", "http://127.0.0.1"); + if (request.method === "POST") { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { task_id: "task-retalk-fail", task_status: "PENDING" }, + request_id: "req-fail", + }), + ); + return; + } + if (url.pathname === "/api/v1/tasks/task-retalk-fail") { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { + task_id: "task-retalk-fail", + task_status: "FAILED", + code: "InvalidParameter", + message: "face not detected", + }, + request_id: "req-fail", + }), + ); + return; + } + response.writeHead(404); + response.end(); + }); + + const { stderr, exitCode } = await runCommandInProcess(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--base-url", + origin, + "--api-key", + "sk-test", + "--video", + "https://example.com/v.mp4", + "--audio", + "https://example.com/a.wav", + "--poll-interval", + "0.05", + "--timeout", + "10", + ]); + expect(exitCode).toBe(1); + expect(stderr).toMatch(/face not detected/); + // Server FAILED message stays verbatim; task_id lives in the hint only. + expect(stderr).not.toMatch(/face not detected task_id=/); + expect(stderr).toMatch(/task_id[= ]task-retalk-fail|task-retalk-fail/); + expect(stderr).not.toMatch(/Task failed:/); + }); +}); + +const retalkLiveVideo = process.env.BAILIAN_E2E_VIDEORETALK_VIDEO_URL?.trim(); +const retalkLiveAudio = process.env.BAILIAN_E2E_VIDEORETALK_AUDIO_URL?.trim(); + +describe.skipIf( + !isBailianE2EVideoEnabled() || !isDashScopeE2EReady() || !retalkLiveVideo || !retalkLiveAudio, +)("e2e: video retalk(DashScope live)", () => { + test("videoretalk live retalk drive", async () => { + const outDir = makeE2eOutputDir("video-retalk-live"); + const { stdout, stderr, exitCode } = await runCommandE2e(VIDEO_RETALK_ROUTES, [ + "video", + "retalk", + "--video", + retalkLiveVideo!, + "--audio", + retalkLiveAudio!, + "--download", + join(outDir, "retalk-live.mp4"), + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ video_url?: string; saved?: string }>(stdout); + expect(body.video_url?.startsWith("https://")).toBe(true); + expect(body.saved).toBeTruthy(); + }, 3_600_000); +}); diff --git a/packages/commands/tests/e2e/video-style.e2e.test.ts b/packages/commands/tests/e2e/video-style.e2e.test.ts new file mode 100644 index 00000000..2e20e28c --- /dev/null +++ b/packages/commands/tests/e2e/video-style.e2e.test.ts @@ -0,0 +1,371 @@ +import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http"; +import { readFileSync, rmSync } from "node:fs"; +import { join } from "node:path"; +import { afterEach, describe, expect, test } from "vite-plus/test"; +import { + isBailianE2EVideoEnabled, + isDashScopeE2EReady, + makeE2eOutputDir, + parseStdoutJson, + runCommandHelp, + runCommandE2e, + runCommandInProcess, +} from "./helpers.ts"; +import { VIDEO_STYLE_ROUTES } from "./topic-routes.ts"; + +const servers: Server[] = []; +const tempDirs: string[] = []; + +afterEach(async () => { + await Promise.all( + servers.splice(0).map( + (server) => + new Promise((resolve, reject) => { + server.close((error) => (error ? reject(error) : resolve())); + }), + ), + ); + for (const tempDir of tempDirs.splice(0)) { + rmSync(tempDir, { recursive: true, force: true }); + } +}); + +async function startServer( + handler: (request: IncomingMessage, response: ServerResponse, body: string) => void, +): Promise<{ + origin: string; + requests: Array<{ + method?: string; + path: string; + headers: IncomingMessage["headers"]; + body: string; + }>; +}> { + const requests: Array<{ + method?: string; + path: string; + headers: IncomingMessage["headers"]; + body: string; + }> = []; + const server = createServer((request, response) => { + const chunks: Buffer[] = []; + request.on("data", (chunk) => chunks.push(chunk)); + request.on("end", () => { + const body = Buffer.concat(chunks).toString("utf8"); + const url = new URL(request.url ?? "/", "http://127.0.0.1"); + requests.push({ + method: request.method, + path: url.pathname, + headers: request.headers, + body, + }); + handler(request, response, body); + }); + }); + await new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(0, "127.0.0.1", resolve); + }); + servers.push(server); + const address = server.address(); + if (!address || typeof address === "string") throw new Error("Expected TCP address"); + return { origin: `http://127.0.0.1:${address.port}`, requests }; +} + +describe("e2e: video style", () => { + test("help shows bilingual flags and fixed model", async () => { + const { stderr, exitCode } = await runCommandHelp(VIDEO_STYLE_ROUTES, [ + "video", + "style", + "--help", + ]); + expect(exitCode, stderr).toBe(0); + expect(stderr).toMatch(/--video/); + expect(stderr).toMatch(/Style ID|风格编号/); + expect(stderr).toMatch(/video-style-transform/); + expect(stderr).not.toMatch(/--model/); + expect(stderr).not.toMatch(/--concurrent/); + }); + + test("missing video / local path / oss / async conflict → 2", async () => { + const missing = await runCommandInProcess(VIDEO_STYLE_ROUTES, ["video", "style", "--quiet"]); + expect(missing.exitCode).toBe(2); + expect(missing.stderr).toMatch(/--video/i); + + const localPath = await runCommandInProcess(VIDEO_STYLE_ROUTES, [ + "video", + "style", + "--video", + "./clip.mp4", + ]); + expect(localPath.exitCode).toBe(2); + expect(localPath.stderr).toMatch(/public|公网|local|本地/i); + + const ossUrl = await runCommandInProcess(VIDEO_STYLE_ROUTES, [ + "video", + "style", + "--video", + "oss://bucket/clip.mp4", + ]); + expect(ossUrl.exitCode).toBe(2); + expect(ossUrl.stderr).toMatch(/public|公网|oss:\/\//i); + + const asyncDownload = await runCommandInProcess(VIDEO_STYLE_ROUTES, [ + "video", + "style", + "--video", + "https://example.com/clip.mp4", + "--async", + "--poll-interval", + "5", + ]); + expect(asyncDownload.exitCode).toBe(2); + expect(asyncDownload.stderr).toMatch(/--async|--poll-interval/i); + }); + + test("non-ASCII public URL passes through on dry-run", async () => { + const videoUrl = "https://example.com/风格.mp4"; + const { stdout, stderr, exitCode } = await runCommandInProcess(VIDEO_STYLE_ROUTES, [ + "video", + "style", + "--video", + videoUrl, + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ request?: { input?: { video_url?: string } } }>(stdout); + expect(body.request?.input?.video_url).toBe(videoUrl); + }); + + test("dry-run preserves style=0 and boolean false", async () => { + const { stdout, stderr, exitCode } = await runCommandInProcess(VIDEO_STYLE_ROUTES, [ + "video", + "style", + "--video", + "https://example.com/clip.mp4", + "--style", + "0", + "--fps", + "15", + "--animate-emotion", + "false", + "--min-len", + "540", + "--super-resolution", + "true", + "--dry-run", + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ + endpoint?: string; + request?: { + model?: string; + input?: { video_url?: string }; + parameters?: { + style?: number; + video_fps?: number; + animate_emotion?: boolean; + min_len?: number; + use_SR?: boolean; + }; + }; + }>(stdout); + expect(body.endpoint).toMatch(/\/api\/v1\/services\/aigc\/video-generation\/video-synthesis$/); + expect(body.request?.model).toBe("video-style-transform"); + expect(body.request?.input?.video_url).toBe("https://example.com/clip.mp4"); + expect(body.request?.parameters?.style).toBe(0); + expect(body.request?.parameters?.video_fps).toBe(15); + expect(body.request?.parameters?.animate_emotion).toBe(false); + expect(body.request?.parameters?.min_len).toBe(540); + expect(body.request?.parameters?.use_SR).toBe(true); + }); + + test("wait mode continues through SUSPENDED and reads output_video_url", async () => { + let pollCount = 0; + const mp4Bytes = Buffer.from("style-mp4"); + const { origin } = await startServer((request, response) => { + const url = new URL(request.url ?? "/", "http://127.0.0.1"); + if (request.method === "POST") { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { task_id: "task-style-1", task_status: "PENDING" }, + request_id: "req-style-1", + }), + ); + return; + } + if (url.pathname === "/api/v1/tasks/task-style-1") { + pollCount += 1; + if (pollCount < 2) { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { task_id: "task-style-1", task_status: "SUSPENDED" }, + request_id: "req-style-1", + }), + ); + return; + } + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { + task_id: "task-style-1", + task_status: "SUCCEEDED", + output_video_url: `${origin}/styled.mp4`, + }, + usage: { SR: 720 }, + request_id: "req-style-1", + }), + ); + return; + } + if (url.pathname === "/styled.mp4") { + response.writeHead(200, { "content-type": "video/mp4" }); + response.end(mp4Bytes); + return; + } + response.writeHead(404); + response.end(); + }); + + const outDir = makeE2eOutputDir("video-style-wait"); + tempDirs.push(outDir); + const dest = join(outDir, "styled.mp4"); + + const { stdout, stderr, exitCode } = await runCommandInProcess(VIDEO_STYLE_ROUTES, [ + "video", + "style", + "--base-url", + origin, + "--api-key", + "sk-test", + "--video", + "https://example.com/clip.mp4", + "--style", + "0", + "--poll-interval", + "0.05", + "--timeout", + "10", + "--download", + dest, + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ + task_id?: string; + video_url?: string; + saved?: string; + output?: { output_video_url?: string }; + usage?: { SR?: number }; + }>(stdout); + expect(body.task_id).toBe("task-style-1"); + expect(body.video_url).toMatch(/styled\.mp4$/); + expect(body.output?.output_video_url).toMatch(/styled\.mp4$/); + expect(body.usage?.SR).toBe(720); + expect(readFileSync(dest).equals(mp4Bytes)).toBe(true); + }); + + test("task-get and download see output_video_url", async () => { + const mp4Bytes = Buffer.from("download-style"); + const { origin } = await startServer((request, response) => { + const url = new URL(request.url ?? "/", "http://127.0.0.1"); + if (url.pathname === "/api/v1/tasks/task-style-dl") { + response.writeHead(200, { "content-type": "application/json" }); + response.end( + JSON.stringify({ + output: { + task_id: "task-style-dl", + task_status: "SUCCEEDED", + output_video_url: `${origin}/styled.mp4`, + }, + request_id: "req-dl", + }), + ); + return; + } + if (url.pathname === "/styled.mp4") { + response.writeHead(200, { "content-type": "video/mp4" }); + response.end(mp4Bytes); + return; + } + response.writeHead(404); + response.end(); + }); + + const getResult = await runCommandInProcess(VIDEO_STYLE_ROUTES, [ + "video", + "task", + "get", + "--base-url", + origin, + "--api-key", + "sk-test", + "--task-id", + "task-style-dl", + "--output", + "json", + ]); + expect(getResult.exitCode, getResult.stderr).toBe(0); + const getBody = parseStdoutJson<{ output_video_url?: string; task_status?: string }>( + getResult.stdout, + ); + expect(getBody.task_status).toBe("SUCCEEDED"); + expect(getBody.output_video_url).toMatch(/styled\.mp4$/); + + const outDir = makeE2eOutputDir("video-style-download"); + tempDirs.push(outDir); + const dest = join(outDir, "from-task.mp4"); + const dl = await runCommandInProcess(VIDEO_STYLE_ROUTES, [ + "video", + "download", + "--base-url", + origin, + "--api-key", + "sk-test", + "--task-id", + "task-style-dl", + "--out", + dest, + "--output", + "json", + ]); + expect(dl.exitCode, dl.stderr).toBe(0); + expect(readFileSync(dest).equals(mp4Bytes)).toBe(true); + }); +}); + +const styleLiveUrl = process.env.BAILIAN_E2E_VIDEO_STYLE_URL?.trim(); + +describe.skipIf(!isBailianE2EVideoEnabled() || !isDashScopeE2EReady() || !styleLiveUrl)( + "e2e: video style(DashScope live)", + () => { + test("video-style-transform live", async () => { + const outDir = makeE2eOutputDir("video-style-live"); + const { stdout, stderr, exitCode } = await runCommandE2e(VIDEO_STYLE_ROUTES, [ + "video", + "style", + "--video", + styleLiveUrl!, + "--style", + "0", + "--download", + join(outDir, "style-live.mp4"), + "--output", + "json", + ]); + expect(exitCode, stderr).toBe(0); + const body = parseStdoutJson<{ video_url?: string; output_video_url?: string }>(stdout); + expect( + body.output_video_url?.startsWith("https://") || body.video_url?.startsWith("https://"), + ).toBe(true); + }, 3_600_000); + }, +); diff --git a/packages/core/src/types/api.ts b/packages/core/src/types/api.ts index 95c6f91f..8edbd7bf 100644 --- a/packages/core/src/types/api.ts +++ b/packages/core/src/types/api.ts @@ -281,6 +281,35 @@ export interface DashScopeVideoEditRequest { }; } +/** VideoRetalk (bl video retalk) request body. */ +export interface DashScopeVideoRetalkRequest { + model: string; + input: { + video_url: string; + audio_url: string; + ref_image_url?: string; + }; + parameters?: { + video_extension?: boolean; + query_face_threshold?: number; + }; +} + +/** Video style transform (bl video style) request body. */ +export interface DashScopeVideoStyleTransformRequest { + model: string; + input: { + video_url: string; + }; + parameters?: { + style?: number; + video_fps?: number; + animate_emotion?: boolean; + min_len?: number; + use_SR?: boolean; + }; +} + // ---- Application (Agent / Workflow) ---- export interface AppCompletionRequest { @@ -962,7 +991,16 @@ export interface QwenMtUniOutputData { export interface DashScopeTaskResponse { output: { task_id: string; - task_status: "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "UNKNOWN" | "CANCELED"; + task_status: + | "PENDING" + | "RUNNING" + | "SUCCEEDED" + | "FAILED" + | "UNKNOWN" + | "CANCELED" + | "PRE-PROCESSING" + | "POST-PROCESSING" + | "SUSPENDED"; finished?: boolean; task_metrics?: { TOTAL?: number; @@ -981,6 +1019,8 @@ export interface DashScopeTaskResponse { results?: Array<{ url: string }>; // Video generation returns video_url video_url?: string; + // video-style-transform returns output_video_url + output_video_url?: string; // Image translation (qwen-mt-image) returns image_url image_url?: string; // qwen-mt-uni business envelope (exact casing) diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 316b7d9c..f223a6cd 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -68,6 +68,8 @@ export type { DashScopeVideoEditRequest, DashScopeVideoRefRequest, DashScopeVideoRequest, + DashScopeVideoRetalkRequest, + DashScopeVideoStyleTransformRequest, KnowledgeChatContentPart, KnowledgeChatMessage, KnowledgeChatRequest, diff --git a/packages/runtime/src/utils/polling.ts b/packages/runtime/src/utils/polling.ts index ef802e88..4a71d9c8 100644 --- a/packages/runtime/src/utils/polling.ts +++ b/packages/runtime/src/utils/polling.ts @@ -45,7 +45,10 @@ export async function poll(client: Client, opts: PollOptions): Promise { ); } - await new Promise((resolve) => setTimeout(resolve, opts.intervalSec * 1000)); + const remainingMs = deadline - Date.now(); + if (remainingMs <= 0) break; + const sleepMs = Math.min(opts.intervalSec * 1000, remainingMs); + await new Promise((resolve) => setTimeout(resolve, sleepMs)); } throw new BailianError( diff --git a/skills/bailian-gen/SKILL.md b/skills/bailian-gen/SKILL.md index 79b5ab10..cebfaceb 100644 --- a/skills/bailian-gen/SKILL.md +++ b/skills/bailian-gen/SKILL.md @@ -43,7 +43,9 @@ BAILIAN_CALLER_TYPE=agent BAILIAN_CALLER_NAME=codex BAILIAN_SKILL_NAME=bailian-g | Image text translation (layout-preserving) | `bl image translate` | Default `qwen-mt-image` (async); optional `qwen-mt-image-2.0`. Not image edit. | | File multimodal translation | `bl omni translate` | `qwen-mt-uni` (async file→file). Keep `bl omni --message` for multimodal chat. | | Text-to-video / image-to-video | `bl video generate` | `wan3.0-video` | -| Video edit / style transfer | `bl video edit` | `happyhorse-1.0-video-edit` | +| Video edit (happyhorse) | `bl video edit` | `happyhorse-1.0-video-edit` — prompt-based edit; preset comic/ink restyle → `bl video style` | +| Talking-head / lip sync | `bl video retalk` | Fixed `videoretalk` (no `--model`; Beijing only) | +| Video style transform | `bl video style` | Fixed `video-style-transform` (Beijing; public URL only in v1; 8 preset styles) | | Reference-to-video + voice | `bl video ref` | `wan3.0-video` | | Speech synthesis (TTS / voiceover) | `bl speech synthesize` | `cosyvoice-v3-flash` | | Voice clone / manage | `bl speech voice clone/list/get/update/delete/preview` | CosyVoice/Qwen-Audio: `voice-enrollment` → `speech synthesize --model`. Omni (non-realtime flash/plus only): `qwen-voice-enrollment` create/list/delete → `omni --model --voice` | @@ -53,6 +55,8 @@ BAILIAN_CALLER_TYPE=agent BAILIAN_CALLER_NAME=codex BAILIAN_SKILL_NAME=bailian-g | Image describe | `bl vision describe` | `qwen3-vl-plus`;宿主能做且未点名 → host-first | | Video / A-V understand | `bl vision describe --video` 或 `bl omni` | 视频理解默认走百炼;`omni` 默认 `qwen3.8-omni-flash`,省略 `--model` 且无 `--text-only` 时自动切换 `qwen3.5-omni-plus` | +`bl video edit` vs `bl video style`: edit uses happyhorse for prompt-based style/object edits; style applies one of 8 preset comic/ink transforms (`video-style-transform`). `bl video retalk` is audio-driven lip-sync (videoretalk). Style outputs are silent MP4. Retalk and style are Beijing-only and do not expose `--model`. + Unless the user explicitly specifies a model, omit `--model` and let the CLI use the active Profile’s default. For ASR model selection, keep `fun-asr` (or other `*-filetrans`) for long recordings, repeated files, speaker diarization, or asynchronous task IDs. For one local or remote audio file up to about five minutes when the user asks for low-latency Flash models, use `--model fun-asr-flash-2026-06-15`, `--model qwen-audio-3.0-asr-flash`, or `--model qwen3-asr-flash`. Flash recognition is synchronous and accepts exactly one file per call. diff --git a/skills/bailian-gen/reference/index.md b/skills/bailian-gen/reference/index.md index 85758739..89c0b437 100644 --- a/skills/bailian-gen/reference/index.md +++ b/skills/bailian-gen/reference/index.md @@ -9,34 +9,36 @@ Use this index for the skill-scoped quick index and global flags. ## Quick index -| Command | Authentication | Description | Detail | -| ----------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------- | ---------------------- | -| `bl image edit` | API Key | Edit an existing image with text instructions (Qwen-Image / Wan 2.7) | [image.md](image.md) | -| `bl image generate` | API Key | Generate images (Qwen-Image / wan2.x) | [image.md](image.md) | -| `bl image translate` | API Key | Translate text in an image (Qwen-MT-Image) | [image.md](image.md) | -| `bl omni` | API Key | Multimodal chat with text + audio output (Qwen-Omni) | [omni.md](omni.md) | -| `bl omni translate` | API Key | Translate a document, image or audio file (Qwen-MT-Uni) | [omni.md](omni.md) | -| `bl speech generate` | API Key | Generate podcast/dialogue audio content from a text prompt | [speech.md](speech.md) | -| `bl speech recognize` | API Key | Recognize speech from audio files (FunAudio-ASR / Qwen-ASR Flash) | [speech.md](speech.md) | -| `bl speech synthesize` | API Key | Synthesize speech from text | [speech.md](speech.md) | -| `bl speech vocabulary create` | API Key | Create a precompiled hot-word vocabulary for ASR | [speech.md](speech.md) | -| `bl speech vocabulary delete` | API Key | Delete a precompiled hot-word vocabulary | [speech.md](speech.md) | -| `bl speech vocabulary get` | API Key | Get details of a precompiled hot-word vocabulary | [speech.md](speech.md) | -| `bl speech vocabulary list` | API Key | List precompiled hot-word vocabularies | [speech.md](speech.md) | -| `bl speech vocabulary update` | API Key | Replace the contents of a precompiled hot-word vocabulary | [speech.md](speech.md) | -| `bl speech voice clone` | API Key | Clone a custom voice from reference audio | [speech.md](speech.md) | -| `bl speech voice delete` | API Key | Delete a custom voice | [speech.md](speech.md) | -| `bl speech voice design` | API Key | Design a custom voice from a text description | [speech.md](speech.md) | -| `bl speech voice get` | API Key | Get details of a custom voice | [speech.md](speech.md) | -| `bl speech voice list` | API Key | List custom voices | [speech.md](speech.md) | -| `bl speech voice preview` | API Key | Fetch the reference audio URL for a cloned voice | [speech.md](speech.md) | -| `bl speech voice update` | API Key | Update the reference audio of a cloned voice | [speech.md](speech.md) | -| `bl video download` | API Key | Download a completed video by task ID | [video.md](video.md) | -| `bl video edit` | API Key | Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.) | [video.md](video.md) | -| `bl video generate` | API Key | Generate a video from text or image (wan3.0-video / wan2.6-t2v / happyhorse-1.1-i2v) | [video.md](video.md) | -| `bl video ref` | API Key | Reference-to-video generation (wan3.0-video / happyhorse-1.1-r2v / wan2.6-r2v): multi-subject, multi-shot with voice | [video.md](video.md) | -| `bl video task get` | API Key | Query async task status | [video.md](video.md) | -| `bl vision describe` | API Key | Describe an image or video using Qwen-VL | [vision.md](vision.md) | +| Command | Authentication | Description | Detail | +| ----------------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------- | ---------------------- | +| `bl image edit` | API Key | Edit an existing image with text instructions (Qwen-Image / Wan 2.7) | [image.md](image.md) | +| `bl image generate` | API Key | Generate images (Qwen-Image / wan2.x) | [image.md](image.md) | +| `bl image translate` | API Key | Translate text in an image (Qwen-MT-Image) | [image.md](image.md) | +| `bl omni` | API Key | Multimodal chat with text + audio output (Qwen-Omni) | [omni.md](omni.md) | +| `bl omni translate` | API Key | Translate a document, image or audio file (Qwen-MT-Uni) | [omni.md](omni.md) | +| `bl speech generate` | API Key | Generate podcast/dialogue audio content from a text prompt | [speech.md](speech.md) | +| `bl speech recognize` | API Key | Recognize speech from audio files (FunAudio-ASR / Qwen-ASR Flash) | [speech.md](speech.md) | +| `bl speech synthesize` | API Key | Synthesize speech from text | [speech.md](speech.md) | +| `bl speech vocabulary create` | API Key | Create a precompiled hot-word vocabulary for ASR | [speech.md](speech.md) | +| `bl speech vocabulary delete` | API Key | Delete a precompiled hot-word vocabulary | [speech.md](speech.md) | +| `bl speech vocabulary get` | API Key | Get details of a precompiled hot-word vocabulary | [speech.md](speech.md) | +| `bl speech vocabulary list` | API Key | List precompiled hot-word vocabularies | [speech.md](speech.md) | +| `bl speech vocabulary update` | API Key | Replace the contents of a precompiled hot-word vocabulary | [speech.md](speech.md) | +| `bl speech voice clone` | API Key | Clone a custom voice from reference audio | [speech.md](speech.md) | +| `bl speech voice delete` | API Key | Delete a custom voice | [speech.md](speech.md) | +| `bl speech voice design` | API Key | Design a custom voice from a text description | [speech.md](speech.md) | +| `bl speech voice get` | API Key | Get details of a custom voice | [speech.md](speech.md) | +| `bl speech voice list` | API Key | List custom voices | [speech.md](speech.md) | +| `bl speech voice preview` | API Key | Fetch the reference audio URL for a cloned voice | [speech.md](speech.md) | +| `bl speech voice update` | API Key | Update the reference audio of a cloned voice | [speech.md](speech.md) | +| `bl video download` | API Key | Download a completed video by task ID | [video.md](video.md) | +| `bl video edit` | API Key | Edit a video with happyhorse-1.0-video-edit (prompt-based style/object edits; preset comic/ink restyle → video style) | [video.md](video.md) | +| `bl video generate` | API Key | Generate a video from text or image (wan3.0-video / wan2.6-t2v / happyhorse-1.1-i2v) | [video.md](video.md) | +| `bl video ref` | API Key | Reference-to-video generation (wan3.0-video / happyhorse-1.1-r2v / wan2.6-r2v): multi-subject, multi-shot with voice | [video.md](video.md) | +| `bl video retalk` | API Key | Drive a talking-head video with audio (VideoRetalk) | [video.md](video.md) | +| `bl video style` | API Key | Restyle a video with 8 presets (video-style-transform); for prompt-based edit use video edit | [video.md](video.md) | +| `bl video task get` | API Key | Query async task status | [video.md](video.md) | +| `bl vision describe` | API Key | Describe an image or video using Qwen-VL | [vision.md](vision.md) | ## By group @@ -45,7 +47,7 @@ Use this index for the skill-scoped quick index and global flags. | `image` | `edit`, `generate`, `translate` | [image.md](image.md) | | `omni` | `(root)`, `translate` | [omni.md](omni.md) | | `speech` | `generate`, `recognize`, `synthesize`, `vocabulary create`, `vocabulary delete`, `vocabulary get`, `vocabulary list`, `vocabulary update`, `voice clone`, `voice delete`, `voice design`, `voice get`, `voice list`, `voice preview`, `voice update` | [speech.md](speech.md) | -| `video` | `download`, `edit`, `generate`, `ref`, `task get` | [video.md](video.md) | +| `video` | `download`, `edit`, `generate`, `ref`, `retalk`, `style`, `task get` | [video.md](video.md) | | `vision` | `describe` | [vision.md](vision.md) | ## Global flags diff --git a/skills/bailian-gen/reference/video.md b/skills/bailian-gen/reference/video.md index 6ea7e423..803ced10 100644 --- a/skills/bailian-gen/reference/video.md +++ b/skills/bailian-gen/reference/video.md @@ -7,13 +7,15 @@ Index: [index.md](index.md) ## Commands in this group -| Command | Authentication | Description | -| ------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------- | -| `bl video download` | API Key | Download a completed video by task ID | -| `bl video edit` | API Key | Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.) | -| `bl video generate` | API Key | Generate a video from text or image (wan3.0-video / wan2.6-t2v / happyhorse-1.1-i2v) | -| `bl video ref` | API Key | Reference-to-video generation (wan3.0-video / happyhorse-1.1-r2v / wan2.6-r2v): multi-subject, multi-shot with voice | -| `bl video task get` | API Key | Query async task status | +| Command | Authentication | Description | +| ------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------- | +| `bl video download` | API Key | Download a completed video by task ID | +| `bl video edit` | API Key | Edit a video with happyhorse-1.0-video-edit (prompt-based style/object edits; preset comic/ink restyle → video style) | +| `bl video generate` | API Key | Generate a video from text or image (wan3.0-video / wan2.6-t2v / happyhorse-1.1-i2v) | +| `bl video ref` | API Key | Reference-to-video generation (wan3.0-video / happyhorse-1.1-r2v / wan2.6-r2v): multi-subject, multi-shot with voice | +| `bl video retalk` | API Key | Drive a talking-head video with audio (VideoRetalk) | +| `bl video style` | API Key | Restyle a video with 8 presets (video-style-transform); for prompt-based edit use video edit | +| `bl video task get` | API Key | Query async task status | ## Command details @@ -47,12 +49,12 @@ bl video download --task-id 3b256896-xxxx --out video.mp4 --quiet ### `bl video edit` -| Field | Value | -| ------------------ | -------------------------------------------------------------------------------------- | -| **Name** | `video edit` | -| **Description** | Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.) | -| **Authentication** | API Key | -| **Usage** | `bl video edit --video --prompt [flags]` | +| Field | Value | +| ------------------ | --------------------------------------------------------------------------------------------------------------------- | +| **Name** | `video edit` | +| **Description** | Edit a video with happyhorse-1.0-video-edit (prompt-based style/object edits; preset comic/ink restyle → video style) | +| **Authentication** | API Key | +| **Usage** | `bl video edit --video --prompt [flags]` | #### Flags @@ -215,6 +217,83 @@ bl video ref --prompt "Image 1 and Image 2 have a conversation" --image a.jpg -- bl video ref --prompt "Image 1 drinks water" --image person.jpg --watermark false ``` +### `bl video retalk` + +| Field | Value | +| ------------------ | --------------------------------------------------------------------- | +| **Name** | `video retalk` | +| **Description** | Drive a talking-head video with audio (VideoRetalk) | +| **Authentication** | API Key | +| **Usage** | `bl video retalk --video --audio [flags]` | + +#### Flags + +| Flag | Type | Required | Description | +| --------------------------- | ------- | -------- | ------------------------------------------------------------------------------------------ | +| `--video ` | string | yes | Input video URL or local file (mp4/avi/mov) | +| `--audio ` | string | yes | Driving audio URL or local file (wav/mp3/aac) | +| `--ref-image ` | string | no | Optional reference face image when the video has multiple people | +| `--video-extension ` | boolean | no | Extend video by alternating reverse/forward playback when audio is longer (default: false) | +| `--face-threshold ` | number | no | Face match threshold 120–200 (default: 170; only with --ref-image) | +| `--download ` | string | no | Save video to this file on completion (default: /videos/.mp4) | +| `--async` | switch | no | Return async task id without waiting | +| `--poll-interval ` | number | no | Polling interval when waiting (default: 15) | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Fixed model videoretalk (Beijing only). Wait-mode polling uses at least 600s (--timeout lower values are raised). + +#### Examples + +```bash +bl video retalk --video https://example.com/face.mp4 --audio https://example.com/speech.wav --download out.mp4 +``` + +```bash +bl video retalk --video ./face.mp4 --audio ./speech.wav --ref-image ./person.jpg --face-threshold 170 +``` + +### `bl video style` + +| Field | Value | +| ------------------ | -------------------------------------------------------------------------------------------- | +| **Name** | `video style` | +| **Description** | Restyle a video with 8 presets (video-style-transform); for prompt-based edit use video edit | +| **Authentication** | API Key | +| **Usage** | `bl video style --video [flags]` | + +#### Flags + +| Flag | Type | Required | Description | +| --------------------------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `--video ` | string | yes | Input video public URL (local paths not supported in v1) | +| `--style ` | number | no | Style ID 0–7 (default: 0). 0 Japanese comic, 1 American comic, 2 fresh comic, 3 3D cartoon, 4 Chinese cartoon, 5 paper art, 6 simple illustration, 7 Chinese ink | +| `--fps ` | number | no | Output video FPS 15–25 (default: 15; maps to video_fps) | +| `--animate-emotion ` | boolean | no | Animate facial emotion (server default: true) | +| `--min-len ` | number | no | Short-side length 540 or 720 (server default: 720; 720P costs more than 540P) | +| `--super-resolution ` | boolean | no | Enable super-resolution (maps to use_SR; server default: false; with min_len=540 outputs 1080P billed as 540P) | +| `--download ` | string | no | Save video to this file on completion (default: /videos/.mp4) | +| `--async` | switch | no | Return async task id without waiting | +| `--poll-interval ` | number | no | Polling interval when waiting (default: 15) | +| `--api-key ` | string | no | API key | +| `--base-url ` | string | no | API base URL | + +#### Notes + +- Fixed model video-style-transform (Beijing only). Wait-mode polling uses at least 600s (--timeout lower values are raised). + +#### Examples + +```bash +bl video style --video https://example.com/clip.mp4 --style 0 --download styled.mp4 +``` + +```bash +bl video style --video https://example.com/clip.mp4 --style 4 --fps 15 --min-len 540 --super-resolution true +``` + ### `bl video task get` | Field | Value |