Skip to content
Back to search

halfsize

Compress any video to an exact size (25 MB, 10 MB, ...) locally with FFmpeg, then prove the quality with VMAF/SSIM. One command, no upload, no account.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/YKLovePython/halfsize with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/YKLovePython/halfsize'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/yklovepython--halfsize/badge.svg)](/listings/yklovepython--halfsize)

HTML

<a href="/listings/yklovepython--halfsize"><img src="/api/listings/yklovepython--halfsize/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Requires [Node.js 18+](https://nodejs.org). FFmpeg is bundled on first install; if it cannot be downloaded, `halfsize` uses your system install instead.

# compress to a size
npx halfsize video.mp4 --to 25mb

# or just name the app you are uploading to
npx halfsize video.mp4 --for discord

# several files in one go
npx halfsize clip1.mp4 clip2.mp4 clip3.mp4 --to 10mb

# smaller file, same quality budget
npx halfsize video.mp4 --to 10mb --codec h265

# quality-first mode when size does not matter
npx halfsize video.mp4 --crf 23

# preview the plan without encoding
npx halfsize video.mp4 --to 25mb --dry-run

# machine-readable, for scripts
npx halfsize video.mp4 --to 25mb --json

Install it globally if you will use it more than once:

npm install -g halfsize

The local web app

npx halfsize --web

Opens `http://127.0.0.1:4174` — drag a video in, pick 25 MB / 10 MB / 20 MB / 5 MB or type your own limit, and watch the encode. The file goes to a temporary folder **on your own machine**; nothing is sent anywhere.

<p align="center"> </p>

After each run you can download a **share card** (the image at the top of this README) with the real numbers on it.

Use it from an agent

The repo ships a skill in [`skills/halfsize/SKILL.md`](skills/halfsize/SKILL.md). Drop that folder into your agent's skills directory (for Claude Code: `.claude/skills/halfsize/`) and the agent can turn "make this fit in 25 MB" into a compression plus a measured quality report, instead of guessing a bitrate.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 438 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. <p align="center">
  2. <img src="https://raw.githubusercontent.com/YKLovePython/halfsize/main/docs/card.webp" width="760" alt="halfsize: 23.2 MB to 1.99 MB, 12x smaller, VMAF 84.4">
  3. </p>
  4. <h1 align="center">halfsize</h1>
  5. <p align="center">
  6. <b>Compress any video to any size. Locally. And keep the quality.</b>
  7. </p>
  8. <p align="center">
  9. <a href="https://www.npmjs.com/package/halfsize"><img alt="npm" src="https://img.shields.io/npm/v/halfsize?color=b6f36a"></a>
  10. <a href="https://www.npmjs.com/package/halfsize"><img alt="downloads" src="https://img.shields.io/npm/dm/halfsize?color=b6f36a"></a>
  11. <a href="LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT-b6f36a"></a>
  12. <a href="https://github.com/YKLovePython/halfsize/actions/workflows/test.yml"><img alt="tests" src="https://github.com/YKLovePython/halfsize/actions/workflows/test.yml/badge.svg"></a>
  13. <img alt="node" src="https://img.shields.io/badge/node-%3E%3D18-b6f36a">
  14. <img alt="no upload" src="https://img.shields.io/badge/upload-none-b6f36a">
  15. </p>
  16. <p align="center">
  17. <a href="README.zh-CN.md">中文说明</a> ·
  18. <a href="https://YKLovePython.github.io/halfsize/">Website &amp; guides</a> ·
  19. <a href="#quick-start">Quick start</a> ·
  20. <a href="#how-it-works">How it works</a> ·
  21. <a href="#faq">FAQ</a>
  22. </p>
  23. <p align="center">
  24. <sub>As featured in <a href="https://www.ruanyifeng.com/blog/2026/11/weekly-issue-418.html">阮一峰《科技爱好者周刊》第 418 期</a> · 2,500+ downloads on npm</sub>
  25. </p>
  26. <p align="center">
  27. <b>New in 0.1.11:</b> <code>--fix</code> repairs an install where npm silently skipped the
  28. FFmpeg download, and <code>--mcp</code> turns the same command into a tool for Claude Code,
  29. Cursor and VS Code. Neither one sends your video anywhere.
  30. <a href="https://github.com/YKLovePython/halfsize/releases/tag/v0.1.11">Release notes</a>
  31. </p>
  32. ---
  33. WeChat and Discord both stop at **20 MB**. Email chokes around the same.
  34. So you open a video editor, guess a bitrate, export, check the size, export again, and still
  35. can't tell whether the picture got worse.
  36. `halfsize` turns that into one command:
  37. ```bash
  38. npx halfsize wedding.mp4 --to 25mb
  39. ```
  40. It computes the bitrate, picks the resolution that actually fits, encodes twice, then measures
  41. the result with **SSIM** and **VMAF** so you know whether it still looks the same.
  42. ```
  43. halfsize 0.1.11
  44. source.mp4
  45. 23.2 MB 8s 1920x1080 30.00 fps h264
  46. target 2.00 MB
  47. plan H.264 960x540 1.81 Mbps audio 128 kbps 2-pass
  48. scale 1920x1080 -> 960x540
  49. estimate 1.94 MB (12x smaller)
  50. output source.2mb.mp4
  51. measuring quality done in 1s
  52. 23.2 MB -> 1.99 MB 12x smaller 0.4% under target
  53. VMAF 84.4 SSIM 0.968 slight softening
  54. -> C:\Videos\source.2mb.mp4
  55. ```
  56. ## Why this exists
  57. "Make it smaller" is a solved problem. **"Make it fit in exactly 20 MB, and tell me if it
  58. still looks right"** is the part every tool makes you guess at.
  59. - HandBrake is excellent, but it asks you to think in codecs, RF values, and presets.
  60. - Online compressors work until you remember you just uploaded a private video to a stranger.
  61. - `ffmpeg` can do all of this. Nobody remembers the 11 flags, and almost nobody checks VMAF afterwards.
  62. `halfsize` is the missing 5%: a target size you type, and a quality score you can read.
  63. | | halfsize | HandBrake | Online compressors |
  64. |---|---|---|---|
  65. | Fit an exact size | ✅ one flag | manual bitrate math | usually re-encodes blindly |
  66. | Tells you the quality cost | ✅ VMAF + SSIM | ❌ | ❌ |
  67. | Your file stays on your machine | ✅ | ✅ | ❌ |
  68. | Scriptable / CI friendly | ✅ CLI + JSON | ❌ GUI | ❌ |
  69. | Learns a new UI | no | yes | yes |
  70. ## Quick start
  71. Requires [Node.js 18+](https://nodejs.org). FFmpeg is bundled on first install; if it cannot
  72. be downloaded, `halfsize` uses your system install instead.
  73. ```bash
  74. # compress to a size
  75. npx halfsize video.mp4 --to 25mb
  76. # or just name the app you are uploading to
  77. npx halfsize video.mp4 --for discord
  78. # several files in one go
  79. npx halfsize clip1.mp4 clip2.mp4 clip3.mp4 --to 10mb
  80. # smaller file, same quality budget
  81. npx halfsize video.mp4 --to 10mb --codec h265
  82. # quality-first mode when size does not matter
  83. npx halfsize video.mp4 --crf 23
  84. # preview the plan without encoding
  85. npx halfsize video.mp4 --to 25mb --dry-run
  86. # machine-readable, for scripts
  87. npx halfsize video.mp4 --to 25mb --json
  88. ```
  89. Install it globally if you will use it more than once:
  90. ```bash
  91. npm install -g halfsize
  92. ```
  93. ### In CI
  94. The same compression runs in GitHub Actions, and the quality report lands in the build log:
  95. ```yaml
  96. - uses: YKLovePython/halfsize-action@v1
  97. with:
  98. files: artifacts/recording.mp4
  99. args: --to 20mb
  100. ```
  101. [halfsize-action on the GitHub Marketplace](https://github.com/marketplace/actions/halfsize-compress-video-to-an-exact-size).
  102. ### The local web app
  103. ```bash
  104. npx halfsize --web
  105. ```
  106. Opens `http://127.0.0.1:4174` — drag a video in, pick 20 MB / 16 MB / 5 MB or type
  107. your own limit, and watch the encode. The file goes to a temporary folder **on your own
  108. machine**; nothing is sent anywhere.
  109. <p align="center">
  110. <img src="https://raw.githubusercontent.com/YKLovePython/halfsize/main/docs/screenshot.webp" width="860" alt="halfsize local web app showing 23.2 MB compressed to 1.99 MB with VMAF 84.4">
  111. </p>
  112. After each run you can download a **share card** (the image at the top of this README) with the
  113. real numbers on it.
  114. Step-by-step guides with measured quality numbers:
  115. [Discord 20 MB](https://YKLovePython.github.io/halfsize/discord/) ·
  116. [WhatsApp 16 MB](https://YKLovePython.github.io/halfsize/whatsapp/) ·
  117. [WeChat 20 MB](https://YKLovePython.github.io/halfsize/wechat/) ·
  118. [email attachments](https://YKLovePython.github.io/halfsize/email/) ·
  119. [X / Twitter](https://YKLovePython.github.io/halfsize/twitter/) ·
  120. [any 20 MB limit](https://YKLovePython.github.io/halfsize/20mb/) ·
  121. [FFmpeg target size](https://YKLovePython.github.io/halfsize/ffmpeg-compress-to-size/) ·
  122. [compress without uploading](https://YKLovePython.github.io/halfsize/offline/).
  123. ### Which size do I need?
  124. | Where it is going | The cap | Command |
  125. |---|---|---|
  126. | Discord (free) | 20 MB per file | `--for discord` |
  127. | WeChat chat video | 20 MB | `--for wechat` |
  128. | WhatsApp, sent as media | 16 MB | `--for whatsapp` |
  129. | Gmail attachment | 25 MB message → 18 MB file | `--for gmail` |
  130. | Outlook / corporate mail | 20 MB message → 15 MB file | `--for outlook` |
  131. | X / Twitter | 512 MB | `--for twitter` |
  132. | Anything else | whatever you type | `--to 700mb` |
  133. The email rows are smaller on purpose: base64 makes the attachment about 37% bigger than the
  134. file, so an 18 MB MP4 is what fits in a 25 MB message. Caps change; `--to` always overrides the
  135. preset. Full table, with what each cap counts and the measured VMAF at each size:
  136. [size limits by platform](https://YKLovePython.github.io/halfsize/file-size-limits/) ·
  137. [every target size explained](https://YKLovePython.github.io/halfsize/compress-video-to-size/) ·
  138. [video size calculator](https://YKLovePython.github.io/halfsize/video-size-calculator/).
  139. ### Use it from an agent
  140. The repo ships a skill in [`skills/halfsize/SKILL.md`](skills/halfsize/SKILL.md). Install it with
  141. the [skills CLI](https://skills.sh) so Claude Code, Codex, Cursor, OpenCode and the rest pick it
  142. up automatically:
  143. ```bash
  144. npx skills add YKLovePython/halfsize
  145. ```
  146. Or copy the folder into your agent's skills directory by hand (for Claude Code:
  147. `.claude/skills/halfsize/`). Either way the agent can turn "make this fit in 25 MB" into a
  148. compression plus a measured quality report, instead of guessing a bitrate.
  149. If your client speaks MCP instead, halfsize is also a single-tool MCP server:
  150. ```json
  151. {
  152. "mcpServers": {
  153. "halfsize": { "command": "npx", "args": ["-y", "halfsize", "--mcp"] }
  154. }
  155. }
  156. ```
  157. That gives the agent one tool, `compress_video(input, target, output?, codec?, verify?)`,
  158. backed by the same CLI and the same JSON report. It is stdio only: no port, no daemon,
  159. nothing listening. Per-client setup (Claude Code, Claude Desktop, Cursor, VS Code) is on
  160. [MCP server](https://YKLovePython.github.io/halfsize/mcp/).
  161. ## How it works
  162. 1. **Probe.** Read duration, resolution, frame rate, audio bitrate, rotation, and HDR metadata.
  163. 2. **Budget.** Total bitrate = target bytes × 8 ÷ duration, minus audio, minus a small
  164. container overhead.
  165. 3. **Pick a resolution.** Walk a ladder from the source size down to 240p and choose the
  166. largest one whose pixels fit the budget at that codec's bits-per-pixel target
  167. (H.264: 0.072 bpp, H.265: 0.045 bpp). This is why a 12× shrink still looks reasonable:
  168. the encoder gets to spend its bits on fewer pixels.
  169. 4. **Encode twice.** Two-pass ABR with `libx264` or `libx265`. Pass one learns where the bits
  170. are needed; pass two spends them. Output is `yuv420p`, AAC audio, `+faststart`, and tagged
  171. `hvc1` for H.265 so it plays on Apple devices. HLG/PQ sources are tone-mapped to SDR BT.709
  172. in the same pass; without that, 8-bit pixels keep their HDR tags and look grey.
  173. 5. **Prove it.** Sample three points in the video, compute SSIM at each, and VMAF at the
  174. midpoint. Compare against thresholds and print a verdict in plain language.
  175. ```
  176. VMAF ≥ 95 indistinguishable
  177. VMAF ≥ 90 looks the same
  178. VMAF ≥ 80 slight softening
  179. VMAF ≥ 70 visible loss
  180. below 70 clearly degraded
  181. ```
  182. VMAF is Netflix's perceptual metric; it correlates with human judgement far better than PSNR
  183. or bitrate. It is not magic, but it is a much better answer than "trust me".
  184. ## What each size costs
  185. Same 60-second 1080p clip, default settings, measured on a normal laptop:
  186. | Target | Output | Resolution | Video bitrate | VMAF | Verdict |
  187. |---|---|---|---|---|---|
  188. | 20 MB | 19.45 MB | 1280×720 | 2.46 Mbps | 88.3 | slight softening |
  189. | 16 MB | 15.59 MB | 960×540 | 1.94 Mbps | 84.8 | slight softening |
  190. | 10 MB | 9.77 MB | 960×540 | 1.17 Mbps | 82.9 | slight softening |
  191. | 5 MB | 4.93 MB | 640×360 | 0.55 Mbps | 72.0 | visible loss |
  192. Source: 60 s, 1920×1080, 30 fps, 18 Mbps H.264 (136 MB). VMAF is measured against the
  193. source at the midpoint, SSIM at three points. Real numbers move with content: a talking head
  194. does much better than confetti.
  195. At 20 MB the tool picked 720p on purpose. Sixty seconds of 1080p at 2.4 Mbps looks worse than
  196. 720p at the same bits. `--no-downscale` overrides that, and `--codec h265` buys roughly 30%
  197. more quality at the same size if your player supports it.
  198. ## CLI reference
  199. ```
  200. halfsize <file> [options]
  201. --to <size> Target size: 25mb, 700k, 1.5gb
  202. --for <app> Target cap for discord, whatsapp, wechat, gmail, outlook, email, twitter
  203. --crf <n> Quality mode instead of size mode (18 best, 23 balanced, 28 small)
  204. --codec <name> h264 (default, maximum compatibility) or h265 (about 30% smaller)
  205. --preset <name> ultrafast .. veryslow (default: medium)
  206. --out <file> Output path
  207. --no-audio Drop the audio track
  208. --no-verify Skip SSIM/VMAF
  209. --no-downscale Never reduce resolution (the target may then be missed)
  210. --force Encode even when the target is below the minimum for this duration
  211. --json Machine-readable result
  212. --dry-run Print the plan, do not encode
  213. --web Start the local web app
  214. --port <n> Port for the web app (default 4174)
  215. --doctor Show which FFmpeg and encoders were found
  216. --fix Download FFmpeg when npm skipped it
  217. --mcp Run as an MCP server on stdio (for AI agents)
  218. -h, --help Help
  219. -v, --version Version
  220. ```
  221. Sizes accept `b`, `k`/`kb`, `m`/`mb`, `g`/`gb`, with or without a space. No unit means MB.
  222. `--for` uses the current free-tier caps (checked November 2026): `discord` 20 MB,
  223. `whatsapp` 16 MB, `wechat` 20 MB, `gmail`/`email` 18 MB, `outlook` 15 MB, `twitter`
  224. 512 MB. Email caps apply to the base64-encoded message, so an 18 MB file is the largest
  225. that stays under Gmail's 25 MB. Caps change, so `--to` always overrides.
  226. Exit codes: `0` success, `1` error. `--json` returns the plan, the measured quality, and the
  227. target accuracy, which makes it easy to wrap in a script.
  228. ## Install notes
  229. Needs Node.js 18 or newer. The first `npx` run downloads both the package and a
  230. prebuilt FFmpeg, so it can pause for a minute. If you will use it more than once,
  231. install it globally and skip that wait on every run:
  232. ```bash
  233. npm install -g halfsize
  234. halfsize video.mp4 --to 25mb
  235. ```
  236. If `npx` keeps starting an old cached version, pin it: `npx halfsize@latest ...`.
  237. `ffmpeg-static` downloads a prebuilt FFmpeg during `npm install`; FFprobe ships inside
  238. `ffprobe-static`, so it needs no download. If you are behind a proxy or a TLS-inspecting
  239. network, that download can silently fail and leave you with a CLI that starts but cannot
  240. encode. One command repairs it, without reinstalling anything:
  241. ```bash
  242. npx halfsize@latest --fix
  243. ```
  244. `--fix` fetches the same published FFmpeg and FFprobe builds, checks each download against
  245. the sha256 that `ffmpeg-static` published, and keeps them in a user-level cache
  246. (`%LOCALAPPDATA%\halfsize\Cache\bin`, `~/Library/Caches/halfsize/bin`, or
  247. `~/.cache/halfsize/bin`). Every later run, global or `npx`, finds them there. It tries GitHub
  248. first and falls back to the npmmirror binary mirror, which is fast in mainland China.
  249. Two alternatives if the download itself is blocked:
  250. ```bash
  251. # use the npmmirror binary mirror (fast in mainland China)
  252. FFMPEG_BINARIES_URL=https://registry.npmmirror.com/-/binary/ffmpeg-static npx halfsize video.mp4 --to 25mb
  253. # or an FFmpeg already on disk
  254. HALFSIZE_FFMPEG=/path/to/ffmpeg HALFSIZE_FFPROBE=/path/to/ffprobe npx halfsize video.mp4 --to 25mb
  255. ```
  256. If npm says `unable to verify the first certificate`, a proxy or antivirus is inspecting
  257. TLS. On Node 22.15+ use the system certificate store:
  258. ```powershell
  259. $env:NODE_OPTIONS="--use-system-ca"; npx halfsize video.mp4 --to 25mb
  260. ```
  261. A failed binary download no longer aborts the install: halfsize still starts and prints the
  262. `--fix` command. On Windows, `winget install Gyan.FFmpeg` is enough. On macOS,
  263. `brew install ffmpeg`. On Debian/Ubuntu, `sudo apt install ffmpeg`. Run
  264. `npx halfsize --doctor` to see what was found.
  265. ## FAQ
  266. **Does my video get uploaded?**
  267. No. Compressing a video never touches the network: the only outbound request halfsize ever
  268. makes is `--fix` downloading FFmpeg itself when npm skipped it. The web app talks only to
  269. `127.0.0.1`, and uploaded files go to a temp directory that is deleted when the process exits.
  270. **How do I get a video under Discord's 20 MB limit?**
  271. `npx halfsize clip.mp4 --for discord` targets the free-tier cap (20 MB as of late 2026) and
  272. writes a normal MP4 that plays in Discord's preview. Long 1080p clips usually come out at 720p;
  273. that resolution drop is what buys the size.
  274. **WeChat says the video is too large. What now?**
  275. `npx halfsize clip.mp4 --for wechat` targets the 20 MB chat-video cap. If you need it smaller
  276. still, pass `--to 10mb` (or any size) instead.
  277. **How many minutes of video fit in 20 MB?**
  278. About two minutes at 1.2 Mbps, which is normal 720p. Five minutes only works at 400 kbps
  279. (low-motion 540p), and ten minutes leaves 133 kbps — that is a slideshow, not video. Since 0.1.9
  280. the tool does that arithmetic before encoding and reports the smallest size the duration can hold,
  281. so you find out in a second instead of ten minutes.
  282. **Why does my iPhone video turn grey after compressing?**
  283. Because it is HDR. iPhone 12 and later record HLG by default, and older tools re-encode those
  284. values as ordinary 8-bit video while keeping the HDR tag, so players show it flat and washed out.
  285. halfsize detects HLG and PQ and converts to SDR BT.709 inside the same encode pass, including the
  286. quality measurement, so the output looks like what you saw on the phone. On a version before 0.1.9,
  287. upgrade instead of tuning bitrate.
  288. **Why did it lower my resolution?**
  289. Because 20 MB of 4K is not enough bits to look good. Lowering resolution and keeping the
  290. bitrate per pixel sane almost always looks better than keeping 4K and starving it. Use
  291. `--no-downscale` if you want to override that.
  292. **Why is the output slightly under the target, not exactly on it?**
  293. Container overhead and two-pass ABR both vary a little. `halfsize` aims ~3% under so it never
  294. overshoots a hard platform cap. In the example above it landed 0.4% under.
  295. **H.264 or H.265?**
  296. H.264 plays everywhere, including old Android phones and browsers. H.265 is roughly 30% smaller
  297. at the same quality but can be awkward in some editors and older hardware. Default is H.264.
  298. **Does it work on Windows / macOS / Linux?**
  299. Yes. It is plain Node.js and FFmpeg.
  300. **Can I batch a folder?**
  301. Yes. List the files, or let your shell expand them:
  302. ```bash
  303. npx halfsize *.mp4 --to 25mb
  304. ```
  305. Each file gets its own plan and verdict, a failure does not stop the rest, and `--json` returns
  306. `{ "files": [ ... ] }`. `--out` is allowed only when there is a single input.
  307. **Why "halfsize"?**
  308. Because the honest answer to "how much smaller will it get?" is usually "about half, or a lot
  309. more than half". The tool reports the real number either way.
  310. ## Roadmap
  311. - Hardware encoding (NVENC / QSV / VideoToolbox) as an opt-in fast path
  312. - A folder watcher that compresses new files as they appear
  313. - Subtitle and multiple audio track passthrough
  314. - AV1 (`libsvtav1`) when the source is already AV1-friendly
  315. - A single-file binary, so Node.js is not required
  316. If you want one of these, open an issue and say which. Pull requests are welcome; see
  317. [CONTRIBUTING.md](CONTRIBUTING.md).
  318. ## Development
  319. ```bash
  320. git clone https://github.com/YKLovePython/halfsize.git
  321. cd halfsize
  322. npm install
  323. npm test
  324. node bin/halfsize.mjs --web
  325. ```
  326. The test suite includes a real end-to-end encode: it generates a clip with FFmpeg, compresses
  327. it to a target, probes the output, and asserts the size and SSIM. No fixtures in the repo.
  328. ## License
  329. MIT. Use it, fork it, ship it.
  330. See [CHANGELOG.md](CHANGELOG.md) for what changed.
  331. ---
  332. If `halfsize` saved you from guessing a bitrate, a star helps the next person find it.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.