Jump to content

Windows script to insert new AAC audio into MKV container


rbjtech

Recommended Posts

rbjtech

In an effort to make all my media as 'streaming' friendly as possible (to eliminate transcoding) I've been developing a script to automate adding a new default AAC Audio track into MKV's and thought I'd share it on here as I think it works rather well. (but test/use at your own risk..)

 

ps - I know there are tools online that do this (Popcorn etc) but none gave me the level of control that I wanted.

 

The script reads a text file containing the UNC/filenames that you want converted -

 

a) Checks the file using ffprobe to determine the 1st Audio track - if mp3 or AAC already, then it skips the file.

b ) Uses ffmpeg to convert the 1st Audio track (from AC3, DTS, HD Audio etc) to Stereo AAC and also bumps the volume to equal the DTS/AC3 (approx).

c) Inserts this track as Default Audio - retaining all the other Audio tracks as well.

d) Note - this script does not retain internal subtitles - this is by design as I use external .srt only - again to maximise streaming/device non-transcode compatibility. 

e) Checks the success of ffmpeg and if no errors - then deletes the original file and renames the temp file to the original filename.  ** REM these lines out if you want to retain the original **

f) Logs everything including keeping the ffmpeg log.

 

To generate the input file (films.txt) then just use 'dir /a-s /b /s "\\server\share\directory\*.mkv" > films.txt' from the root and this will list all the MKV files in all sub-directories for example.

 

I suggest testing on a sample file first to ensure it does what you expect - but this has been extensively tested on all my MKV files (1000's..) and thus far has not failed once.

 

To use :-

 

rename the batchaac.bat.txt file to .bat 

modify the .bat file (notepad etc) with the location of your ffmpeg/ffprobe - not sure if you can use emby's version - untested.

example films.txt given but obviously generate your own ;)

run 'batchaac' from a command prompt - it will create a \batch and \batch\logs directory to keep the logs\temp files in.

 

Enjoy.

films.txt

batchaac.bat.txt

Edited by rbjtech
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...