Okay, so to try and explain... I have a lot of Video Files and Audio Files I am trying to mux.
I have a Video file and I am trying to mux with 1 single Audio File which is the default audio track.
I am trying to use a batch file to mux these together with MKVMerge and this is working, but I have some differences in output.
I want all output files to follow the same structure, but right now they are not doing this...
I have 3 different types of existing Video file:
1.
I have an MKV containing only Video (and Global tags).
When I mux using my batch file: it outputs with Video is ID0, Audio is ID1.
2.
I have another MKV containing Video, Subtitles (and Global tags).
When I mux using my batch file, Video is returned as ID0, Subtitles are already ID1 so newly muxed Audio becomes ID2
any variation on this (for example, if there are 2 subtitles already in the file) keeps pushing the audio onwards by +1 ID each time.
3.
I have yet another type of MKV containing Video, Audio and Subtitles (and Global tags, sometimes Track ID tags also)
When I mux using my batch file:
Video is ID0, existing Audio is already ID1, Subtitles are ID2. New Audio I am muxing then becomes ID3.
The Audio track I am muxing - I ALWAYS want this to be ID1.
So how do I force the new Audio track that I am muxing to always become ID1?
Effectively if my new audio track now becomes ID1 this should also then (probably, I am guessing?) increment anything else that already existed at ID1 or beyond this on by +1.
I think it is something to do with the --track-order parameter, but right now I just can't quite figure out how I include this since I have 3 different structures (as above).
My script (below) may only need a minor change, but I just can't figure it out right now, so would appreciate some help...
My batch file so far:
Code:FOR %%f IN (*.mkv) DO ( "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac )
It may be worth noting above that when the new Audio file is provided it already identifies itself as ID0 (audio was ripped using MKVCleaver).
Also, is it possible to output the result of each mux to one overall single log file
(i.e. all results sent to a single log file, not one log file per encode)?
How do I change the code also to allow for this?
+ Reply to Thread
Results 1 to 26 of 26
-
Last edited by m3; 5th Sep 2015 at 02:29.
-
Dirty trick for 2:
Code:FOR %%f IN (*.mkv) DO "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv --no-subtitles %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac --no-video %%~nf.mkv
-
[QUOTE=sneaker;2408297]Dirty trick for 2:
Code:FOR %%f IN (*.mkv) DO "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv --no-subtitles %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac --no-video %%~nf.mkv
I would prefer all in the one script, however can use separate scripts if there is no other way.
I have also tried the script above on a type of #3 above (Video, Audio and Subtitles already exist), but it obviously not correct for that. Running that on #3 produces an extra copy of the audio track when it is not needed and the new audio track being added at ID2 instead of ID1.
So for type 3. what existed before: ID0 Video, ID1 Audio, ID2 Subtitles
then becomes: ID0 Video, ID1 Audio (existing), ID2 Audio (newly muxed), ID3 Audio (copy of ID1), ID4 SubtitlesLast edited by m3; 5th Sep 2015 at 13:20.
-
Code:
FOR %%f IN (*.mkv) DO "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv --no-audio --no-subtitles %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac --no-video %%~nf.mkv
-
Have tested a few times and I *think* (fingers crossed) that is working - thanks!
Will test some more to be certain...
I have also been trying to create the logs using what was supplied above and another script found on this site here: https://forum.videohelp.com/threads/368801-Help-with-Mkvmerge?p=2361639&viewfull=1#post2361639,
but the logging is not working for me
Any variation on the log is welcome - I am happy if it logs anything but really will only be looking through the log to see if was OK, there were warnings or mux failed.
Here is what I currently have (but log is not working):
Code:@echo on break>all_logs.log FOR %%f IN (*.mkv) DO ( "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv --no-audio --no-subtitles %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac --no-video %%~nf.mkv ) pause :end :print_log echo. >>all_logs.log echo %~n1.LOG >>all_logs.log echo --------------------------------- >>all_logs.log type "%~1">>all_logs.log goto :eof
This creates a logfile, but the only entry right now is:
.LOG
---------------------------------Last edited by m3; 5th Sep 2015 at 13:19.
-
m3:
you replaced %%y for %%f, so you have to replace that "y" everywhere to "f", one "y" you missed -
Okay, almost there... just need help with a couple of tweaks...
Code:@echo on break>all_logs.log FOR %%f IN (*.mkv) DO ( "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv --no-audio --no-subtitles %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac --no-video %%~nf.mkv>"%%~dpnf.log" call :print_log "%%~dpnf.log" del "%%~dpnf.log" ) pause :end :print_log echo. >>all_logs.log echo %~n1.LOG >>all_logs.log echo --------------------------------- >>all_logs.log type "%~1">>all_logs.log goto :eof
The logfile prints successfully, however there is always an error at the end:
"type "" 1>>all_logs.log
The system cannot find the path specified"
My understanding is that the line "type "%~1">>all_logs.log" is copying the contents of "%~1" to all_logs.log, but what exactly is "%~1" here? Obviously the syntax is incorrect anyway though.
Also, I would like to add a couple of blank lines between each of the results that are outputted into the logfile (makes it easier to see where one file ends and the next begins when scrolling through)?Last edited by m3; 5th Sep 2015 at 16:46.
-
%%f becomes %~1 in calling function, first argument it is always %~1
just looking at it try:
Code:call :print_log "%%f"
also change:
Code::print_log echo. >>all_logs.log echo %~n1.LOG >>all_logs.log echo --------------------------------- >>all_logs.log type "%~dpn1.log">>all_logs.log goto :eof
if you want to add a empty line somewhere you can use:
Code:echo. >>all_logs.log
Last edited by _Al_; 5th Sep 2015 at 20:22.
-
Code:
@echo on break>all_logs.log FOR %%f IN (*.mkv) DO ( "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv --no-audio --no-subtitles %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac --no-video %%~nf.mkv>"%%~dpnf.log" call :print_log "%%f" ) pause :end :print_log echo. >>all_logs.log echo %~n1.LOG >>all_logs.log echo --------------------------------- >>all_logs.log type "%~dpn1.log">>all_logs.log del "%~dpn1.log" goto :eof
Just one more thing, that message: The system cannot find the path specified was causing batch script not recognizing that del "%%~dpnf.log" , that is what I think, because batch script sorts all lines withinin parentheses at the same time at the beginning, it does not simply processes line at a time, so it could not understands what that file "%%~dpnf.log" was, as batch script was concerned, "%%~dpnf.log" was not created yet. So better to delete that generated one time log within that function. That is another reason to not be afraid to use functions all the time, even merged one in another.Last edited by _Al_; 5th Sep 2015 at 21:05.
-
Removing the "call" as you did above (i.e. you changed it toCode:>"%%~dpnf.log:print_log "%%f"
So I put theCode:call :print_log
However, the amended line towards the bottom type "%~dpn1.log">>all_logs.log is still throwing an error, this one this time:
type ".log" 1>>all_logs.log
The system cannot find the path specified.
By the way, another side note... Ever since I started writing to the logfile, I cannot see the muxing % progress in the DOS window anymore as it is taking place.
Any way to bring this back so that I can see the progress as it is taking place? All I get now is a flashing cursor while it is muxing. -
you have to call :
Code:call :print_log "%%f"
Code:@echo off break>all_logs.log FOR %%f IN (*.mkv) DO ( "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv --no-audio --no-subtitles %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac --no-video %%~nf.mkv>"%%~dpnf.log" call :print_log "%%f" ) pause :end :print_log rem type individual log into cmd window echo. echo. type "%~dpn1.log" rem log it echo. >>all_logs.log echo %~n1.LOG >>all_logs.log echo --------------------------------- >>all_logs.log type "%~dpn1.log">>all_logs.log del "%~dpn1.log" goto :eof
-
or you can try to do this, if that mkvmerge is going to show up a progress at that cmd prompt top bar:
Code:@echo off break>all_logs.log FOR %%f IN (*.mkv) DO call :mux "%%f" pause :end :mux "mkvmerge.exe" -o "C:\Temp\%~n1-new.mkv" --no-audio --no-subtitles "%~n1.mkv" --language 0:eng --default-track 0:yes "%~n1_track01.aac" --no-video "%~n1.mkv">"%~dpn1.log" rem type individual log into cmd window echo. echo. type "%~dpn1.log" rem log it echo. >>all_logs.log echo %~n1.LOG >>all_logs.log echo --------------------------------- >>all_logs.log type "%~dpn1.log">>all_logs.log del "%~dpn1.log" goto :eof
-
No luck.
Results in the following error in the DOS window:
Code:The system cannot find the file specified. The system cannot find the file specified. Could Not find C:\Temp\MKVMovie.log Press any key to continue... The system cannot find the file specified. The system cannot find the file specified. Could Not find C:\Temp\.log
And in the logfile it says the following:
Code:Error: The file '.mkv' could not be opened for reading: open file error.
And no, % progress was never displayed in titlebar of DOS command window -
well, it works for me,
make sure that your BAT file is in the same directory as your mkv files, also I tried to fill in all the full paths in the script, just to be sure, most likely copy/paste failed or something with the cash, try to save the BAT file couple of times or rename it, otherwise have no idea ... also make sure that paths and filenames have no weird characters, just spaces
Code:@echo off break>all_logs.log FOR %%f IN (*.mkv) DO call :mux "%%f" pause :end :mux "mkvmerge.exe" -o "C:\Temp\%~n1-new.mkv" --no-audio --no-subtitles "%~dpn1.mkv" --language 0:eng --default-track 0:yes "%~dpn1_track01.aac" --no-video "%~dpn1.mkv">"%~dpn1.log" rem type individual log into cmd window echo. echo. type "%~dpn1.log" rem log it echo. >>"%~dp1\all_logs.log" echo %~n1.LOG >>"%~dp1\all_logs.log" echo --------------------------------- >>"%~dp1\all_logs.log" type "%~dpn1.log">>"%~dp1\all_logs.log" del "%~dpn1.log" goto :eof
-
Thanks, the minor changes you have made in the version above seem to have fixed something, I will test a few times and report back on it.
Coming back to this again.
It has come to my attention that I may be giving myself double the amount of work that is needed here...
Right now, I am using 2 steps:
i. Another script (not previously discussed) to remove the audio track that I do not want (in most cases this is the first track, usually track ID1). This muxes to the different filetypes I described before early in this thread.
ii. I then take the file that was output from i. and use the script we have been discussing in this thread
But I got to thinking, wouldn't it be more efficient just to replace the existing audio track in the original file with a single script, rather than using 2 different scripts resulting in 2 different output files (which is effectively an 'intermediate' file and a 'final' file right now)?
Problem is I don't know how to combine my first script with what you had discussed.
I had been using the mkvmerge command line -a !1 in my own first script to remove/delete Audio Track 1, but how do I combine this with the code you had given? The parameters --no-audio and -a !1 don't work together in a single command do they?
How would I rewrite the mkvmerge script to do all of that in one go?
In summary:
1. Provide the original mkv as input. Delete any existing Audio Track 1 from the mkv.
2. Insert the new Audio Track 1 (already held in a separate file) as the new ID1 and bump any already still existing IDs (e.g. any other Audio Tracks and Subtitles) +1 onwards for each respectively. Output the newly muxed mkv. -
I'm not sure what you are trying to do. Yes, mkvmerge can use mkv files as input just fine - that's what we have been doing already. And yes, we can disable e.g. track ID 1 when muxing to do that. I mean, how did you do that until now? You must have already done this. All you have to know is that options like "--no-audio" and "-a !1" are per input file:
mkvmerge -o output.mkv [options for first input file] [file name of first input file] [options for second input file] [file name of second input file] [options for third input file] [file name of third input file] ....
If you look at the script I have given you you should spot the dirty trick: I added your input file twice. First I only added the video (by disabling audio and subtitles), then I added your audio file and after that I added the input file the second time (but only audio and subtitles, by disabling video). You can also only add the file a single time but you have to know the order and number of tracks to correctly use the "--track-order" parameter. The trick avoids this. Scripting something with "--track-order" is certainly possible, but in Windows' batch this is very annoying and complicated so I will not do it for you.
--track-order works like this: every pair of numbers represents a track. Since mkvmerge starts counting at 0 this means "0:0" represents the first track of the first input file. "0:1" represents the second track of the first input file. "1:0" represents the first track of the second input file, etc. The order in which you put them into the argument dictates the order in the final file. I.e. "--track-order "0:1,0:0"" will result in "second track of first input file will become new first track, first track of first input file will become new second track"Last edited by sneaker; 6th Sep 2015 at 04:33.
-
If you look at the script I have given you you should spot the dirty trick: I added your input file twice.
Sorry maybe my previous explanation was a little confusing. I will try it again.
Here is my current process:
1. I have an original mkv file, let's call it MyVideo.mkv.
It contains Video, Audio (sometimes 2 audio tracks) and Subtitles (sometimes 2 subtitle tracks).
I want to remove the 1st audio track, and I do so using MKVMerge.
Since I am removing the 1st audio track, a new file is then output: MyVideoWithAudioTrack1Removed.mkv
I also have the replacement audio track that I want to add extracted elsewhere and in waiting, let's call it: NEWAudioTrack1.aac
2.
I take MyVideoWithAudioTrack1Removed.mkv and use MKVMerge/the script in this thread to merge NewAudioTrack1.aac into it.
This creates another output file: MyVideoWithNEWAudioTrack1Added.mkv
So when I finish I currently have 3 MKV files:
MyVideo.mkv (which I began with)
MyVideoWithAudioTrack1Removed.mkv and
MyVideoWithNEWAudioTrack1Added.mkv
What I am thinking is, can I possibly do this in a single step, without the need to create the middle file (MyVideoWithAudioTrack1Removed.mkv) just by better use of the mkvmerge parameters and if so, how?
Thinking about what you explained, I am trying to determine if something like this would require "--track-order" to be used or if it can be done by removing all audio then re-adding the original file but not including audio track 1? If that makes sense.
I looked some at --track-order myself and yes was confused by it also. -
So you want to replace first original audio only for your new one and keep the rest?
-
when loading all tracks mkvmerge cmd line looks like this:
Code:"mkvmerge.exe" -o "C:\\test-new.mkv" "--default-track" "0:yes" "--forced-track" "0:no" "--display-dimensions" "0:1920x1080" "--default-track" "1:yes" "--forced-track" "1:no" "--default-track" "2:no" "--forced-track" "2:no" "-a" "1,2" "-d" "0" "--track-tags" "0,1,2" "-S" "--no-global-tags" "--no-chapters" "(" "C:\\test.mkv" ")" "--track-order" "0:0,0:1,0:2"
Code:"mkvmerge.exe" -o "C:\\test-new.mkv" "--default-track" "0:yes" "--forced-track" "0:no" "--display-dimensions" "0:1920x1080" "--default-track" "2:no" "--forced-track" "2:no" "-a" "2" "-d" "0" "--track-tags" "0,1,2" "-S" "--no-global-tags" "--no-chapters" "(" "test.mkv ")" "--track-order" "0:0,0:2"
So you might take a look into that one, it seems that just unchecking first audio caused "-a" "2" selection instead of "-a" "1,2" , other thing "-d" "0" seem to be selecting first video track. That is just first glance, more you can "dig up from mkvmerge command line help.
-So your whole first input would be your original video only "-d" "0",
-second input would be your new audio "-a" "0"
-third input would your original video but selected rest of audio only "-a" "2" or "-a" "2,3" depending how much audio tracks is there, basicaly skipping "1" track (first audio)
fourth option would be original video but selected subtitles only "-s" "3" or "-s" "3,4" depending how much sub tracks is there, same as previous input
Not sure, is that aboiut right? Batch script would have to assign for every track its number (ID) to substitute those numbers with variables.Last edited by _Al_; 6th Sep 2015 at 19:10.
-
Yes and no... as sneaker mentioned in a previous post - as files can be different, using the --track-order method could become a real pain.
So of course I am trying to think of the alternative, there must be an easier way...
Playing around with MKVMerge GUI and sneaker's original script, it seems that MKVMerge auto-allocates ID's based on the order that you deliver the items to it. This is a plus as it is doing some of the work.
So I am trying to think of an alternative method that capitalises on this... and what comes to mind is, no matter about the differences between files - going back to the original mkv files (1 Video, 1 or 2 Audios, 0, 1 or 2 Subtitles) what is there that is consistent about these?
There is at least 1 thing that is consistent - they all have at least 1 Video Track and 1 main Audio Track.
So for consistency, maybe the way to approach the command is this:
- With Original mkv file as input, strip all audio
- mux new AAC track (which by default should then automatically become track 1 as it comes directly after Video track)
- insert all other previously existing audio and subtitle tracks
- delete what has now become the 2nd audio track (which would be the old/original audio which is now in ID2)
So based on what I have explained and sneaker's original script, is this the answer... or close to it?
Code:FOR %%f IN (*.mkv) DO "mkvmerge.exe" -o C:\Temp\%%~nf-new.mkv --no-audio --no-subtitles %%~nf.mkv --language 0:eng --default-track 0:yes %%~nf_track01.aac --audio-tracks !1 --no-video %%~nf.mkv
-
try this , add this line into #15 post:
Code:"mkvmerge.exe" -o C:\Temp\%~n1-new.mkv -A -S "%~n1.mkv" "%~n1_track01.aac" -D -a !1 -S "%~n1.mkv" -D -A "%~n1.mkv">"%~dpn1.log"
Code:video only ..... -A -S "%~n1.mkv" new audio only .... "%~n1_track01.aac" rest of the audio only .... -D -a !1 -S "%~n1.mkv subs only .... -D -A "%~n1.mkv"
or just this shorter line might work also:
Code:"mkvmerge.exe" -o C:\Temp\%~n1-new.mkv -A -S "%~n1.mkv" "%~n1_track01.aac" -D -a !1 "%~n1.mkv">"%~dpn1.log"
Last edited by _Al_; 7th Sep 2015 at 00:13.
-
I just tried this and it actually works, there must be quotes around filenames, script throws out first audio and ads new one instead with ID1
Code:@echo off break>all_logs.log FOR %%f IN (*.mkv) DO call :mux "%%f" pause :end :mux "mkvmerge.exe" -o "C:\Temp\%~n1-new.mkv" -A -S "%~n1.mkv" "%~n1_track01.aac" -D -a !1 "%~n1.mkv">"%~dpn1.log" rem type individual log into cmd window echo. echo. type "%~dpn1.log" rem log it echo. >>"%~dp1all_logs.log" echo %~n1.LOG >>"%~dp1all_logs.log" echo --------------------------------- >>"%~dp1all_logs.log" type "%~dpn1.log">>"%~dp1all_logs.log" del "%~dpn1.log" goto :eof
Last edited by _Al_; 7th Sep 2015 at 13:03.
-
Yes just gave it a shot... seems to be working thanks!
...continuing to test
Similar Threads
-
MKVMERGE Batch Muxing multiple audio and subtitle tracks?
By jahob000 in forum Newbie / General discussionsReplies: 38Last Post: 30th May 2023, 19:13 -
A batch/Python script to Mux subtitles with video
By Scavvy in forum ProgrammingReplies: 4Last Post: 6th Jul 2015, 03:23 -
mkvmerge linux- how to batch split video files?
By nie-do in forum LinuxReplies: 3Last Post: 20th May 2015, 04:53 -
What program can batch convert JUST audio of .mp4 files then re-mux?
By Whitezombie455 in forum Video ConversionReplies: 18Last Post: 25th Jan 2015, 09:36 -
Can't find the file i mux using Mkvmerge. With video. HELPPP!!!
By usrnm in forum Video ConversionReplies: 1Last Post: 25th Nov 2013, 04:51