Kompres Video
Bidik sebuah ukuran — 10 MB untuk Discord, 25 MB untuk email — atau cukup turunkan kualitasnya. Berjalan di mesin Anda, jadi tidak ada batas ukuran maupun antrean.
Peramban Anda yang membaca dan mengodekan ulang berkas. Tidak ada permintaan yang mengirimnya ke mana pun — halaman ini tidak punya server tujuan unggah.
Pertanyaan
Benarkah bisa mengenai ukuran persis?
Untuk itulah mode «pas ke sebuah ukuran» dibuat. Bobot berkas adalah bitrate dikali durasi, jadi begitu durasinya diketahui, bitrate yang dibutuhkan tinggal aritmetika. Pengode tidak menuruti bitrate yang diminta dengan tepat — kendali laju bergeser mengikuti materi — sehingga bila lintasan pertama meleset lebih dari beberapa persen, selisihnya diukur dan berkas dikodekan ulang sekali dengan angka yang sudah dikoreksi. Dalam praktik hasilnya berada beberapa persen dari sasaran.
Mengapa 10 MB, 16 MB, 25 MB?
Itu tembok yang benar-benar orang tabrak: 10 MB batas unggah gratis Discord, 16 MB WhatsApp, 25 MB Gmail dan sebagian besar server surel, dan 50 MB Discord Nitro Basic. Alat ini membidik tepat di bawah batas, bukan pas di batas, karena berkas 10,0 MB tetap ditolak oleh batas 10 MB.
Bagaimana kalau sasarannya mustahil?
Ia mengatakannya sebelum mulai, dan menyebut ukuran terkecil yang jujur untuk video itu. Memeras satu jam rekaman ke 10 MB menuntut bitrate yang tidak sanggup ditanggung resolusi mana pun: alat yang menghasilkan berkas tak tertonton lalu menyebutnya berhasil lebih buruk daripada alat yang menolak.
Seberapa kecil berkas saya nanti?
Perkiraan muncul sebelum Anda menekan apa pun, dari pengaturan dan durasinya. Rekaman langsung dari ponsel atau kamera biasanya direkam jauh di atas kebutuhannya, dan penyusutan 60–90% adalah hal lumrah. Yang sudah pernah dikompres tidak punya banyak sisa, dan alat ini membandingkan berkas Anda dengan yang wajar dibutuhkan resolusinya, lalu memperingatkan bila pengodean ulang justru membesarkannya.
Apa yang sebenarnya mengecilkan video?
Lebih sedikit piksel dan lebih sedikit bit per piksel. Resolusi adalah tuas kasar yang bisa diandalkan: turun dari 4K ke 1080p membuang tiga perempat piksel bahkan sebelum kualitas dibicarakan. Bitrate lalu menentukan seberapa banyak detail yang bertahan. Membuang audio hanya menolong sedikit; ia jarang lebih dari beberapa persen sebuah berkas video.
Apakah diunggah ke suatu tempat?
Tidak. Semuanya berjalan dengan WebCodecs di peramban Anda, dan itulah yang membuatnya masuk akal: mengunggah satu gigabyte agar server mengembalikan 200 MB lebih lambat daripada mengerjakannya secara lokal, dan sepanjang jalan rekaman Anda mendarat di cakram orang lain. Tanpa batas ukuran, tanpa antrean, tanpa watermark — sebab tidak ada server yang memberlakukannya.
Alat lainnya
Pasang ini di proyek Anda sendiri
Compressing video to a target file size — the same way this page does it, on the user's machine, with no server. Take the code, or hand the prompt to a coding agent.
// npm i mediabunny
import { Input, Output, Conversion, BlobSource, BufferTarget, Mp4OutputFormat, ALL_FORMATS } from 'mediabunny';
// Size is bitrate x duration, so a target size fixes the bitrate.
const OVERHEAD = 0.04; // container headers and packaging
const AUDIO_BITRATE = 128_000;
export async function compressToSize(file, targetBytes, { width } = {}) {
const input = new Input({ source: new BlobSource(file), formats: ALL_FORMATS });
const duration = await input.computeDuration();
// Aim under the wall: a file of exactly 10.00 MB is still refused by a 10 MB limit.
const aim = targetBytes * 0.96;
const videoBitrate = Math.max(
90_000,
Math.round((aim * 8 * (1 - OVERHEAD) - AUDIO_BITRATE * duration) / duration),
);
const output = new Output({ format: new Mp4OutputFormat(), target: new BufferTarget() });
const conversion = await Conversion.init({
input,
output,
video: {
...(width ? { width } : {}),
bitrate: videoBitrate,
hardwareAcceleration: 'prefer-hardware', // 180 fps vs 34 on an M5 at 1080p
},
audio: { bitrate: AUDIO_BITRATE },
});
if (!conversion.isValid) throw new Error('Cannot convert this file');
await conversion.execute();
return new Blob([output.target.buffer], { type: 'video/mp4' });
}
// Encoders drift, so measure and correct once if the first pass missed.
const blob = await compressToSize(file, 10 * 1024 * 1024);
console.log(blob.size / 1048576, 'MB'); Build me a video compressor that runs entirely in the browser — no upload, no server.
Requirements:
- Use the "mediabunny" npm package, which wraps WebCodecs. Do not use ffmpeg.wasm: it is ~30 MB and
needs SharedArrayBuffer, which requires COOP/COEP headers that break third-party scripts.
- Let the user target a file size (presets: 10 MB Discord, 16 MB WhatsApp, 25 MB email) as well as
picking a quality.
- To hit a size: size = bitrate x duration, so videoBitrate = (targetBytes * 8 * 0.96 - audioBitrate
* duration) / duration. Aim at 96% of the limit, because a file of exactly 10.00 MB is still
rejected by a 10 MB limit.
- Encoders do not obey a requested bitrate exactly. Measure the result; if it missed by more than 4%
or broke the limit, re-encode once with bitrate * (target / actual), damped to at most a halving
or doubling. Stop at two passes.
- Pass hardwareAcceleration: 'prefer-hardware'. Measured on an M5 at 1080p: 180 fps against 34 fps
for software, and the software encoder also overshot the requested bitrate by 3.5x.
- Show the estimated output size before encoding, and the real before/after afterwards.
- Refuse impossible targets up front: below about 90 kbps video is unwatchable, so if the target
cannot be met at that floor, say so and give the smallest honest size instead of producing junk.
- Warn when the source is already compressed below what its resolution needs — re-encoding it will
make it larger, and only reducing the resolution will help.
Reference implementation: https://life2film.com/tools/video-compressor/
The engine is documented for agents, and every tool page is available as
markdown by adding .md to its address.