Text to Video Skill
Create a video generation task from text. The job is submitted immediately; Polling to obtain task status and video URL.
When to Use
✅ USE this skill when:
- - "把这段文字生成视频"
- "帮我把这段文案做成视频"
- "用这段文字生成一个视频"
- User provides a script or paragraph and asks to turn it into video
When NOT to Use
❌ DON'T use this skill when:
- - User asks for video editing, trimming, or effects → use video-editing tools
- User asks for screen recording or capture → use recording tools
- User asks only for video status of an existing job → explain where to find files instead
Prerequisites
CODEBLOCK0
INLINECODE0 is required by the remote video service client.
Overall Flow (Agent Guidance)
- 1. Extract the full text from the user's message, denoted as
TEXT (i.e., the script to be used for video generation). - Use the
video-create subcommand to create a task, read the JSON from stdout, and extract the task_id. - Explicitly inform the user of the
task_id in the chat (optionally include the original JSON output for debugging). - Use the
video-wait subcommand with the task_id as --task-id, polling until successful. - 从
video-wait 的 stdout 中提取 video_url. - Explicitly inform the user of the final
video_url in the chat (you may also include the original output).
Python Client (Step-by-step with Chat Output)
Step 1: Create a video task and print the task_id to the chat
- 1. Extract the text the user wants to generate a video from and assign it to
TEXT.
- If the text contains double quotes
", properly escape them before constructing the command (for example, by replacing
" with
\") to avoid shell parsing errors.
- 2. Run the following command (executed by the agent/tool;
{baseDir} will be replaced with the Skill directory):
CODEBLOCK1
- 3. Read the stdout from this command. The expected output will be JSON, for example:
CODEBLOCK2
- 4. Parse the taskid from stdout (e.g., "abc-123"), and inform the user in the chat: "A text-to-video task has been created, taskid: abc-123. I will keep polling for the task status, and send you the video URL once it is ready."
Step 2: Poll the task until success and output video_url in the chat
- 1. Use the taskid obtained in the previous step and refer to it as taskid.
- 2. Run the following command to poll the task status (check every 10 seconds and wait up to 600 seconds); if it times out, wait a while and retry:
CODEBLOCK3
- 3. Read the stdout from this command. When the task succeeds, the script should output information including the video_url, for example:
CODEBLOCK4
- 4. Parse the key fields from stdout:
- - status (e.g., 2)
- video_url (e.g., "https://example.com/path/to/video.mp4")
- 5. In the chat, respond to the user as follows:
- - Optionally (but recommended for debugging), first display the full JSON output inside a code block.
- Then summarize the key information in natural language, for example:
> "Task completed ✅
> task_id: abc-123
> Video URL: https://example.com/path/to/video.mp4"
- 6. If the stdout indicates that the task failed or timed out (for example, if the status is "failed" or there is no video_url):
- - Explain the reason for failure in the chat (include any error message, if available).
- Inform the user that they can retry later, or check their input, quota, etc.
Expected Script Output Contract
- Parse the stdout JSON.
- Clearly communicate the task
id and videourl to the user in the chat.
- If necessary, optionally display the raw JSON output in a code block.
文字转视频技能
从文本创建视频生成任务。任务立即提交;通过轮询获取任务状态和视频URL。
何时使用
✅ 使用此技能的场景:
- - 把这段文字生成视频
- 帮我把这段文案做成视频
- 用这段文字生成一个视频
- 用户提供脚本或段落并要求将其转换为视频
何时不使用
❌ 不要使用此技能的场景:
- - 用户要求视频编辑、剪辑或特效 → 使用视频编辑工具
- 用户要求屏幕录制或截取 → 使用录制工具
- 用户仅查询现有任务的视频状态 → 告知用户如何查找文件
前提条件
bash
export MAGICAPIKEY=your-key
远程视频服务客户端需要 MAGICAPIKEY。
整体流程(智能体指南)
- 1. 从用户消息中提取完整文本,记为 TEXT(即用于生成视频的脚本)。
- 使用 video-create 子命令创建任务,从标准输出读取JSON,提取 taskid。
- 在聊天中明确告知用户 taskid(可选地包含原始JSON输出用于调试)。
- 使用 video-wait 子命令,以 taskid 作为 --task-id 参数,轮询直至成功。
- 从 video-wait 的标准输出中提取 videourl。
- 在聊天中明确告知用户最终的 video_url(也可包含原始输出)。
Python客户端(分步操作及聊天输出)
步骤1:创建视频任务并将task_id输出到聊天
- 1. 提取用户想要生成视频的文本,赋值给 TEXT。
- 如果文本包含双引号 ,在构建命令前需正确转义(例如,将 替换为 \),以避免shell解析错误。
- 2. 运行以下命令(由智能体/工具执行;{baseDir} 将被替换为技能目录):
bash
python3 {baseDir}/scripts/mediagenclient.py video-create \
--text TEXT
- 3. 读取此命令的标准输出。预期输出为JSON格式,例如:
json
{
biz_code: 10000,
msg: Success,
data: {
task_id: 2032443088023777280
},
trace_id: 664c6e22-1edd-11f1-bf4c-8262dce7d13f
}
- 4. 从标准输出中解析taskid(例如abc-123),并在聊天中告知用户:已创建文字转视频任务,taskid: abc-123。我将持续轮询任务状态,待视频就绪后发送视频URL给您。
步骤2:轮询任务直至成功,并将video_url输出到聊天
- 1. 使用上一步获取的taskid,记为taskid。
- 2. 运行以下命令轮询任务状态(每10秒检查一次,最多等待600秒);如果超时,稍等片刻后重试:
bash
python3 {baseDir}/scripts/media
genclient.py video-wait --task-id YOUR
TASKID --poll 10 --timeout 600
- 3. 读取此命令的标准输出。任务成功时,脚本应输出包含video_url的信息,例如:
json
{
biz_code: 10000,
msg: Success,
data: {
task_id: 1234567890,
task_status: 2,
video_url: https://www.magiclight.com/examplevideo.mp4
},
trace_id: c89aeca8-1edd-11f1-bf4c-8262dce7d13f
}
- 4. 从标准输出中解析关键字段:
- - status(例如2)
- video_url(例如https://example.com/path/to/video.mp4)
- 5. 在聊天中回复用户如下:
- - 可选(但建议用于调试),首先在代码块中显示完整JSON输出。
- 然后用自然语言总结关键信息,例如:
> 任务已完成 ✅
> task_id: abc-123
> 视频URL: https://example.com/path/to/video.mp4
- 6. 如果标准输出显示任务失败或超时(例如,状态为failed或没有video_url):
- - 在聊天中解释失败原因(如有错误信息,一并提供)。
- 告知用户可以稍后重试,或检查输入、配额等。
预期脚本输出约定
- 解析标准输出的JSON。
- 在聊天中清晰地向用户传达task
id和videourl。
- 如有必要,可选择在代码块中显示原始JSON输出。