Make the stereo track play by default across your video library, without re-encoding.
4.3K
set_stereo_default makes the stereo audio track the default track in each video file of your library.
Many ripped and downloaded videos set a 5.1 or 7.1 surround track as the default audio track. On a TV, a soundbar, or a laptop, the dialogue is then often quiet and the effects are loud. set_stereo_default.py finds the stereo track (the audio track with 2 channels) in each file and makes it the default track. The script does not re-encode (compress again) the audio or the video, so the picture and the sound do not change.
This table shows the audio tracks of a typical movie before and after the change:
| Audio track | Before | After |
|---|---|---|
| English, 5.1 surround | โ Default | |
| English, stereo | โ Default | |
| Director's commentary, stereo |
The commentary track is also stereo, but the script never picks a commentary track. For the rules, see Picking the trackโ .
Warning
Use the script on a few files first. Start with `--dry-run`, and use `--backup` until you are satisfied with the results. This is beta software. I tested it carefully on my own library, but it is new.
The script has these features:
--dry-run shows each change before the script makes it. Before it replaces an original file, it makes sure that the new file is correct.--jobs N processes several files at the same time.--log-file writes the details to a file, so the console shows less.docker stop, the script stops and does not leave incomplete files.The Docker image contains the script and all the tools that it needs. It is available for amd64 and arm64 on Docker Hub (tronyx/set-stereo-default) and on GitHub (ghcr.io/tronyx/set-stereo-default). Each week, a new image is built with the security fixes from Alpine (the Linux system in the image). Before an image is published, a scanner looks for known vulnerabilities in it.
# 1. See what would change, without touching anything
docker run --rm -it -v "/path/to/videos:/videos" tronyx/set-stereo-default --dry-run
# 2. Try it for real on one folder, keeping backups
docker run --rm -it -v "/path/to/videos:/videos" tronyx/set-stereo-default "/videos/Some Show" --backup
# 3. Happy? Run it on everything, 3 files at a time
docker run --rm -it -v "/path/to/videos:/videos" tronyx/set-stereo-default --jobs 3
The -v option makes your video folder available inside the container at /videos. Docker gives everything after the image name to the script. The -it options show the progress bars and let the script ask the backup questionโ . The Docker guideโ tells you how to use several folders, keep the log, and run the script on a schedule. It also tells you how to run the script as the owner of the files, which most NFS shares need.
You must have Python 3.10 or newer and ffmpeg 4.4 or newer. For .mkv and .webm files, you must also have MKVToolNix 45 or newer. MKVToolNix 58 or newer is recommended. The tqdmโ package is optional. It shows the progress bars.
Download the script, and install tqdm:
git clone https://github.com/tronyx/Set-Stereo-Default.git
cd Set-Stereo-Default
pip install -r requirements.txt
Install ffmpeg and MKVToolNix:
| System | Command |
|---|---|
| Debian / Ubuntu | sudo apt install ffmpeg mkvtoolnix |
| macOS (Homebrewโ ) | brew install ffmpeg mkvtoolnix |
| Windows | winget install Gyan.FFmpeg and winget install MoritzBunkus.MKVToolNix |
Run the script:
# 1. See what would change, without touching anything
python3 set_stereo_default.py "/path/to/videos" --dry-run
# 2. Try it for real on one folder, keeping backups
python3 set_stereo_default.py "/path/to/videos/Some Show" --backup
# 3. Happy? Run it on everything
python3 set_stereo_default.py "/path/to/videos"
The script also searches the subfolders of each folder. You can also give it individual files. On Windows, type py instead of python3. Installationโ lists the tested versions and has a tip for Windows. Usageโ has all the other information.
| Option | What it does |
|---|---|
--dry-run | Show the changes, but do not make them |
--backup | Keep each original file as <name>.bak. Each backup uses as much disk space as its original file |
--prefer-lang LANG | Use the stereo track in this language (for example, en) if the file has one. If it does not, the usual rules apply |
--jobs N | Process up to N files at the same time (default: 1) |
--input-file FILE | Also process the folders that FILE lists, one folder on each line, in that order |
--log-file PATH | Write the details to a file. The console still shows warnings, errors, and the summary |
Usageโ describes all the options. The --help option also lists them.
Caution
Each change replaces the original file with a new file. Read these three results before you run the script on your full library:
- If another path is a hard link (a second name for the same file) to the file, that path keeps the old version. The two paths also stop sharing disk space. Sonarr, Radarr, and qBittorrent often make hard links. Run the script before you make the links, or make the links again after the script runs.
- If a torrent seeds the file, its hash check (the test that the data did not change) fails. The script does not re-encode the file, but the bytes of the new file are different. A cross-seed that uses the same path also fails. On a private tracker, this failure can look like a hit-and-run (a download that you did not seed).
- The script needs free disk space. While it runs, it needs about the size of your largest file. With
--backup, each backup also uses as much disk space as its file, until you delete the backup.For more information, see Limitationsโ and Disk spaceโ .
Tools such as mkvpropedit can change the flags directly in the original file. This is much faster than writing a new file. But in MKV files, such an edit can move the track list to the end of the file. Then Windows Explorer cannot show a thumbnail. A new file also keeps the original safe, because the script tests the new file before it replaces the original in one step. Why not edit the file in place?โ explains all the reasons.
| Page | Contents |
|---|---|
| ๐ฆ Installationโ | Requirements, the tested versions, installation on Linux, macOS, and Windows, and the disk space that the script needs |
| ๐ Usageโ | The files that the script processes and their order, lists of folders, all the options, sample output, and exit codes |
| ๐ณ Dockerโ | Your videos in the container, several folders, file owners, the log, schedules, and image updates |
| ๐ How it worksโ | How the script picks the track and changes a file, why it does not edit files in place, backups, symlinks, file owners, file dates, temporary files, and limitations |
| ๐ฉบ Troubleshootingโ | What each message means, and what to do |
| ๐งช How it is testedโ | The tests, and the tests that GitHub runs on each change |
For each file that the script skips or does not fix, it writes a line with the reason. At the end of the run, it lists again each file that got a warning and each file that it did not fix. It groups the files that it did not fix by the action that you must take. Troubleshootingโ explains each message. If a result still looks wrong, open an issueโ .
Each change goes through tests on Linux, macOS, and Windows, and in the Docker image on amd64 and arm64. The tests use ffmpeg versions from 4.4 to the newest release, and mkvmerge versions from 45 to the newest release. There is a test for each case that the script handles. Other tests use random track layouts, stop the script at random times, and kill the script while it changes a file. After each of these tests, each file must be correct or exactly the same as before. For more information, see How it is testedโ .
You can send bug reports, ideas, and pull requests. The contributing guideโ tells you how. Do not open an issue to report a security vulnerability, because issues are public. Use the procedure in the security policyโ instead. The changelogโ lists the changes in each release.
This script was largely written with Claudeโ , Anthropic's AI coding assistant. I described what I needed, directed the design, and asked for changes across many iterations rather than writing most of the code by hand. Every feature went through real testing before landing here, and the safety measures (dry-run mode, temp-file-first remuxing, checking every remux before it replaces the original) are exactly the kind of thing I insisted on, because this touches a media library I actually care about. Today the test suite covers both the script's logic and real video files across several ffmpeg and mkvmerge versions.
I'd rather say that plainly than let it pass as fully hand-written. There's a lot of AI-generated code floating around that hasn't been reviewed or tested and ends up breaking people's setups, and I don't want this to be mistaken for that. If something looks off, please open an issueโ .
The license is MIT. See LICENSE.mdโ .
Content type
Image
Digest
sha256:72e30ce47โฆ
Size
83.8 MB
Last updated
about 3 hours ago
docker pull tronyx/set-stereo-default