Unity HandBrake Video Optimizer is a Unity Editor extension for compressing and optimizing project video assets with HandBrakeCLI. It helps Unity developers reduce MP4, MOV, MKV, AVI, and WEBM file sizes while keeping visual quality, source timing, and editor workflow intact.
The tool runs from Tools > Video Optimizer and is designed for game projects, XR projects, mobile builds, WebGL/media-heavy scenes, training simulations, and Unity projects with large video libraries.
- Scan all supported video files under the Unity
Assetsfolder. - Batch optimize selected videos from a dedicated Unity Editor window.
- Use external HandBrakeCLI through
ProcessStartInfo. - Choose presets: Balanced, High Quality, Small Size, and Mobile/Web.
- Choose video codec: H.264/x264 or H.265/x265.
- Use constant quality RF/CRF encoding for predictable quality.
- Preserve source frame timing with HandBrake
--vfr. - Select AAC audio bitrate, including 128k, 160k, and higher values.
- Write optimized copies with
_optimizedsuffix to avoid name conflicts. - Safely overwrite original MP4 files through a temporary encode file.
- Keep Unity asset references when overwriting the original MP4 asset.
- Show progress, stdout/stderr logs, failed files, old size, new size, and percentage savings.
- Support cancellation through
CancellationToken. - Refresh Unity assets after processing with
AssetDatabase.Refresh(). - Editor-only implementation under
Assets/Editor, so it is not included in runtime builds.
Input files scanned under Assets:
.mp4.mov.mkv.avi.webm
Optimized outputs are written as MP4 files for broad Unity, mobile, and web compatibility.
- Unity 2021 LTS or newer
- Windows, macOS, or Linux Unity Editor
- External HandBrakeCLI installation
HandBrake is GPL-2.0 licensed software. This Unity plugin does not embed or redistribute HandBrake source code or binaries. It only calls a user-provided external HandBrakeCLI executable.
Expected executable names:
| Platform | Executable |
|---|---|
| Windows | HandBrakeCLI.exe |
| macOS | HandBrakeCLI |
| Linux | HandBrakeCLI |
-
Install HandBrakeCLI on your machine. Official CLI documentation: https://handbrake.fr/docs/en/latest/cli/cli-options.html
-
Copy this folder into your Unity project:
Assets/Editor/VideoOptimizer/ -
Reopen or recompile Unity.
-
Open the tool from:
Tools > Video Optimizer -
Set the
HandBrakeCLIpath manually or press Auto Find.
- Open Tools > Video Optimizer.
- Press Scan Project Videos.
- Select the videos you want to optimize.
- Choose a preset and codec.
- Adjust RF/CRF quality if needed.
- Choose output folder or enable Overwrite Original.
- Press Optimize Selected.
For transparent replacement of already assigned Unity video assets, enable Overwrite Original. The tool encodes to a temporary file first and replaces the original only after HandBrakeCLI succeeds.
| Goal | H.264 RF | H.265 RF | Audio |
|---|---|---|---|
| High Quality | 20 | 22 | 160k |
| Balanced | 22 | 24 | 160k |
| Small Size | 23 | 26 | 128k |
| Mobile/Web | 23 | 25 | 128k |
Lower RF means higher quality and larger files. Higher RF means smaller files and lower quality.
Unity asset references usually point to the GUID stored in the .meta file.
- Overwrite Original ON for MP4: existing references continue to point to the same asset because the
.metafile is preserved. - Overwrite Original OFF: the tool creates a new
_optimized.mp4file with a new Unity asset GUID, so existing references are not changed automatically. - String URL paths: if a project uses
VideoPlayer.urlor custom string paths, Unity GUID tracking does not apply.
The generated command is equivalent to:
HandBrakeCLI -i input.mp4 -o output.mp4 -f av_mp4 -e x264 -q 22 --vfr --audio 1 -E av_aac -B 160 --optimizeAssets/Editor/VideoOptimizer/
VideoOptimizerWindow.cs
VideoOptimizerSettings.cs
VideoFileInfo.cs
HandBrakeRunner.cs
Unity video optimizer, Unity video compression tool, Unity HandBrake plugin, Unity HandBrakeCLI integration, Unity MP4 compressor, Unity Editor video optimization, compress videos in Unity, Unity H.264 video optimizer, Unity H.265 HEVC video optimizer, Unity mobile video compression, Unity WebGL video optimization, game asset optimization, Unity media asset pipeline, HandBrakeCLI Unity editor tool.
unity, unity-editor, handbrake, handbrakecli, video-optimizer, video-compression, mp4, h264, h265, hevc, game-development, editor-tool, unity-tools
This Unity plugin is released under the MIT License.
HandBrake and HandBrakeCLI are separate external tools licensed by their own project. This repository does not include HandBrake binaries or source code.