Urgent.News

What's breaking now, across thousands of outlets.

Tech

I downscaled a 1080p video to 480x270 to protect its quality

Someone handed my compressor a 1080p clip. It gave back a 480×270 postage stamp. Nothing crashed. Every line did what I wrote it to do. I had written code that looked at that video, decided it was too damaged to deserve its own resolution, and rescued it by throwing away three quarters of its pixels. I build this thing on my own, so there's nobody to hide behind here. Every bug below is mine, and…

The author wrote a compressor that downscales videos from 1080p to 480x270 resolution to protect their quality. The compressor analyzes the video, determines it's too damaged to keep its original resolution, and discards three quarters of the pixels. The author built this tool on their own, so they are responsible for any bugs. They used two engines for compression: WebCodecs for the fast path and ffmpeg.wasm for containers that WebCodecs can't demux.

The author chose ffmpeg.wasm deliberately to avoid SharedArrayBuffer issues. They focused on bitrate because it affects how a video looks, not the source resolution. The author set a bitrate floor at 0.075 bpp, which caused the downsizing issue. The issue arose when the author forced a bitrate on the video, resulting in a lower resolution than necessary.

The downscaled video had far more pixels than the original, defeating the purpose of protecting quality. The author corrected the issue by setting the bitrate floor to be 20% of the source's original bitrate. Additionally, the author discovered they were using an incorrect bitrate calculation method that included audio and container overhead, leading to inaccurate encoding decisions. The author addressed this by properly computing the video bitrate from packet statistics.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Iniciando meus estudos em Event Loop

✨♻️ JavaScript Visualized: Event Loop Lydia Hallie Lydia Hallie Lydia Hallie Follow Nov 20 '19 ✨♻️ JavaScript Visualized: Event Loop # javascript # webdev

More from Sunday 20 September →