Free tool · runs in your browser · nothing uploaded
Scroll-video encoder
Turn a video into an MP4 where every frame is a keyframe, so it seeks smoothly when scrolling drives the playhead. Then copy the code for a pinned scroll-scrub hero.
1. Your video
Your video stays on your device. It is read and encoded by this browser tab and is never uploaded.
Checking what this browser can encode…
Starting…
3. Your scroll-ready files
Scrub with a slider
Drag to seek. The readout shows how long each seek takes.
Move to seek.
Scrub with scroll
Scroll inside the box, the same way your page will drive it.
scroll ↓
Scroll to seek.
Mobile cut
720 × 1280. Use it with the <source media> line in the code below.
Copy-paste code
A pinned hero that scrubs your video with scroll. It shows the poster first, keeps one seek in flight and always jumps to the latest scroll position, swaps in the mobile cut on portrait phones, and shows the poster as a still for people who prefer reduced motion. The file names match the downloads above.
<!-- Scroll-scrubbed hero. Files from the encoder: hero-scroll.mp4, hero-scroll-mobile.mp4, hero-poster.webp -->
<section class="scrub" id="scrub" aria-label="Product film, controlled by scrolling">
<div class="scrub-pin">
<video class="scrub-video" muted playsinline preload="auto" poster="hero-poster.webp" aria-hidden="true">
<source src="hero-scroll-mobile.mp4" type="video/mp4" media="(max-width: 700px) and (orientation: portrait)">
<source src="hero-scroll.mp4" type="video/mp4">
</video>
<div class="scrub-copy"><h1>Your headline</h1><p>Scroll to move through the film.</p></div>
</div>
</section>
<style>
.scrub { position: relative; height: 400vh; } /* taller = slower scrub */
.scrub-pin { position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden; background: #000; }
.scrub-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scrub-copy { position: absolute; left: 0; right: 0; bottom: 10vh; text-align: center; color: #fff; padding: 0 16px; }
@media (prefers-reduced-motion: reduce) {
.scrub { height: auto; }
.scrub-pin { position: relative; }
}
</style>
<script>
(() => {
const section = document.getElementById("scrub");
const video = section.querySelector("video");
// Reduced motion: drop the video sources and keep the poster as a still image.
if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
video.querySelectorAll("source").forEach(s => s.remove());
video.load();
return;
}
let target = 0, seeking = false, ready = false, primed = false;
// Scroll progress through the section, 0 at the top and 1 at the end.
const progress = () => {
const r = section.getBoundingClientRect();
const range = section.offsetHeight - innerHeight;
return range > 0 ? Math.min(1, Math.max(0, -r.top / range)) : 0;
};
// One seek in flight. While it runs, only the latest target is kept.
const seek = () => {
if (!ready || seeking) return;
if (Math.abs(video.currentTime - target) < 0.01) return;
seeking = true;
video.currentTime = target;
};
video.addEventListener("seeked", () => { seeking = false; seek(); });
let raf = 0;
const onScroll = () => {
if (raf) return;
raf = requestAnimationFrame(() => {
raf = 0;
if (ready) target = progress() * Math.max(0, video.duration - 0.05);
seek();
});
};
// iOS Safari only paints frames from seeks after the video has started once.
const prime = () => {
if (primed) return;
primed = true;
const p = video.play();
if (p) p.then(() => video.pause()).catch(() => {});
};
video.addEventListener("loadedmetadata", () => { ready = true; onScroll(); });
if (video.readyState >= 1) ready = true;
addEventListener("scroll", onScroll, { passive: true });
addEventListener("resize", onScroll);
addEventListener("touchstart", prime, { once: true, passive: true });
addEventListener("pointerdown", prime, { once: true });
onScroll();
})();
</script>Build a pinned, scroll-scrubbed hero section for my site in plain HTML, CSS and JavaScript (no libraries).
Files (all in the same folder as the page):
- hero-scroll.mp4: H.264, every frame is a keyframe, so it seeks fast. Desktop source.
- hero-scroll-mobile.mp4: 720x1280 portrait cut of the same footage. Mobile source.
- hero-poster.webp: the first frame, used as the poster.
Behaviour:
1. A section 400vh tall with a sticky inner block (100svh) that pins the video full-bleed (object-fit: cover) while the reader scrolls through it.
2. Map scroll progress through the section (0 to 1) to video.currentTime (0 to duration). Read the scroll in a requestAnimationFrame callback.
3. Keep only one seek in flight: set currentTime, wait for the 'seeked' event, then jump to the latest target. Never queue every scroll position.
4. Show the poster until the video has data. Use <source media="(max-width: 700px) and (orientation: portrait)"> to pick the mobile file.
5. With prefers-reduced-motion: reduce, remove the video sources, show the poster as a still and let the section scroll normally.
6. On iOS, call play() then pause() once on the first touch so seeks paint.
7. Overlay my copy on the video: [HEADLINE], [SUBHEAD] and a [BUTTON LABEL] linking to [URL]. Fade the headline out between 0% and 20% progress and fade a second line, [SECOND LINE], in between 60% and 80%.
8. Make it accessible: the video is decorative (aria-hidden), the text is real HTML with enough contrast over the footage (add a subtle gradient), and the page works with JavaScript off (poster plus text).
Style: [describe your fonts, colours and mood]. Give me one complete HTML file.Templates that use scroll-driven video and 3D
Free templates with this kind of scroll-controlled hero, each with the full prompt and code.
What scroll-scrubbed video is
A scroll-scrubbed video doesn’t play on its own. The page pins it in place while you scroll through a tall section, and a few lines of JavaScript turn the scroll position into a time: the top of the section is the first frame and the bottom is the last. Scroll down and the footage moves forward; scroll up and it runs backwards. Product pages use it to let the reader drive a camera move, an exploded view or a slow reveal. Under the hood it is one property, video.currentTime, set again and again as the reader scrolls.
Why all-intra (GOP 1) makes seeking smooth
Normal web video is encoded for playing straight through. An H.264 file stores a complete picture, a keyframe, every few seconds, and in between it stores frames that only describe what changed. A keyframe and the frames that depend on it form a group of pictures, or GOP. To show frame 140 of a clip with a keyframe every 250 frames, the browser has to go back to the keyframe and decode every frame up to 140. During playback that work is spread out. During a seek it all happens at once, and scrolling asks for many seeks a second.
An all-intra file has a GOP of one: every frame is a keyframe, so any frame can be decoded on its own. A seek costs one frame of decoding instead of dozens, which is why the test player above keeps up in both directions. Scrolling backwards is where long GOPs hurt most, because each step back means decoding forward again from an earlier keyframe.
The trade-off: file size
Keyframes are expensive. In-between frames reuse most of the previous picture, which is why a normal MP4 is compact; an all-intra file has to store every picture in full. Expect it to be roughly 3 to 10 times larger than the same clip encoded for playback, depending on motion and detail. The tool shows the real size next to your input.
Four settings control the size: length, width, frame rate and quality. Length matters most. A scroll hero rarely needs more than 4 to 10 seconds of footage, because the reader sets the pace and a 400vh section only gives them a few screens of scrolling. Halving the frame rate halves the file, and dropping from 1920 to 1280 wide cuts it by more than half.
Recommended settings
- Width: 1280 for most heroes. Use 1920 only for full-bleed footage with fine detail, and 960 for background video under text.
- Frame rate: 24 or 30 fps. Scrolling rarely shows more distinct frames than that, and 60 fps doubles the file.
- Length: 4 to 10 seconds. Trim to the part the reader scrolls through.
- Quality: 60 to 75 for most footage. Go lower for dark or soft footage, higher for text, thin lines and product close-ups.
- Audio: strip it. A scrubbed video is muted, and phones only load muted video without a tap.
- Size target: under about 15 MB for desktop and 6 MB for the mobile cut.
How to use it in your page
- Encode your clip above and download the MP4, the mobile MP4 if you made one, and the poster.
- Put the files next to your page, or in a media folder and update the paths.
- Paste the HTML, CSS and JS from Copy-paste code. The section is 400vh tall and the inner block is sticky, so the video stays pinned while you scroll through it. Make the section taller for a slower scrub.
- Host the files somewhere that supports HTTP range requests. Cloudflare, Netlify, Vercel, GitHub Pages and most CDNs do. Safari can’t seek a video served without them.
- Test in Chrome, Safari and Firefox. Scroll fast in both directions. If it stutters, lower the width or frame rate first.
The script keeps only one seek in flight. When the reader scrolls faster than the decoder, it doesn’t queue every position; it remembers the latest target and jumps there as soon as the current seek finishes. That keeps the picture in step with the scrollbar instead of trailing behind it.
Mobile tips
- A landscape video centre-cropped on a portrait phone loses most of the frame. Make the mobile cut and drag the crop box to keep the subject in view.
<source media>picks the mobile file when the page loads. Current Chrome, Firefox and Safari support it; for older browsers, choose the file in JavaScript withmatchMediabefore settingsrc.- Use
100svhfor the pinned block so the browser’s address bar doesn’t resize the video while scrolling. - iOS Safari paints seeked frames only after the video has started once, so the code calls
play()thenpause()on the first touch. - Keep the mobile file small: 720 wide, 24 fps and 4 to 6 seconds is usually 3 to 6 MB.
- Respect reduced motion. The code shows the poster as a still instead.
The same encode with ffmpeg
If you prefer the terminal, this produces the same kind of file. -g 1 sets the GOP to one frame, -keyint_min 1 and -sc_threshold 0 stop the encoder from changing that, -movflags +faststart moves the index to the start of the file, and -an drops the audio.
ffmpeg -ss 0 -t 8 -i input.mov -vf "fps=30,scale=1280:-2" \
-c:v libx264 -preset slow -crf 23 \
-g 1 -keyint_min 1 -sc_threshold 0 \
-pix_fmt yuv420p -movflags +faststart -an hero-scroll.mp4
The mobile cut, centre-cropped to 9:16:
ffmpeg -ss 0 -t 8 -i input.mov -vf "fps=30,crop=ih*9/16:ih,scale=720:1280" \
-c:v libx264 -preset slow -crf 25 -g 1 -keyint_min 1 -sc_threshold 0 \
-pix_fmt yuv420p -movflags +faststart -an hero-scroll-mobile.mp4
To check that every frame is a keyframe, count the key flags. A single line ending in 1 means they all are:
ffprobe -v error -select_streams v -show_entries frame=key_frame -of csv=p=0 hero-scroll.mp4 | sort | uniq -c
How this tool works
The browser reads your file with its own video decoder. The tool steps a hidden video to the middle of each output frame, waits until that frame is ready, draws it at the output size and hands it to the WebCodecs H.264 encoder with a keyframe flag. A small MP4 library writes the file with the index at the start. Stepping frame by frame is slower than streaming decode, but it lands on the exact frame every time, reads MP4, MOV and WebM the same way, and turns variable frame rate phone footage into a steady frame rate.
If your browser can’t encode H.264 with WebCodecs, the tool loads ffmpeg.wasm and runs x264 with the settings above. Both run entirely in the tab, and the result table checks the finished file: how many frames are keyframes and whether the index comes first.
FAQ
Is my video uploaded?
No. The file is read and encoded by your own browser and never leaves your device. The page only downloads its own code, a small MP4 library and, if your browser needs it, ffmpeg.wasm, all from public CDNs. There is no server that receives your video.
Which browsers does it work in?
The tool checks when the page loads and tells you which engine it will use. Recent Chrome and Edge, and Safari 16.4 or later, have the WebCodecs H.264 encoder and use the fast path. Browsers without it, including some Firefox and Linux setups, use ffmpeg.wasm instead, which works but is several times slower.
Why is the output bigger than my input?
Your input stores one full picture every few seconds and only changes in between. The output stores every frame as a full picture so any frame can be shown instantly. Expect it to be about 3 to 10 times larger at the same width. Trim the clip and lower the width or frame rate to bring it down.
How long can the video be?
Short clips work best: 4 to 12 seconds covers almost every scroll hero. The tool warns above 60 seconds or with a 4K source, because the finished file is assembled in memory and a browser tab has a limit, especially on phones.
Why does scrubbing still stutter on my site?
Check three things: the file is served with range requests (most hosts do this), the width is no larger than you need (1280 is enough for most heroes), and your script keeps only one seek in flight. The code on this page does all three.
Can I use the output for commercial projects?
Yes. The tool is free, the output is your own video, and the code snippet is free to use on any site without credit.