Finishing a Remotion Video Editor: Timeline Sync, Track Order, Trims and Fades, and the Server MP4 Render
Three prompt rounds turn a first-draft Remotion editor into a usable one: grid/list projects with Delete, a playhead that follows the player, resizable panels, z-index from track numbers, trims and fades, then an export that renders H.264 on the server (65 s the first time, 32 s after). Ends with a full promo made in the finished editor.
What you will learn
- Keep a timeline playhead in sync with a Remotion Player using requestAnimationFrame and seekTo
- Turn track numbers into zIndex so track 1 is always the front layer
- Map fit, scale, trim and audio fades onto Remotion props
- Follow the export route: bundle once, selectComposition, renderMedia to H.264, upload to storage
Before you start
- Remotion basics: Composition, Sequence and Player
- React useEffect and useRef
The first version of the editor could already export a video, but a few things weren't right. This article follows three rounds of fixes, then uses the finished editor from start to end. Every round starts the same way: test the app, write down what's wrong, and ask the agent again.
Round 1: projects page and a playhead that follows
Two problems from the first test. On the projects page there was no way to delete a project, because Delete didn't show in the menu. And the timeline and the viewer weren't connected: the viewer played from the beginning, and the playhead didn't follow.
We took a screenshot of the page and pasted it into the agent with the prompt. A screenshot helps a lot, because the agent sees exactly what you see. Role: a senior front-end developer on a Next.js and Remotion video editor. Context: the projects page and the editor screen, screenshot attached. Task: a grid view and a list view for projects, Delete easy to find in the three-dots menu, and the timeline linked to the viewer so the playhead and picture always show the same moment. Format: audit the whole project, fix what you find, list every change.
Grid or list, remembered
projects-view.tsx keeps one value, view, either grid or list, and saves it in local storage:
const [view, setView] = React.useState<ViewMode>("grid");
// on mount:
const saved = window.localStorage.getItem(STORAGE_KEY);
if (saved === "grid" || saved === "list") setView(saved);
// on click:
setView(next);
window.localStorage.setItem(STORAGE_KEY, next);
The three-dots menu in project-actions-menu.tsx lists Edit, Rename, Duplicate and Delete, with Delete in red. It's now drawn in a fixed position above everything else, so no card can cut it off, and Delete asks first because it can't be undone.
The playhead follows the player
In timeline.tsx, on every screen refresh the timeline asks the player for its current frame and moves the playhead when it changes:
let raf = 0;
let last = -1;
const tick = () => {
const f = playerRef.current?.getCurrentFrame();
if (typeof f === "number" && f !== last) {
last = f;
setCurrentFrame(f);
}
raf = requestAnimationFrame(tick);
};
raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, [playerRef]);
A second effect scrolls the timeline to keep the playhead in view. The other direction still works: drag the playhead and the player seeks.
function beginScrub(e: React.PointerEvent) {
scrubbingRef.current = true;
const frame = frameFromClientX(e.clientX);
playerRef.current?.seekTo(frame);
setCurrentFrame(frame);
}
Fit, scale, trim and fades
With a test project, the image was far too big at first. Every image and video clip has a Fit setting: cover fills the frame and may crop the edges, contain shows the whole picture. Scale makes it smaller or bigger, and X and Y offsets move it. In MainVideo.tsx these become plain styles:
<OffthreadVideo
src={clip.src}
volume={clipVolume(clip)}
startFrom={clip.trimStart}
style={{
width: "100%",
height: "100%",
objectFit: clip.fit,
transform: `translate(${clip.x}%, ${clip.y}%) scale(${clip.scale})`,
}}
/>
Trim start is entered in seconds; one second at 30 fps is 30 frames, and that number goes to Remotion as startFrom, so the clip skips its first part. Mute, Volume, Fade in and Fade out live in the same panel. A fade is a small ramp on the volume:
return (f: number) => {
let v = base;
if (fin > 0) {
v *= interpolate(f, [0, fin], [0, 1], {
extrapolateLeft: "clamp",
extrapolateRight: "clamp",
});
}
if (fout > 0) {
v *= interpolate(f, [clip.durationInFrames - fout, clip.durationInFrames], [1, 0], {
extrapolateLeft: "clamp",
extrapolateRight: "clamp",
});
}
return Math.max(0, Math.min(1, v));
};
Text clips land at the playhead on the first free track, 3 seconds long, fading in, bold white on a transparent background. The properties panel changes the words, animation, size, weight, alignment, colours and offsets, and every change saves straight into the project.
Round 2: room to work
With a few clips in place, the viewer was large and the timeline had little room, and the side panels couldn't be closed. The second prompt: let the user close and open the media panel and the properties panel, and make the viewer smaller or bigger so the timeline gets more room; keep everything else working. While the app runs, the page picks up the new code by itself, so no restart.
In editor.tsx: two top-bar buttons fold the side panels, thin dividers between panels can be dragged within sensible limits, and the divider above the timeline shares space between viewer and timeline. The layout is saved in local storage, and clicking a clip reopens the properties panel by itself.
Round 3: which clip is in front?
The image was on the timeline but invisible in the viewer. Moving clips between tracks changed nothing; the full-screen video still covered it. The third prompt: number the tracks, and treat track 1 as the front layer, so an image on track 1 sits over a full-screen video on track 2; make the preview and the export follow the same order.
The agent's fix, in MainVideo.tsx:
const maxRow = comp.clips.reduce((m, c) => Math.max(m, c.row), 0);
// ...
<ClipRenderer clip={clip} zIndex={maxRow - clip.row + 1} />
It finds the highest row (row 3, the audio track, in the test project). Each clip gets a z-index of highest row minus its own row, plus one. So text on track 1 (row 0) gets 4, the image on track 2 gets 3, the video on track 3 gets 2. The bigger number is drawn in front, so the order no longer depends on which clip was added first. The timeline now numbers every track, with a note that track 1 is the front layer.
Two exports prove it. Text on track 1, image on 2, video on 3: at two seconds, the image and text sit over the video. Move the video to track 1 and the text to track 3: the video fills the frame, and the image and text are hidden behind it. Exactly what the timeline says.
Export: what happens on the server
Export first saves the project, so the server renders the latest version. The window shows "saving your project", then "rendering your video", then "your video is ready" with a preview and a Download MP4 button. The first export took 65 seconds including a headless browser download; the second took 32 seconds.
The render route checks the user is signed in, loads the project, and bundles the Remotion project once per server process:
// Bundling the Remotion project is expensive, so do it once per server process.
let bundlePromise: Promise<string> | null = null;
function getServeUrl(): Promise<string> {
if (!bundlePromise) {
bundlePromise = bundle({
entryPoint: path.join(process.cwd(), "remotion", "index.ts"),
webpackOverride: (config) => config,
});
}
return bundlePromise;
}
After ensureBrowser(), it renders and uploads:
const composition = await selectComposition({
serveUrl,
id: COMPOSITION_ID,
inputProps,
});
await renderMedia({
composition,
serveUrl,
codec: "h264",
outputLocation,
inputProps,
});
// 5. Upload the MP4 to Storage and hand back a public URL.
const fileBuffer = await fs.readFile(outputLocation);
const storagePath = `${user.id}/${projectId}-${Date.now()}.mp4`;
const { error: uploadError } = await admin.storage
.from(RENDERS_BUCKET)
.upload(storagePath, fileBuffer, {
contentType: "video/mp4",
upsert: true,
});
selectComposition reads size, frame rate and length from the project (through calculateMetadata). renderMedia draws every frame and encodes them into H.264. The file goes to the renders bucket under the user's folder, and the route sends its link back. Ours came out at 1080p, 30 fps, 5 seconds, with sound.
The finished editor, start to end
After one more prompt (audio editing for audio clips and the sound of video clips), the lecture makes a short promo in the finished app, Reelix. npm run dev found port 3000 busy and used 3001. Sign out and back in with Google still works, from the starter kit.
- New project "Study Easy Promo", landscape canvas (16:9; portrait is for Reels and Shorts, square for feed posts), Create and edit.
- The starting text clip becomes "Welcome to Study Easy". Add an image (track 2, 3 s), a video (track 3, 6 s) and audio (track 4, 8 s). The project length follows the longest clip: 8 seconds.
- Drag the image below the video and it's hidden; drag it back and it shows. The track order decides what's in front.
- On the video clip, switch Mute on so the music plays and the video stays silent.
- Add "StudyEasy.org" on track 1 from 3 to 6 seconds, with fade in.
The plan: 0 to 3 s, the title in front of the image, video hidden. At 3 s the image and first text end, so the video shows with StudyEasy.org in front. At 6 s the video ends, so the last two seconds are only background, with music for all 8 seconds. The first export took about two minutes (Remotion downloaded a headless browser first), the next about 35 seconds. Preview and export both run on your machine, so speed depends on your hardware. The download showed exactly what we planned.
Common mistakes
- Relying on array order for layers. Use an explicit z-index from the track number.
- Re-bundling Remotion on every export. Cache the bundle promise per process.
- Rendering an unsaved project. Save first, then send the project ID.
- Describing a UI bug only in words. Paste a screenshot with the prompt.
Quick recap
| Fix | Key code |
|---|---|
| Playhead follows player | requestAnimationFrame + getCurrentFrame(); drag calls seekTo |
| Front layer | zIndex = maxRow - row + 1 |
| Trim | startFrom={clip.trimStart} |
| Fades | volume as a function of frame with interpolate |
| Export | bundle once, selectComposition, renderMedia H.264, upload to renders |
Try it yourself
Add a lock button to each track so its clips can't be dragged, or prompt your agent to add it, and then read every line it gives you.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
React State, Events, Lists and Conditional Rendering: Follow One Click
Follow one click through a React counter, render by render: what useState hands back, why a plain variable never updates the page, ternaries and &&, map with keys, and the index-as-key bug that moves a typed note to the wrong task.
React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
Watch useEffect on a timeline with real render counts: the dependency array deciding re-runs, a timer cleanup that keeps one timer alive, the leak StrictMode exposes, and two effects you should delete (a copied total and a click flag).
Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
A task board where the filter is stuck in one component, fixed by lifting it to App. Then useRef as a box React does not watch (three clicks, zero renders), a ref that refocuses an input, and the tree React DevTools shows.
Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
Four versions of an add-task form, traced with real logs: a controlled input, a classic onSubmit, a form action that gets FormData and resets itself, and useActionState with a pending button from useFormStatus, plus the draft trick that keeps typed text after an error.
