Video
Make and edit MP4 videos on the phone by writing HTML canvas scenes and rendering them with native H.264 encoding.
Mobile Agent can make and edit videos without a video-generation model. The agent writes a self-contained HTML canvas scene, the app plays it frame by frame in a hidden WebView, and a native Android encoder turns those frames into an H.264 MP4 with mixed audio. Everything runs on your phone.
This is powered by the preinstalled html-video skill and the renderVideo tool.
Why this approach
A video-generation model would need to invent every frame, which is slow, expensive, and hard to revise precisely. Mobile Agent instead treats a video as deterministic code:
- The scene is an HTML file you can read, diff, and edit.
- Every frame is drawn by a
render(t, canvas, ctx, audio, speech)function. - Re-rendering after a change produces exactly the new frames, and unchanged shots can be reused.
- Text, charts, diagrams, logos, and user-provided media can appear exactly as intended.
- Audio, narration, and captions are scheduled alongside the visuals.
No GPU video model, no cloud render farm, and no per-second generation cost.
Make a video
Ask for one in plain language:
Make a 10-second animated explainer about how a black hole works.The agent will:
- Load the
html-videoskill. - Write a single HTML document with the video contract.
- Optionally preview the composition with
previewScene. - Call
renderVideowith the finished HTML. - Embed the resulting MP4 in the chat as a playable video card.
Rendering is real time: a 10-second video takes roughly 10 seconds. A video can be up to 600 seconds long; anything over 45 seconds renders in 45-second segments and is concatenated. Do not ask the agent to retry a stalled export automatically — it reports the error and asks first.
The scene contract
The HTML document defines a global object before the body finishes loading:
<script>
window.MOBILE_AGENT_VIDEO = {
duration: 10, // seconds, 1–600
fps: 30, // 5–60, default 30
width: 1280, // even, ≤ 1920
height: 720, // even, ≤ 1920
canvasId: "scene", // optional; otherwise the first visible canvas
render: function (t, canvas, ctx, audio, speech) {
// Draw the frame at time t (seconds).
// Must be deterministic and synchronous.
},
};
</script>The renderer resizes the canvas to the export resolution, calls render once per frame, captures each frame as a JPEG, and hands it to the native MediaCodec encoder. Audio is mixed offline and encoded as AAC.
Shots and incremental edits
For anything with two or more story beats, the scene declares shots:
shots: [
{ id: "intro", start: 0, end: 4, render: function (t, c, ctx, a, s) { /* ... */ } },
{ id: "orbit", start: 4, end: 10, render: function (t, c, ctx, a, s) { /* ... */ } },
]Each shot owns [start, end); the top-level render draws the gaps. Shots are the unit of cache reuse: editing one shot's drawing code re-encodes only the segments containing it, while shared code, assets, clip windows, or the audio schedule invalidate the whole video. Aim for 2–8 meaningful shots, and declare them on the first render.
Audio
Add an audio schedule to include sound:
audio: {
master: 0.9,
tracks: [
{ file: "workspace://<audio-file-id>", start: 0, loop: true, volume: 0.5, fadeOut: 2 },
{ synth: { kind: "pad", notes: ["C3", "G3", "Bb3"], attack: 2 }, start: 0, duration: 12, volume: 0.3 },
],
}- File tracks reference audio already in the workspace (MP3, WAV, M4A, AAC, OGG, WebM, or the audio of an MP4/MOV), streamed over loopback HTTP up to 200 MB.
- Synth tracks generate tones, pads, filtered noise, and drum patterns without any external file.
- Scenes with
<video>clips must explicitly choose a soundtrack schedule oraudio: false. - When editing an existing video, the agent preserves the original soundtrack unless you ask for silence or replacement.
Audio-reactive visuals can use the fourth render argument (audio) for BPM, beats, levels, onsets, and beat pulses. analyzeAudio can inspect a track first and save a reusable analysis result.
Voiceover and captions
The preferred narration path is the on-device textToSpeech tool. It speaks the script with system voices, saves numbered WAV parts, and the agent schedules them as file tracks. listVoices shows installed voices and locales. If a local voice is missing, the agent can fall back to a network TTS endpoint or ask you for an audio file.
For captions, run transcribeAudio on the narration to get word and phrase timings, then pass the segments as speech in the contract. The fifth render argument exposes activeText(t), activeSegment(t), progress, and upcoming segment starts, so captions stay glued to the voice.
Images and clips
Scenes can draw user images with <img src="workspace://<image-file-id>"> (JPEG, PNG, WebP, GIF up to 100 MB) and play muted video clips with <video muted playsinline src="workspace://<video-file-id>"> (MP4, WebM, MOV up to 1 GB), both served from the device. Video clips are driven by scene JavaScript, so the agent controls timing rather than relying on native playback.
Preview and inspect
| Tool | What it does |
|---|---|
previewScene | Renders storyboard timestamps into one contact sheet (up to 12 times) so composition and captions can be checked before a full render. Pass layout: "frames" for full-resolution stills. |
previewMix | Renders a short audio/video mix preview so the soundtrack can be checked before export. |
getVideoFrame | Saves a still from an existing video at one or more timestamps, returning a numbered contact sheet for vision-capable models. |
renderVideo | Records the scene and returns the MP4 workspace file, plus its duration, size, audio status, and warnings. |
A preview is approximate: async media settles, audio doesn't play, and file tracks stay silent. The render is the source of truth.
Scenes saved as HTML can also be opened from the Library in a built-in player with play/pause, seeking, fullscreen, and live soundtrack playback.
Revise a video
When you ask for changes to a rendered video, the agent reads the saved .source.html file instead of regenerating from scratch:
- Edit the exact scene HTML — timings, colors, copy, motion.
- Keep the shot windows and ids stable when possible.
- Re-render with the same promised duration.
- Report which segments were re-encoded versus reused.
The MP4 is baked, so a change is not real until it has been re-rendered. Use getVideoFrame to inspect a specific moment ("at 0:12 the logo clips") when you need to verify what is actually on screen.
Limits and practical notes
- Duration: 1–600 seconds; over 45 seconds renders in segments.
- Resolution: up to 1920×1920, with even width and height.
- Frame rate: 5–60 fps.
- Output: H.264 MP4 with AAC audio, saved to the workspace and playable in chat.
- No video model: visuals are drawn by code, so the scene is only as capable as the HTML/CSS/Canvas code behind it.
- Battery: rendering is CPU/GPU work in real time. Long videos benefit from the battery-optimization exemption described in Scheduler.
- Source retained: every render saves the source HTML, so a later edit never starts from a blank page.
Related tools
renderVideo, previewScene, previewMix, getVideoFrame, analyzeAudio, transcribeAudio, textToSpeech, and listVoices are all built-in tools. Their availability follows the normal per-tool and per-agent permissions — see Built-in Tools and Tool Approvals.