正在加载视频...

视频加载失败

I've done so many scrubbed video sequences on scroll over the years, that I thought it would be helpful to share some pro tips in this thread:

70,216 次观看 • 2 年前 •via X (Twitter)

10 条评论

Josh Kirk 的头像
Josh Kirk2 年前

Generally the process looks like this: 1. Get your source video at 1.2-1.5x the width where it will be used, compress using a tool like 2. Use ffmpeg to cut the video into frames. Make sure to have a different frame set for desktop and mobile.

Josh Kirk 的头像
Josh Kirk2 年前

3. Do whatever you can do decrease the frame file size. If you have some frames that don't require transparency, they should be jpeg/webp. 4. Load said frames as blob images using a javascript webworker (see image) which moves the fetching and decoding off the main thread.

Josh Kirk 的头像
Josh Kirk2 年前

5. Once you have all your images back from the worker, draw the first frame to your canvas and watch for the section to be in view. 6. While in view, determine the percentage of the animation you've scrolled through, making sure to not draw the same frame twice in a row.

Josh Kirk 的头像
Josh Kirk2 年前

And that's pretty much it in terms of implementation. But it's worth mentioning that there are some optimizations that can happen before even getting to development. For example, consider advising your art directors to prioritize:

Josh Kirk 的头像
Josh Kirk2 年前

1. Shots with simple color palettes, avoiding complex image data. A mostly-black frame will be significantly smaller than a frame from a video with grass and leaves.

Josh Kirk 的头像
Josh Kirk2 年前

1a. Sequences that focus on the main subject.. Try to remove all background objects & scenery (replace with a solid color) 2. Smooth movements that can be cleanly expressed with lower framerates. Lots of fast movements/cuts require framerates that are hard to tie to scroll.

mitch. 的头像
mitch.2 年前

This is great! A video tutorial would be awesome, do you have one?

Meris 的头像
Meris2 年前

Nice tips, it comes down to loading speed and every small detail is important

Thom Aufresne 的头像
Thom Aufresne2 年前

Very insightful thank you! In your experience, is using a video file an option? I'm often battling weird behaviors/animation getting stuck when scrubbing a video

Terkel Gjervig 的头像
Terkel Gjervig2 年前

Wow, I've implemented this countless times, but I've learned a few tricks from your insights. Thanks for sharing!

相关视频