MkvOpusEnc is a batch MKV audio processing toolchain with Python as the primary implementation.
The main script is MkvOpusEnc.py. It scans the current folder for .mkv files, re-encodes non-AAC/Opus audio to Opus, preserves metadata, and organizes outputs automatically.
The PowerShell script MkvOpusEnc.ps1 is a Windows compatibility version for users who do not have Python installed. It follows the same ffmpeg-based pipeline.
- Primary script: MkvOpusEnc.py
- Windows fallback: MkvOpusEnc.ps1
If both are available in your environment, use the Python script.
- Process all
.mkvfiles in the current directory (except files starting withtemp-output-). - Keep
aacandopusaudio tracks as-is (remux). - Re-encode other audio codecs to Opus.
- Normalize re-encoded tracks with ffmpeg
loudnorm(two-pass linear, true-peak aware). No SoX. - Preserve language, track title, and delay for re-encoded tracks.
- Optional Nightmode Dialogue downmix to stereo for 6+ channel tracks (
pan '<', so the mix cannot clip). - Write one log file per input to
conv_logs. - Move processed outputs to
completedand originals tooriginal.
- Python 3.8+
- ffmpeg
- ffprobe
- mkvmerge (MKVToolNix)
- opusenc (opus-tools)
- mediainfo
All tools must be available in your PATH.
For MkvOpusEnc.ps1, install PowerShell 7+ plus the same external tools above.
Install the media tools using your package manager, then verify they are on PATH.
Run the following commands to confirm each required tool is available:
ffmpeg -version
ffprobe -version
mkvmerge --version
opusenc --version
mediainfo --Versionwinget install Gyan.FFmpeg MoritzBunkus.MKVToolNix MediaArea.MediaInfoFor Opus tools (opusenc), install from:
sudo apt-get update
sudo apt-get install ffmpeg mkvtoolnix opus-tools mediainfoRun from a folder containing your .mkv files:
python MkvOpusEnc.pyWith Nightmode Dialogue downmix enabled:
python MkvOpusEnc.py --downmixCustom loudness targets:
python MkvOpusEnc.py --norm-i -18 --norm-tp -1.5--downmix: Nightmode Dialogue downmix of 5.1/7.1 to stereo before Opus encoding.--norm-i LUFS: target integrated loudness (default:-18.0).--norm-tp dBTP: true-peak ceiling (default:-1.5).
When at least one input file is found, the script creates:
completed/for processed MKV filesoriginal/for original source filesconv_logs/for per-file logs
Use MkvOpusEnc.ps1 when Python is unavailable:
./MkvOpusEnc.ps1
./MkvOpusEnc.ps1 -Downmix
./MkvOpusEnc.ps1 -Downmix -NormI -18 -NormTp -1.5The PowerShell version follows the same batch behavior and ffmpeg loudnorm pipeline as the Python script.