GIF to MKV Converter
Learn how to convert GIF files to MKV video format using FFmpeg or HandBrake, with a command builder and format comparison.
FFmpeg Command Builder
Fill in the fields and copy a ready-to-run FFmpeg command.
Generated Command
ffmpeg -i animation.gif -c:v libx264 -crf 23 -pix_fmt yuv420p animation.mkv
Re-encodes all GIF frames to H.264 inside an MKV container. The -pix_fmt yuv420p flag ensures compatibility with most players.
GIF vs MKV — Format Comparison
| Feature | GIF | MKV |
|---|---|---|
| Released | 1987 (CompuServe) | 2002 (Open source) |
| Color depth | 256 colors per frame | 16.7M+ (full color) |
| Compression | LZW (poor for video) | H.264/H.265/AV1 |
| Typical file size | Large (5–50 MB) | Small (0.5–5 MB) |
| Audio support | No | Yes (unlimited tracks) |
| Transparency | 1-bit (on/off) | Full alpha (with codecs) |
| Max resolution | 65535 x 65535 px | Unlimited |
| Open standard | Yes (expired patents) | Yes (Matroska) |
Quick FFmpeg Reference
Basic H.264 conversion
ffmpeg -i input.gif -c:v libx264 -crf 23 -pix_fmt yuv420p output.mkv
H.265 — smaller file size
ffmpeg -i input.gif -c:v libx265 -crf 28 -pix_fmt yuv420p output.mkv
Force 15 fps output
ffmpeg -i input.gif -r 15 -c:v libx264 -crf 23 -pix_fmt yuv420p output.mkv
Scale to 640px wide
ffmpeg -i input.gif -vf scale=640:-2 -c:v libx264 -crf 23 -pix_fmt yuv420p output.mkv
Batch convert (Linux/macOS)
for f in *.gif; do ffmpeg -i "$f" -c:v libx264 -crf 23 -pix_fmt yuv420p "${f%.gif}.mkv"; done
Batch convert (Windows CMD)
for %f in (*.gif) do ffmpeg -i "%f" -c:v libx264 -crf 23 -pix_fmt yuv420p "%~nf.mkv"
Using HandBrake (GUI Method)
- 1 Download and install HandBrake from handbrake.fr (free, Windows/macOS/Linux).
- 2 Open HandBrake and click "Open Source," then select your .gif file.
- 3 In the "Summary" tab, set the container to "MKV File."
- 4 Go to the "Video" tab, choose H.264 or H.265 as the video codec, and set a quality value (RF 22–28 is typical).
- 5 Click "Browse" next to the output destination and choose where to save the .mkv file.
- 6 Click "Start Encode" and wait for the conversion to finish.
Copied!
Summary
Learn how to convert GIF files to MKV video format using FFmpeg or HandBrake, with a command builder and format comparison.
How it works
- FFmpeg reads each frame of the GIF and decodes the indexed-color palette data.
- The frames are passed through a video encoder (H.264 or H.265) with optional filters for scaling or frame-rate adjustment.
- The encoded video stream is written into an MKV container with no audio track (GIFs carry no audio).
- Use the command builder below to generate an FFmpeg command matched to your GIF.
- Run the command in your terminal; most GIF-to-MKV conversions complete in under a second.
Use cases
- Shrink large GIF files by up to 90% for storage or sharing.
- Convert GIF animations to MKV for embedding in video projects.
- Preserve smooth frame rates by re-encoding GIF loops as proper video.
- Archive GIF collections in a future-proof container format.
- Convert GIFs to MKV before uploading to video platforms.
- Improve color fidelity by escaping GIF's 256-color palette limit.
- Loop a GIF as a seamless MKV background video.
- Batch-convert a folder of GIFs to MKV with one FFmpeg script.
Frequently Asked Questions
Last updated: 2026-06-11 ·
Reviewed by Nham Vu