PDA

View Full Version : .mkv container with h264 mass convert aac audio to mp3


gavogavo
14th May 2009, 17:35
I have a huge amount of videos with .mkv containers and h264 video with aac audio. I need to demux all the audio and reconvert it to .mp3 then mux them back in. Without reencodeing anyone have any ideas on how the easiest way to batch do this.

Inspector.Gadget
14th May 2009, 18:18
Out of curiosity, why do you want to do this?

gavogavo
15th May 2009, 01:50
reduce the load on xbox xbmc, when I play it with aac i have drop framed aac takes alot of cpu out of xbmc.

Sharktooth
15th May 2009, 03:22
LC-AAC is not much more complex to decode than MP3

gavogavo
17th May 2009, 23:22
will xbmc cpu says different

Skelsgard
19th May 2009, 01:27
If you're running on Windows you can use a DOS batch file, but it is absolutely contradictory to "reconvert" aac to mp3 without "reencoding".

For simplicity, put lame.exe, neroaacdec.exe, mp4box.exe, mkvextract.exe and mkvmerge.exe (from the mkvtoolnix pack) in the same folder, then put this code into a .bat file
FOR /F "tokens=*" %%a IN ('dir /b *.mkv') DO call exec.bat "%%~na%%~xa" "%%~na"
name it wathever you want (i.e: whatever.bat).

Then put this code in a second .bat
mkvextract tracks %1 2:%2_temp.aac
for /f "tokens=*" %%a IN ('dir /b *.aac') DO mp4box -import "%%a" "%%~na.mp4"
for /f "tokens=*" %%b IN ('dir /b *.mp4') DO neroaacdec -if "%%b" -of "%%~nb.wav"
for /f "tokens=*" %%c IN ('dir /b *.wav') DO lame --vbr-new -V 3 -m j -q 0 --priority 0 "%%c" "%%~nc.mp3"
for /f "tokens=*" %%d IN ('dir /b *.mkv') DO mkvmerge -o "%%~nd_done.mkv" -d 1 -A -S "%%d" -a 0 -D -S "%%~nd_temp.mp3" --track-order 0:1,1:0
del *temp.*

and save it as exec.bat (if you wanna name it other than that, remember to change the reference to this .bat in the first one)

Then put your source file to be transcoded and run whatever.bat

It will do all the work automatically for you.
Notes: MP4box is needed to remux the raw AAC with ADTS header back to MP4 as mkvextract doesn't support MP4 output (only raw AAC) and neroaacdec doesn't seem to accept this raw aac.
It would have been cool also if neroaacdec would do stdout so no need for intermediate WAV file while transcoding mp4->mp3.

You need to tweak the lame settings to suit your needs. I pre-chose VBR -V 3, as it provides a good balance between size and quality, but you might want to try something higher or lower depending on your needs (less space or higher quality).

But the script works for me flawlessly.
As I don't do batch scripting, I have no idea if this batch can be optimized in any way (super ultra beginner style :D).
Anyone who can add something or trim anything unnecessary, please do so.

Later :)

gavogavo
10th August 2009, 06:28
any easier ways with guis?

Skelsgard
11th August 2009, 01:45
You copy the text, paste it in a .txt file, put the .txt in the same folder as the mkv files, then rename it to .bat, then run the .bat, and everything is done without you having to do or touch or type anything again.
I don't wanna sound like a jerk, but I don't think it gets any easier than this, dude.
I'm not aware of any one-app or gui that will do the batch processing you want.

gavogavo
12th August 2009, 05:08
When I run it mp4box says it crash then it stops working. How do I also change the script to convert to cbr?

nurbs
12th August 2009, 08:35
You can convert to CBR by reading the lame documentation and replacing "--vbr-new -V 3" with whatever switch tells the encoder to do a CBR encode.

TheFluff
12th August 2009, 09:07
I dunno why that script uses mp4box at all, just use faad.exe and decode the raw aac directly instead...

Skelsgard
13th August 2009, 05:39
I dunno why that script uses mp4box at all, just use faad.exe and decode the raw aac directly instead...

Cause it's using neroaacdec. I don't know if faad.exe supports all AAC modes, I haven't use faad for ages since I was waiting for a new faad version for a long time till I gave up, so to be on the safe side....
If faad.exe does support every aac mode, than this:
for /f "tokens=*" %%a IN ('dir /b *.aac') DO mp4box -import "%%a" "%%~na.mp4"
for /f "tokens=*" %%b IN ('dir /b *.mp4') DO neroaacdec -if "%%b" -of "%%~nb.wav"

can be replaced by
for /f "tokens=*" %%a IN ('dir /b *.aac') DO faad.exe "%%a"

RunningSkittle
13th August 2009, 13:12
Just a quick note for the author of the batch script: its easier and recommended to use the /r switch (no need to parse from dir in the modern age of ntbatch)

for /r %%a in ("%path%/*.mkv") do (stuff)

plus is has the advantage of being able to re curse through sub directories (read the documentation for additional switches and info)

also instead of doing %%~na%%~xa you can just do %%~xna... or any other combination


@echo off
set path="G:\Movies\"
rem (enable this next line of code and disable the above to use folder drag and drop)
rem set path=%1
for /r %path% %%a in (*.mkv) do (call :StartConvert "%%a")
goto EndConvert
:StartConvert
rem (remove echo commands when you are sure the commands work)
echo mkvextract tracks %1 2:"%~n1_temp.aac"
echo mp4box -import %1 "%~n1_temp.mp4"
echo neroaacdec -if %1 -of "%~n1_temp.wav"
echo lame --vbr-new -V 3 -m j -q 0 --priority 0 %1 "%~n1_temp.mp3"
echo mkvmerge -o "%~n1_done.mkv" -d 1 -A -S %1 -a 0 -D -S "%~n1_temp.mp3" --track-order 0:1,1:0
echo del *temp.*
echo ===================================
goto eof
:EndConvert
pause
:eof

...something like that... Probably would be useful to specify separate working and final directories.

Skelsgard
13th August 2009, 19:50
Just a quick note for the author of the batch script: its easier and recommended to use the /r switch (no need to parse from dir in the modern age of ntbatch)

for /r %%a in ("%path%/*.mkv") do (stuff)

plus is has the advantage of being able to re curse through sub directories (read the documentation for additional switches and info)

also instead of doing %%~na%%~xa you can just do %%~xna... or any other combination


@echo off
set path="G:\Movies\"
rem (enable this next line of code and disable the above to use folder drag and drop)
rem set path=%1
for /r %path% %%a in (*.mkv) do (call :StartConvert "%%a")
goto EndConvert
:StartConvert
rem (remove echo commands when you are sure the commands work)
echo mkvextract tracks %1 2:"%~n1_temp.aac"
echo mp4box -import %1 "%~n1_temp.mp4"
echo neroaacdec -if %1 -of "%~n1_temp.wav"
echo lame --vbr-new -V 3 -m j -q 0 --priority 0 %1 "%~n1_temp.mp3"
echo mkvmerge -o "%~n1_done.mkv" -d 1 -A -S %1 -a 0 -D -S "%~n1_temp.mp3" --track-order 0:1,1:0
echo del *temp.*
echo ===================================
goto eof
:EndConvert
pause
:eof

...something like that... Probably would be useful to specify separate working and final directories.

Will keep it in mind :thanks: