EDIT: Updated the scripts slightly to add language metadata, add SL & SR to the night mode script (sometimes channels are called BL BR or SL SR) (thanks @leelynds). Corrected the bitrate on both scripts. The .bat files have been updated too.
EDIT 2: Added FLC (front left centre) & FRC (Front right centre) channels to the Nightmode mix-down. This means all channels are there for a 7.1 mix-down now. Also, I’ve added 2 more scripts which are the exact same as the first 2, but also includes the ‘loudnorm’ filter, which normalizes the new mix-down track to EBU R128 (industry standard). Note that the ‘LoudNorm’ scripts are slower than the others because it adds another process.
EDIT 3: As an alternate to the ‘NightMode’ scripts I have added one more script which adds actual DRC (Dynamic Range Compression) to the mixdown instead of just mixing the FL, FR, BL(SL), BR(SR), FLC, FRC, FC, LFE channels at different volumes (thanks @OttoKerner) . This is most similar to what a soundbar might do in order to reduce the loud & increase the quiet parts of a movie. Try out both to see which works best for you, and be sure to dig into the settings to find the sweet spot for your setup 
Hey all, I was looking for a simple solution to a few issues I was having:
- AAC 5.1 doesn’t work too well on Apple TV.
- Like many others, I get annoyed when a movie is too loud during action scenes, but too quiet during dialogue. Especially at night.
I started looking into this after I watched ‘Rumble in the Bronx’ (Classic JC, amirite?) and got really annoyed at how loud the sound effects were while the dialogue was really quiet. Suffice to say, after searching for a solution, it turns out that movie just has a really bad sound mix (who’d have thought huh?!) so my search for a solution to fix the problem was all for naught, but I came across the Apple TV AAC 5.1 issue around the same time, so I figured I’d keep looking for a solution & just share them with you guys anyway.
I wanted something that was quick & that could be done in batches so I don’t have to manually edit each file.
BOTH THESE SCRIPTS ARE VERY SIMILAR, BUT ARE DESIGNED FOR DIFFERENT USES.
NOTE: I’m not a coder, I’ve just pieced this together by scouring the internet for related problems & piecing together. Although, I do feel like I have a slightly better grasp on ffmpeg now, and boy is it powerful!
HOW FAST IS IT AT PROCESSING FILES?
In my testing, the scripts achieved the follow speeds (ymmv depending on setup):
- Downmix_Stereo.bat = 47x
- Nighmode_Stereo.bat = 47x
- Downmix_Stereo_LoudNorm = 7x
- Nightmode_Stereo_LoudNorm = 18x
- Downmix_Stereo_DRC+LoudNorm = 6.6x
HOW TO USE THESE SCRIPTS?
Since the scripts are ffmpeg, they should work on most systems, however (and remember I’m no coder) there are some parts of the scripts that probably wont work unless you’re on Windows. I’ll try and point out these parts of the scripts at the end.
You need to install ffmpeg. I set it up as an environment variable so I could just reference ‘ffmpeg’ in cmd & I don’t have to keep pointing to where its located each time, the article I linked to shows how to do that.
These scripts are designed to work with .mkv files. Though you can easily mod this work with .mp4 if you’d like instead.
To run a script:
- save it as a .bat file (I’ll include links to those below too for simplicity)
- Paste the .bat into the folder with all the videos you want to run through the script
- Double click it & watch it do its thing
SCRIPT 01 - 5.1/7.1 to Stereo Mixdown
What does it do?
- Keeps all existing video, audio (up to 6 tracks), subtitles & chapters.
- Creates a stereo mixdown of the first audio track (which is assumed to be a 5.1 track, not much use using this on a video which is already stereo).
- Names the new track ‘Eng 2.0 Stereo’
- Inserts the new track as the second track in the audio stream. So if you have multiple tracks (such as commentary etc), those tracks will be moved below the new track.
Example
Lets say the input file looks like the following:
Name: input.mkv
- Video Stream
- 5.1 Audio Track
- Commentary Audio Track
- Subtitle (eng)
- Subtitle (fr)
The output, after being run through this script will look like the following:
(note: A sub-folder called ‘ffmpegOut’ will be created in whatever folder you run this script in, this is where the output file will be saved, so there is no overwriting files ****)
Name: input_Stereo.mkv (file name now has ‘_Stereo’ appended to it)
- Video Stream
- 5.1 Audio Track
- Stereo Audio Track (downmix of the 5.1 track)
- Commentary Audio Track
- Subtitle (eng)
- Subtitle (fr)
The Script
if not exist "ffmpegOut\" MD "ffmpegOut"
for %%A IN ("*.mkv") Do ffmpeg -y -i "%%A" -map 0:v -c:v copy -map 0:a:0? -c:a:0 copy -map 0:a:0? -c:a:1 aac -b:a:1 192k -ac 2 -metadata:s:a:1 title="Eng 2.0 Stereo" -map 0:a:1? -c:a:2 copy -map 0:a:2? -c:a:3 copy -map 0:a:3? -c:a:4 copy -map 0:a:4? -c:a:5 copy -map 0:a:5? -c:a:6 copy -map 0:a:6? -c:a:7 copy -map 0:s? -c:s copy "ffmpegOut/%%~nA_Stereo.mkv"
pause
SCRIPT 02 - 5.1/7.1 to NIGHTMODE Stereo Mixdown
What does it do?
- Keeps all existing video, audio (up to 6 tracks), subtitles & chapters.
- Creates a ‘nightmode’ stereo mixdown of the first audio track (which is assumed to be a 5.1 track, not much use using this on a video which is already stereo).
- Names the new track ‘Eng NightMode’
- Inserts the new track as the second track in the audio stream. So if you have multiple tracks (such as commentary etc), those tracks will be moved below the new track.
Example
Lets say the input file looks like the following:
Name: input.mkv
- Video Stream
- 5.1 Audio Track
- Commentary Audio Track
- Subtitle (eng)
- Subtitle (fr)
The output, after being run through this script will look like the following:
(note: A sub-folder called ‘ffmpegOut’ will be created in whatever folder you run this script in, this is where the output file will be saved, so there is no overwriting files ****)
Name: input_Stereo.mkv (file name now has ‘_Stereo’ appended to it)
- Video Stream
- 5.1 Audio Track
- NightMode Audio Track (downmix of the 5.1 track)
- Commentary Audio Track
- Subtitle (eng)
- Subtitle (fr)
What is ‘NightMode’?
People with ‘cheaper’ 2.1 audio setups often find that 7.1/5.1 audio tends to have LOUD music/sound effects but QUIETdialogue. ‘NightMode’ attempts to fix this (while keeping the original track of course!) by re-mapping the audio channels of the 7.1/5.1 track to favor the centre channel (where the dialogue comes from mostly).
Here’s what it is doing:
In each (Left or Right) Channel it is putting:
- 100% of the Front Centre Channel
- 30% of the Front L/R & Back L/R Channel
- 30% of the Front L/R Centre Channels
- 60% of the LFE Channel
Some of you may find the default settings too aggressive so feel free to tweak them to your liking by tweaking the following section of the script (maybe try 0.60 instead?): FL=FC+0.30*FL+0.30*FLC+0.30*BL+0.30*SL+0.60*LFE|FR=FC+0.30*FR+0.30*FRC+0.30*BR+0.30*SR+0.60*LFE
FC = Front Centre
FLC = Front Left Centre
FL = Front Left
BL = Back Left
SL = Side Left (same as Back Left)
FR = Front Right
FRC = Front Right Centre
BR = Back Right
SR = Side Right (same as Back Right)
LFE = Low Frequency Effects
Just play with the multipliers on each of those settings until you get something that suits your needs.
Notes
Because of the way these scripts are set up, they are able to copy up to 6 audio tracks. If there are more tracks in the video file than that and you want to keep them all, you’ll have to mod the script slightly. I’ll give a breakdown of what each component of the script does at the end, so you can mod it however you like.
The Script
if not exist "ffmpegOut\" MD "ffmpegOut"
for %%A IN ("*.mkv") Do ffmpeg -y -i "%%A" -map 0:v -c:v copy -map 0:a:0? -c:a:0 copy -map 0:a:0? -c:a:1 aac -b:a:1 192k -ac 2 -filter:a:1 "pan=stereo|FL=FC+0.30*FL+0.30*FLC+0.30*BL+0.30*SL+0.60*LFE|FR=FC+0.30*FR+0.30*FRC+0.30*BR+0.30*SR+0.60*LFE" -metadata:s:a:1 title="Eng NightMode" -metadata:s:a:1 language=eng -map 0:a:1? -c:a:2 copy -map 0:a:2? -c:a:3 copy -map 0:a:3? -c:a:4 copy -map 0:a:4? -c:a:5 copy -map 0:a:5? -c:a:6 copy -map 0:a:6? -c:a:7 copy -map 0:s? -c:s copy "ffmpegOut/%%~nA_NightMode.mkv"
pause
SCRIPT 03/04 - 5.1/7.1 to Stereo Mixdown (LoudNorm) / NIGHTMODE Stereo Mixdown (LoudNorm)
These are the exact same as the first 2, but also includes the ‘loudnorm’ filter, which normalizes the new mix-down track to EBU R128 (industry standard).
Note
The ‘LoudNorm’ scripts are significantly slower (tough still fast!) than the others because it adds another process.
Script 03
if not exist "ffmpegOut\" MD "ffmpegOut"
for %%A IN ("*.mkv") Do ffmpeg -y -i "%%A" -map 0:v -c:v copy -map 0:a:0? -c:a:0 copy -map 0:a:0? -c:a:1 aac -ac 2 -filter:a:1 "loudnorm" -ar:a:1 48000 -b:a:1 192k -metadata:s:a:1 title="Eng 2.0 Stereo" -metadata:s:a:1 language=eng -map 0:a:1? -c:a:2 copy -map 0:a:2? -c:a:3 copy -map 0:a:3? -c:a:4 copy -map 0:a:4? -c:a:5 copy -map 0:a:5? -c:a:6 copy -map 0:a:6? -c:a:7 copy -map 0:s? -c:s copy "ffmpegOut/%%~nA_Stereo_LoudNorm.mkv"
pause
Script 04
if not exist "ffmpegOut\" MD "ffmpegOut"
for %%A IN ("*.mkv") Do ffmpeg -y -i "%%A" -map 0:v -c:v copy -map 0:a:0? -c:a:0 copy -map 0:a:0? -c:a:1 aac -ac 2 -filter:a:1 "pan=stereo|FL=FC+0.30*FL+0.30*FLC+0.30*BL+0.30*SL+0.60*LFE|FR=FC+0.30*FR+0.30*FRC+0.30*BR+0.30*SR+0.60*LFE,loudnorm" -ar:a:1 48000 -b:a:1 192k -metadata:s:a:1 title="Eng NightMode" -metadata:s:a:1 language=eng -map 0:a:1? -c:a:2 copy -map 0:a:2? -c:a:3 copy -map 0:a:3? -c:a:4 copy -map 0:a:4? -c:a:5 copy -map 0:a:5? -c:a:6 copy -map 0:a:6? -c:a:7 copy -map 0:s? -c:s copy "ffmpegOut/%%~nA_NightMode_LoudNorm.mkv"
pause
SCRIPT 05 - 5.1/7.1 to Stereo Mixdown with DRC + LoudNorm
What does it do?
- Keeps all existing video, audio (up to 6 tracks), subtitles & chapters.
- Creates a ‘DRC’ stereo mixdown of the first audio track (which is assumed to be a 7.1 or 5.1 track, not much use using this on a video which is already stereo).
- Names the new track ‘Eng 2.0 Stereo DRC’
- Inserts the new track as the second track in the audio stream. So if you have multiple tracks (such as commentary etc), those tracks will be moved below the new track.
What is ‘DRC’?
Similar to ‘NightMode’, DRC (Dynamic Range Compression) is another way of reducing the loudest parts of a movie. DRC is the ‘proper’ way of doing this as it actually compresses the ‘Dynamic Range’ of the audio. A good AV Receiver includes similar DRC controls.
The Script
if not exist "ffmpegOut\" MD "ffmpegOut"
for %%A IN ("*.mkv") Do ffmpeg -y -i "%%A" -map 0:v -c:v copy -map 0:a:0? -c:a:0 copy -map 0:a:0? -c:a:1 aac -ac 2 -filter:a:1 "acompressor=ratio=4,loudnorm" -ar:a:1 48000 -b:a:1 192k -metadata:s:a:1 title="Eng 2.0 Stereo DRC" -metadata:s:a:1 language=eng -map 0:a:1? -c:a:2 copy -map 0:a:2? -c:a:3 copy -map 0:a:3? -c:a:4 copy -map 0:a:4? -c:a:5 copy -map 0:a:5? -c:a:6 copy -map 0:a:6? -c:a:7 copy -map 0:s? -c:s copy "ffmpegOut/%%~nA_Stereo_DRC.mkv"
pause
BREAKDOWN OF THE SCRIPTS
if not exist "ffmpegOut\" MD "ffmpegOut"
This is the windows command to create a folder (within the folder you loaded the script) called “ffmpegOut”. If the folder already exists, it will not make the folder. Just replace “ffmpegOut” if you want to call the folder something else.
for %%A IN ("*.mkv") Do ffmpeg -y -i "%%A"
for %%A IN ("*.mkv") This is telling the script to find any .mkv file within the folder you run the script in. The %%A is a stand in for your mkv’s file name. *.mkv means it will only run .mkv files through the script. If you need it to work with mp4’s, just replace ‘mkv’ with ‘mp4’.
Do ffmpeg -y -i "%%A" This is just telling the script to open ffmpeg & input your file (note the %%A is there again)
-map 0:v -c:v copy This is telling the script to copy the video track (no re-encoding). v = Video
-map 0:a:0? -c:a:0 copy This is copying the first audio track & keeping it assigned as the first track. a = Audio
-map 0:a:0? -c:a:1 aac -b:a:1 192k -ac 2 -metadata:s:a:1 title="Eng 2.0 Stereo" This is taking the first audio track again, converting it to ‘AAC’ with a bitrate of 192k & 2 audio channels (stereo), and assigning it as the second audio track. It is then giving the track a title of “Eng 2.0 Stereo”
-map 0:a:1? -c:a:2 copy -map 0:a:2? -c:a:3 copy -map 0:a:3? -c:a:4 copy -map 0:a:4? -c:a:5 copy -map 0:a:5? -c:a:6 copy -map 0:a:6? -c:a:7 copy This is copying all other audio track that may be in the video file ( ? essentially means, “if it exists, do this. If it doesn’t, don’t worry about it”), and also moving each of them down one slot in the audio track order (so that the newly created track can be the second track). If, you have a video file that has even more tracks than this that you’d like to copy, just add extra -map 0:a:6? -c:a:7 copy sections, but increment the numbers each time. Eg: -map 0:a:7? -c:a:7 copy -map 0:a:8? -c:a:9 copy etc.
-map 0:s? -c:s copy This copies all subtitles (if they exist). s = Subtitles.
"ffmpegOut/%%~nA_Stereo.mkv" This saves the output file in the ffmpegOut folder & gives it the same name as the original but with ‘Stereo’ at the end. Because the files will be saved in a subfolder, you could remove ‘_Stereo’ so that the output has the exact same name as the input, but I added this as additional protection against overwriting or accidentally deleting the original file.
loudnorm Normalizes the audio to EBU R128 (industry standard). You can read more about this here
-ar:a:1 48000 This sets the new track’s sample rate to 48000. We need to use this when using the loudnorm filter because loudnorm needs to re-sample the audio 192 kHz in order to work, so this ensures it is re-sampled it to 48000 before output.
acompressor=ratio=4 These are the audio compressor settings used on the DRC script. You can read more about this here
ffmpeg_Audio_Scripts.zip (1.9 KB)
I don’t include the LFE channel, because I’m not convinced it’s necessary in a stereo track, My opinion, though.