Convert Y4M to MKV — Free Online Tool

Convert Y4M (YUV4MPEG2) uncompressed video files to MKV using H.264 encoding directly in your browser. Y4M is a raw, uncompressed intermediate format — converting it to MKV with libx264 dramatically reduces file size while preserving visual quality through CRF-controlled compression.

FFmpeg Command

Copy this command to run the same conversion locally with FFmpeg on your desktop. Download FFmpeg

Free — no uploads, no signups. Your files never leave your browser.

Estimated output:

Conversion Complete!

Download

How It Works

Y4M files store raw YUV pixel data frame-by-frame with no compression whatsoever, making them enormous but losslessly accurate. During this conversion, FFmpeg reads each uncompressed YUV frame and encodes it using the libx264 H.264 encoder at CRF 23 (a perceptually near-transparent quality level), then wraps the resulting video stream in a Matroska (MKV) container. Because Y4M carries no audio, the AAC audio codec flag is present in the command but will produce no audio track if the source has none. The Matroska container is chosen here for its flexibility — it supports subtitles, chapters, and multiple audio tracks should you later remux or enrich the file.

What Each Flag Does

Flag What it does
ffmpeg Invokes the FFmpeg tool. In the browser-based version of this tool, FFmpeg runs via WebAssembly (FFmpeg.wasm) entirely client-side — your Y4M file never leaves your machine.
-i input.y4m Specifies the input Y4M file. FFmpeg reads the YUV4MPEG2 header to extract frame rate, resolution, chroma subsampling, and interlacing information before decoding the raw uncompressed YUV frames.
-c:v libx264 Encodes the video stream using the libx264 H.264 encoder, transforming each raw YUV frame from the uncompressed Y4M source into a compressed H.264 stream that will be wrapped in the MKV container.
-c:a aac Sets the audio codec to AAC for any audio streams present. Since Y4M is a video-only format with no audio, this flag has no effect on the output but is included as a safe default for MKV compatibility.
-crf 23 Sets the Constant Rate Factor for the libx264 encoder to 23, which is the default quality level — a perceptually high-quality setting that balances file size and visual fidelity well for content originating from a pristine uncompressed Y4M source.
-b:a 128k Sets the target audio bitrate to 128 kbps for the AAC encoder. This has no practical effect for Y4M conversions since Y4M carries no audio, but is included to ensure predictable behavior if an audio stream were somehow present.
output.mkv Defines the output file as a Matroska (.mkv) container. The .mkv extension instructs FFmpeg to mux the encoded H.264 video into the Matroska format, which supports future additions of subtitles, chapters, and multiple audio tracks.

Common Use Cases

  • Compressing the raw Y4M output from video synthesis tools like Blender's compositor or VapourSynth before archiving or sharing, reducing file sizes by 50x or more without visible quality loss
  • Converting Y4M intermediate files produced by FFmpeg pipe workflows or tools like x264/x265 in two-pass encoding setups into a self-contained, shareable MKV file
  • Turning raw Y4M captures from scientific or industrial imaging software into H.264 MKV files that are compatible with standard media players and video editors
  • Encoding lossless Y4M test sequences (such as those from video codec research databases) into compressed MKV for distribution or streaming tests
  • Preparing Y4M output from analog capture cards or frame grabbers for long-term storage in an efficient, widely-supported format without re-encoding through multiple lossy steps
  • Packaging Y4M footage generated by animation rendering pipelines into MKV for delivery to clients who need a standard video file rather than a raw format

Frequently Asked Questions

The size reduction is dramatic. Y4M stores raw YUV pixel data with zero compression, so a single minute of 1080p30 Y4M footage can easily exceed 10–15 GB. Encoding to H.264 at CRF 23 typically produces files 50 to 200 times smaller, depending on content complexity. A 10 GB Y4M file might become 100–300 MB as an MKV, with visually near-identical quality.
Yes, but in practice the loss is imperceptible at the default CRF 23 setting. Y4M is a lossless uncompressed format, and H.264 encoding is inherently lossy. However, CRF 23 is considered a high-quality transparent encode for most content — you would need to do a pixel-level comparison to spot differences. If you need lossless output, you can change the video codec to libx264 with -crf 0 for lossless H.264, though this will produce much larger files than CRF 23.
Y4M is a video-only format and carries no audio stream whatsoever. The -c:a aac flag is included in the command as a safe default for MKV output, but FFmpeg will simply not create an audio track in the output file if there is no audio stream in the Y4M source. The resulting MKV will be a video-only file, which is perfectly valid and will play normally in any media player.
Change the -crf value to control quality versus file size. The CRF scale for libx264 runs from 0 (lossless) to 51 (worst quality). Lower numbers mean higher quality and larger files. For example, -crf 18 is considered visually lossless for most content and is a common choice when encoding from a pristine Y4M source where you want to preserve as much quality as possible. Use -crf 28 or higher if file size is the priority over quality.
Yes — Y4M headers embed metadata such as frame rate, interlacing, aspect ratio, and chroma subsampling (e.g., 4:2:0, 4:2:2, or 4:4:4). FFmpeg reads this header information and uses it during encoding, so the output MKV will reflect the correct frame rate and pixel format. However, if your Y4M source uses 4:4:4 chroma subsampling, note that libx264 with default settings may downsample to 4:2:0; you can preserve 4:4:4 by adding -pix_fmt yuv444p to the command.
Yes. On Linux or macOS you can loop over files in a terminal: for f in *.y4m; do ffmpeg -i "$f" -c:v libx264 -c:a aac -crf 23 -b:a 128k "${f%.y4m}.mkv"; done. On Windows PowerShell, use: Get-ChildItem *.y4m | ForEach-Object { ffmpeg -i $_.FullName -c:v libx264 -c:a aac -crf 23 -b:a 128k ($_.BaseName + '.mkv') }. The in-browser tool processes one file at a time, so the FFmpeg command shown on this page is especially useful for batch workflows on your desktop.

Technical Notes

Y4M (YUV4MPEG2) is one of the simplest video formats in existence — it is essentially a sequence of raw YUV frames with a plain-text ASCII header describing frame rate, dimensions, interlacing, and chroma subsampling. Because it is completely uncompressed, it is the gold standard for lossless inter-tool piping (e.g., between VapourSynth and x264) but entirely impractical for storage or distribution. When encoding to MKV with libx264 at CRF 23, the encoder operates in variable bitrate mode guided by perceptual quality targets, which is ideal for content originating from a lossless source since the encoder can allocate bits precisely where needed. The Matroska container (.mkv) is an excellent long-term archive format: it is an open standard, supports virtually any codec, and tolerates file corruption better than MP4 due to its EBML structure. One known limitation is that Y4M does not support audio, so the MKV output from this conversion will always be a video-only file unless you later add an audio track via remuxing. Additionally, if your Y4M source uses high bit-depth pixel formats (10-bit or 12-bit), the default libx264 build may need the -pix_fmt yuv420p10le flag and a high-bit-depth-enabled build of FFmpeg to encode correctly without automatic downsampling to 8-bit.

Related Tools