MKV to MP4 Converter

MKV to MP4 Converter
MKV to Mp4 Converter

Converting MKV to MP4 Made Easy: A Multi-threaded Python Solution

If you've ever needed to convert a batch of MKV video files to MP4 format, you know it can be a time-consuming process. That's why I created a Python script that not only automates this task but also makes it faster and more user-friendly with multi-threading and a progress bar. Let's dive into this handy tool!

The Problem
MKV (Matroska Video) files are great for their flexibility and support for multiple audio and subtitle tracks, but they're not as universally compatible as MP4 files. Many devices and platforms prefer MP4, making conversion a common need. Doing this manually with a tool like FFmpeg works, but it's tedious for multiple files and lacks progress feedback.

The Solution
Enter my MKV to MP4 Converter - a Python script that:

  • Converts multiple MKV files to MP4 simultaneously
  • Shows a live progress bar
  • Uses FFmpeg's stream copying for speed
  • Maintains original quality
  • Handles errors gracefully

Here's what the output looks like:
Found 5 MKV files to convert
Converting MKV to MP4: 100%|██████████| 5/5 [00:01<00:00, 3.85file/s]
Conversion complete!

How It Works
The script leverages several key technologies:

  1. FFmpeg: The powerhouse behind the actual conversion
  2. Python's ThreadPoolExecutor: For parallel processing
  3. tqdm: For that slick progress bar
  4. Stream Copying: Fast conversion without re-encoding

The multi-threading aspect is what really shines here. Instead of converting files one by one, it processes multiple files at once (default is 4 concurrent conversions, but you can tweak this). This makes it significantly faster, especially on modern multi-core systems.

Getting Started
Want to try it? It's simple:

  1. Install FFmpeg on your system
  2. Install Python and the tqdm package:
    pip install tqdm
  3. Grab the script from GitHub (link TBD)
  4. Set your input and output directories:
    moviesDir = "path/to/mkv/files"
    mp4Dir = "path/to/mp4/files"
  5. Run it!

Why I Built It
I had a folder of MKV files from my video collection that I wanted to use on various devices. Doing conversions manually was taking too long, and I wanted a way to see the progress. As a Python enthusiast, I saw this as a perfect opportunity to create something useful while practicing multi-threading concepts.

Performance Benefits
On my quad-core system, converting 10 average-sized MKV files went from about 20 seconds sequentially to just 6 seconds with 4 threads. The speedup isn't linear (disk I/O and other factors play a role), but it's a noticeable improvement when dealing with larger batches.

Customization
You can tweak the script to:

  • Adjust the number of simultaneous conversions (max_workers)
  • Change FFmpeg parameters if you need re-encoding instead of stream copying
  • Modify the output directory structure

Limitations

  • Works best with MKV files that have MP4-compatible codecs
  • Speed depends on your hardware and file sizes
  • Requires FFmpeg to be installed

What's Next?
I'm considering adding:

  • GUI interface option
  • Support for more file formats
  • Detailed conversion logs
  • Batch processing options

If you're interested in video file conversion or just want a faster way to handle your MKV files, give this script a try! Check out the full documentation in the README and let me know what you think. Have suggestions? I'm all ears!

Happy converting!

GitHub - jaccon/convertMkvToMp4: Script Python to convert movies Mkv to MP4
Script Python to convert movies Mkv to MP4. Contribute to jaccon/convertMkvToMp4 development by creating an account on GitHub.