Repair corrupted video files with command-line tools: FFmpeg, MP4Box, and mkvtoolnix. Commands, scripts, and device-specific tips for safe, repeatable recovery.
Corrupted or unplayable video files are a common headache — from interrupted recordings on smartphones and action cams to archive footage that won't seek or exhibits audio/video sync problems. Command-line video repair software gives you precise, repeatable tools to diagnose and fix those failures: rebuild container indexes, remux streams losslessly, extract raw essence, or selectively re-encode damaged tracks. Unlike GUI utilities, command-line tools excel at batch jobs, headless servers, and automated pipelines, making them ideal for media professionals, system administrators, and power users who need reliable, scriptable recovery workflows.
This guide walks through the most effective open-source and commercial command-line options (FFmpeg, MP4Box/GPAC, mkvtoolnix, and vendor tools), common repair techniques, diagnostic commands, device-specific tips, automation examples, and ready-to-copy command snippets. You'll learn how to probe files with ffprobe, decide between remuxing and re-encoding, use reference samples from the same camera, and when to escalate to GUI or commercial recovery tools. Follow the practical examples and best practices here — always working on copies and keeping diagnostics — to make video recovery predictable, auditable, and safe.
Command-line video repair tools let you inspect, diagnose, and fix corrupted or unplayable video files using text commands instead of a graphical interface. They're built for precision, repeatability, and integration into automated workflows — qualities that make them a practical choice for hobbyists, media professionals, and system administrators alike.
When to prefer GUI or services:
Best practice:
Open-source command-line tools are the backbone of most video-repair workflows. They're free, actively maintained, scriptable, and cover the majority of container and codec issues you'll face. Below are the primary tools, practical commands, and when to use each.
FFmpeg is the most versatile multimedia toolkit for probing, remuxing, and re-encoding. Common repair approaches use remuxing (no re-encode) first, then selective re-encoding if necessary.
When to use FFmpeg: general repairs, rebuilding indexes, converting codecs, batch scripts, and when you need full control over stream handling.
MP4Box (part of GPAC) focuses on MP4/ISOBMFF containers and is excellent for fixing indexing, fragmented files, and reconstructing MP4 atoms.
When to use MP4Box: MP4/MOV container corruption, missing moov atom recovery, fragmented file reconstruction, and workflow requiring ISOBMFF-specific manipulations.
MKVToolNix is the go-to for Matroska (MKV) containers. It exposes muxing, header edits, and track extraction tools.
When to use mkvtoolnix: MKV files with header/index problems, reordering/removing corrupted tracks, and cases where container-specific features (subtitles, chapters) must be preserved.
avconv (from the Libav fork) offers an FFmpeg-like interface on some platforms. Historically a separate project, its feature set and command compatibility vary.
When to use avconv/libav: only if it is the maintained multimedia tool on your system or legacy scripts depend on it. For new workflows, choose FFmpeg for better community support and parity with tutorials.
Summary recommendation: Start with FFmpeg for most repairs (probe → remux → selective re-encode). Use MP4Box for MP4-specific atom/index fixes and mkvtoolnix for Matroska containers. Reserve avconv only for legacy environments. Always work on copies and verify output before replacing originals.
Professional, paid tools can simplify difficult recoveries, add vendor support, and integrate into enterprise pipelines. Commercial CLI solutions often combine automated heuristics, richer diagnostics, and support contracts—useful when files are critical or open-source tools can't fully recover data.
Note: Exact command names and flags vary by vendor and product version—consult vendor docs. Choose commercial CLIs when you need vendor support, guaranteed recovery attempts, or advanced heuristics not available in open-source tools.
When evaluating commercial command-line video repair tools, prioritize these features:
Decision guidance:
One of the most common video repair techniques is rebuilding the container structure or index without re-encoding the video. This preserves original quality while fixing many playback issues.
Re-muxing (changing container without re-encoding) is always the first approach to try as it preserves quality and is fast. Only re-encode when:
When dealing with corrupted files missing important metadata, using a reference file from the same device can provide the missing parameters:
ffmpeg -i broken.mp4 -c copy fixed.mp4MP4Box -add broken.mp4 -new fixed.mp4-c copy) and inspect with codec-specific tools.ffmpeg -i broken.mp4 -c copy -fflags +genpts fixed.mp4ffmpeg -r 29.97 -i broken.mp4 -c:v libx264 fixed.mp4-copyts/-start_at_zero carefully when aligning streams.ffmpeg -fflags +discardcorrupt -i broken.mp4 -c copy fixed.mp4ffmpeg -i broken.mp4 -c:v libx264 -crf 18 fixed.mp4-ss/-to and concatenate.-ignore_unknown and -fflags +discardcorrupt to salvage tails.ffmpeg -i broken.mp4 -map 0:v -map 0:a -c copy fixed.mp4ffmpeg -i broken.mp4 -c:v copy -c:a aac fixed.mp4Quick troubleshooting checklist:
ffprobe -print_format json -show_format -show_streams and inspect duration, codec, and stream presence.ffmpeg -i in -c copy out (fast, non-destructive).Summary: ffprobe + ffmpeg reveal whether issues are container-level (fixable by remux/index rebuild) or bitstream-level (may need re-encoding or vendor tools). Map errors to the targeted fixes above, always operate on copies, and log diagnostics for repeatable, auditable recovery.
Different containers, codecs, and recording devices produce distinct failure modes. Knowing common device quirks and codec behaviors lets you choose targeted repair steps that save time and preserve quality.
Common failures:
Each format has specific quirks:
-c copy to rebuild indexes.Command-line tools are powerful, but they aren't always the fastest or safest path for every damaged video. Use GUI or online services when manual inspection, guided recovery, or vendor heuristics are required.
GUI desktop tools (good for single-file recovery and visual inspection):
Online services (convenient but check privacy):
Enterprise/commercial recovery suites:
Hybrid approach:
Quick decision guide:
Always test any recommended tool on copies and record diagnostics (ffprobe JSON, logs) before and after repair attempts.