英文:
MkvToolNix: Bat file / Batch file to mux pairs of videos together
问题
以下是您提供的文本的翻译部分:
"Struggling for some time in that problem. I have a list of videos going this way, by pairs :
magic.mkv
magic-1.mkv
food.mkv
food-2.mkv
wedding.mkv
wedding-3.mkv
etc.
Each video has its pair, and the pair has a number that is incrementing every time. I want to mux each pair together. And for each pair : First video (without the numbers) keep everything except for chapters, Second video (with the incrementing number) to keep all subtitles only.
Now I know how to select tracks and so on, what I don't know, is how to make this .bat file mux those pairs, whiches are all in the same folder. (I know I could put each pair in a different folder, but I have more than 700 files so first I would like to see if there is a way to do this with code)
Opened to any suggestion (I'm not very tech saavy please be specific).
Thank you in advance.
Tried that, and it crashed ('error the file cannont be opened for reading' - open file error) :
for %%a & for %%a-1 in (*.mkv) do "\\\\\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"
Tried that, and it crashed ('error the file cannont be opened for reading' - open file error) :
for %%a in (*.mkv) do "C:\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" '(' %%~na-1%%~xa ')' --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"
Tried that, and it does not crash, but it looks for the second video like that : 'videoone.mkv-1', as opposed to 'videoone-1.mkv'. It means that '%%a' will look for the full name including the specified extension, so probably '%%a' is not the right thing to use since I need to specify a file name, then the extension :
for %%a in (*.mkv) do "C:\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" '(' %%a %%a-1 ')' --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"
英文:
Struggling for some time in that problem. I have a list of videos going this way, by pairs :
magic.mkv
magic-1.mkv
food.mkv
food-2.mkv
wedding.mkv
wedding-3.mkv
etc.
Each video has its pair, and the pair has a number that is incrementing every time. I want to mux each pair together. And for each pair : First video (without the numbers) keep everything except for chapters, Second video (with the incrementing number) to keep all subtitles only.
Now I know how to select tracks and so on, what I don't know, is how to make this .bat file mux those pairs, whiches are all in the same folder. (I know I could put each pair in a different folder, but I have more than 700 files so first I would like to see if there is a way to do this with code)
Opened to any suggestion (I'm not very tech saavy please be specific).
Thank you in advance.
Tried that, and it crashed ("error the file cannont be opened for reading" - open file error
) :
for %%a & for %%a-1 in (*.mkv) do "\\\\\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"
Tried that, and it crashed ("error the file cannont be opened for reading" - open file error
) :
for %%a in (*.mkv) do "C:\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" '(' %%~na-1%%~xa ')' --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"
Tried that, and it does not crash, but it looks for the second video like that : videoone.mkv-1
, as opposed to videoone-1.mkv
. It means that %%a
will look for the full name including the specified extension, so probably %%a
is not the right thing to use since I need to specify a file name, then the extension :
for %%a in (*.mkv) do "C:\\MKV Tool Nix\mkvtoolnix\mkvmerge.exe" -o "tada\%%~a" '(' %%a %%a-1 ')' --default-track "5:yes" --track-order 1:0,1:1,1:2,1:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10 "%%~a"
答案1
得分: 0
以下是翻译好的部分:
以下示例脚本是否对您有帮助?
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
For %%G In (
*-1*.mkv
*-2*.mkv
*-3*.mkv
*-4*.mkv
*-5*.mkv
*-6*.mkv
*-7*.mkv
*-8*.mkv
*-9*.mkv
) Do (
Set "filebasename=%%~nG"
SetLocal EnableDelayedExpansion
Set "filebasename=!filebasename:.=?!"
For %%H In ("!filebasename:-=.!") Do (
EndLocal
Set "pairedfilebasename=%%~nH"
SetLocal EnableDelayedExpansion
Set "pairedfilebasename=!pairedfilebasename:.=-!"
For %%I In ("!pairedfilebasename:?=.!") Do (
EndLocal
If Exist "%%~I%%~xG" (
Echo 匹配后缀文件名为 "%%~I%%~xG" 的文件是 "%%~G"
)
)
)
)
Pause
如果它对您有用,您只需要更改 Echo
命令行为您特定的 mkvmerge.exe
命令行,记住 "%%~I%%~xG"
是非后缀文件名,"%%G"
是带后缀的文件名。
根据您的文件名构造,您可能需要更改以下部分:
*-1*.mkv
*-2*.mkv
*-3*.mkv
*-4*.mkv
*-5*.mkv
*-6*.mkv
*-7*.mkv
*-8*.mkv
*-9*.mkv
为:
*-*0.mkv
*-*1.mkv
*-*2.mkv
*-*3.mkv
*-*4.mkv
*-*5.mkv
*-*6.mkv
*-*7.mkv
*-*8.mkv
*-*9.mkv
如果您的文件名更复杂,您可能最好将外部的 For
循环更改为使用 Dir
命令管道传递到 findstr.exe
进行筛选,类似于 /IR "\-[123456789][0123456789]*\.mkv$"
。
英文:
Does the following example script help you out?
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
For %%G In (
*-1*.mkv
*-2*.mkv
*-3*.mkv
*-4*.mkv
*-5*.mkv
*-6*.mkv
*-7*.mkv
*-8*.mkv
*-9*.mkv
) Do (
Set "filebasename=%%~nG"
SetLocal EnableDelayedExpansion
Set "filebasename=!filebasename:.=?!"
For %%H In ("!filebasename:-=.!") Do (
EndLocal
Set "pairedfilebasename=%%~nH"
SetLocal EnableDelayedExpansion
Set "pairedfilebasename=!pairedfilebasename:.=-!"
For %%I In ("!pairedfilebasename:?=.!") Do (
EndLocal
If Exist "%%~I%%~xG" (
Echo matching suffixed filename to "%%~I%%~xG" is "%%~G"
)
)
)
)
Pause
All you should need to do, if it works for you, is change the Echo
command line to your particular mkvmerge.exe
command line, remembering that "%%~I%%~xG"
is the non suffixed filename and "%%G"
is the suffixed one.
Depending upon the makeup of your specific filenames you may wish to change:
*-1*.mkv
*-2*.mkv
*-3*.mkv
*-4*.mkv
*-5*.mkv
*-6*.mkv
*-7*.mkv
*-8*.mkv
*-9*.mkv
to:
*-*0.mkv
*-*1.mkv
*-*2.mkv
*-*3.mkv
*-*4.mkv
*-*5.mkv
*-*6.mkv
*-*7.mkv
*-*8.mkv
*-*9.mkv
If your filenames are even more complex, you may be better advised to change to outer For
loop to a For /F
loop using the Dir
command piped to findstr.exe
filtering using something like /IR "\-[123456789][0123456789]*\.mkv$"
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论