Video Editing (weizhi:video)
Scope
| Do | Do Not |
|---|---|
probe, extract frames/audio tracks, exportVideo export | Decode an entire mp4 with webview_exec |
| v1 remux: trim, concatenate without fading | Pretend to support desktop transcoding (desktop does not have this package) |
Initiation Protocol
- First
load_skill(video-edit) to read this document. - Before writing
exportVideoor a complex timeline:find_capsonce (query includesexportVideo weizhi:videoor a specific capability), and write according to the returned call example; do not guess field names. - Place scripts in
jobs/*.js, execute usingrun_jswithfile;timeout_mscan be increased (max 600000). - If the script API returns an error (such as
bad argument,unsupported):find_capsagain to check the signature and modify the script.
Routing
| Task | API |
|---|---|
| Trim a single segment, concatenate multiple segments end-to-end, no re-encoding | v1 exportVideo({ clips: [{ path, startMs?, endMs? }], output }) |
| Multi-track, image title card, Ken Burns, crossfade | v2 exportVideo({ width, height, tracks, output }) |
Timeline v2 (Key Points)
- Image / photo:
type: "image"track,durationMsis mandatory. - mp4 segment:
type: "video"track,inMs/outMs; do not put images in a video track. - Crossfade (image tracks only): the later clip should have
transition: { type: "crossfade", durationMs: D }, and
startMs_next = startMs_prev + durationMs_prev - D(overlap exactly D milliseconds). There is nocrossfadeMsfield. - Clips on the same track without a declared
transitionmust not overlap in time; an erroroverlapping clipsmeans you should check the above formula andtransition. transitionand self-written opacity keyframes cannot be used simultaneously.- Audio track:
type: "audio"as a separate track.
Example (two images crossfade + then video):
import { exportVideo } from "weizhi:video";
const D = 300;
await exportVideo({
width: 720,
height: 1280,
tracks: [
{
type: "image",
clips: [
{ src: "a.jpg", startMs: 0, durationMs: 1000 },
{
src: "b.jpg",
startMs: 1000 - D,
durationMs: 1000,
transition: { type: "crossfade", durationMs: D },
},
],
},
{
type: "video",
clips: [{ src: "clip.mp4", startMs: 1700, inMs: 0, outMs: 5000 }],
},
],
output: "out/final.mp4",
});
Recommended Workflow
probethe source video for duration and resolution.- If a cover frame is needed:
extractFrame/extractFrames(seefind_caps). - For complex videos: you can first export intermediate
part1.mp4,part2.mp4using v1, then concatenate using v1 or v2; avoid stacking clips without declared transitions on one track. - Background music: a separate
audiotrack,outMsaligned with the total video length.
Scripting
- A single
jobs/render.jsscript should handle probing, export, and verification (you canprobethe final output again) in sequence. - Do not replace the entire script with multiple tools from outside.
How to Communicate with the User
Specify the output file name and duration; use a [Video](out/xxx.mp4) link. Avoid stacking technical terms.