August 25th, 2024

Can you convert a video to pure CSS?

The article explores converting video content into CSS animations, highlighting browser compatibility issues, particularly with Safari, and suggesting JavaScript alternatives for cross-browser functionality while detailing performance differences.

Read original articleLink Icon
Can you convert a video to pure CSS?

The article discusses the possibility of converting video content into pure CSS animations, focusing on the use of CSS scroll animations and the limitations of browser compatibility, particularly with Safari. It introduces the concept of using CSS properties like `scroll-timeline-name` and `animation-timeline` to create animations based on scroll position. However, due to Safari's lack of support for these features, the author suggests an alternative method that involves using JavaScript to set CSS variables based on scroll position, allowing for cross-browser compatibility. The article also explores the idea of animating divs based on pixel data extracted from video frames. It details a process for capturing pixel data from a video using a canvas element, generating CSS keyframes for each pixel, and positioning these divs to create a visual representation of the video. The author notes performance differences between browsers, highlighting that Safari handles larger CSS strings and more animated divs more efficiently than Chrome. The article concludes with examples of the animations created, emphasizing the challenges and potential of using CSS for video representation.

- CSS scroll animations can be created using new properties, but Safari lacks support for them.

- An alternative method using JavaScript to set CSS variables allows for cross-browser compatibility.

- The process of converting video frames into pixel data can be achieved using a canvas element.

- Performance varies significantly between browsers, with Safari outperforming Chrome in handling CSS animations.

- The article showcases the potential of CSS animations for video representation, despite technical challenges.

Link Icon 8 comments
By @vladde - 5 months
Hillarious! Soon enough people will rebuild entire browsers with box shadows :)
By @morjom - 5 months
Title reminded me of this video (although not exactly the same thing as in the article):

https://youtu.be/MQbjW2VfaHs?si=FK92sb8DYSQt5sVO

By @snalty - 5 months
The first demo doesn't work for me in Firefox, either.
By @torrefatto - 5 months
I was going to rant something about open standards and how they did not care to test this toy on Firefox (but they did it test it on safari), but I grew tired.
By @Inviz - 5 months
Animating timeline via css variable causes restyle cascade for all descendant elements. Maybe it is fine for shallow structure but generally it’s much more performant to change transformation directly. Of course that makes it less convenient as computation would have to be duplicated in js
By @h1fra - 5 months
Impressive! Uploaded a 32mb video, played a few frames and immediately crashed my tab, honestly, that's also impressive, chrome rarely crash like this :D

NB: using scroll to play video frame by frame is nice but on macos you can hide the scrollbar which makes it not very obvious that you can do that

By @lagniappe - 5 months
CSS will continue to gain more function until it subsumes JS
By @krick - 5 months
Waiting for "Bad apple" as a pure CSS.