Skip to content

Instantly share code, notes, and snippets.

@seamonkey420
Last active June 14, 2025 16:05
Show Gist options
  • Select an option

  • Save seamonkey420/a32ddbf97914d09a7590c8b22def7b5a to your computer and use it in GitHub Desktop.

Select an option

Save seamonkey420/a32ddbf97914d09a7590c8b22def7b5a to your computer and use it in GitHub Desktop.
ffmpeg script to convert main audio stream to aac while copying video and subtitles. windows cmdline based.
:: Can be integrated into explorer shell
:: and right click menus too
:: seamonkey420
:: Requirements: copy ffmpeg to c:\windows\system32
:: env variables needed to parse spaces in file paths!
:: pick one of the below sets of code, top replaces all audio with an ac3 one
:: bottom adds an ac3 stream and retains everything else, video, subs, audio.
setlocal EnableExtensions DisableDelayedExpansion
::get filename and extensions as variables
set _name=%~n1
set _ext=%~x1
::add aac audio
ffmpeg -i "%_name%%_ext%" -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 384k -map 0:s? -c:s copy "%_name%.NEW%_ext%"
@seamonkey420
Copy link
Author

seamonkey420 commented May 29, 2020

NOTES:
Just create txt file, paste code, save. rename to a .cmd or .bat extension. Then drop mkv files on file and it will create new file in same folder as original mkv file w/new.mkv extension. Notes about being able to right click on mkv or any file and try to convert main audio to ac3 5.1. 2nd command to now retain original audio and create 2nd stream in ac3.

MORE NOTES:
Can be integrated into explorer shell and right click menus too!
Requirements: copy ffmpeg to c:\windows\system32
env variables needed to parse spaces in file paths!

Adding as a right-click menu option notes:

  • create new Key here w/name you want command to be:

  • \HKEY_CLASSES_ROOT\ * \shell\Convert MKV to AC3 Audio

  • create new Key under prev key called "command"

  • \HKEY_CLASSES_ROOT\ * \shell\Convert MKV to AC3 Audio\command

  • edit default value to point to script w/%1 variable

  • ie cmd.exe /k ""C:\users\test\convert.bat" "%1""
    ---note the double quotes around the bat and %1, needed to handle spaces in file names!!

  • copy the below two lines only; these are just notes! Just create txt file, paste code, save. rename to a .cmd or .bat extension.

  • Then drop mkv files on file and it will create new file in same folder as original mkv file w/new.mkv extension.

setup automator service on mac to do a similar thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment