我目前正在看一个名为合并。我想创建一个批处理文件,从指定路径递归查找所有 MKV 文件,并从找到的 MKV 文件中删除所有字幕(如果找到的 MKV 包含字幕),最后删除所有已删除字幕的原始 MKV 文件。
我已经花了大约 2 个小时进行谷歌搜索,我发现你必须能够写出这样的内容:
FOR /F "delims=*" %%A IN ('dir /b *.MKV') DO "C:\mkvmerge.exe" -o "fixed_%%A" -a 4 -s 7 --compression -1:none "%%A"
我仍在努力,但如果有人能给我一点帮助,我将不胜感激。
答案1
保存以下内容删除MKVSubs在同一目录中合并工具位于,编辑根文件夹根据您的要求变量并运行批处理文件:
@echo off
cls
set rootfolder=C:\
echo Enumerating all MKVs under %rootfolder%
echo.
for /r %rootfolder% %%a in (*.mkv) do (
for /f %%b in ('mkvmerge -i "%%a" ^| find /c /i "subtitles"') do (
if [%%b]==[0] (
echo "%%a" has no subtitles
) else (
echo.
echo "%%a" has subtitles
mkvmerge -q -o "%%~dpna (No Subs)%%~xa" -S "%%a"
if errorlevel 1 (
echo Warnings/errors generated during remuxing, original file not deleted
) else (
del /f "%%a"
echo Successfully remuxed to "%%~dpna (No Subs)%%~xa", original file deleted
)
echo.
)
)
)
该批处理文件应该很容易理解,但是这里还是有一个概述:
它用于
for /r
递归搜索%rootfolder%
所有 MKV然后在每个 MKV 上运行
mkvmerge -i
以检查是否存在字幕轨道如果 MKV 确实包含字幕轨道,它会运行
mkvmerge -S
重新混合文件,同时跳过所有此类轨道最后,它会检查 mkvmerge 的退出代码,如果该代码(即
errorlevel
)为 0,则表示成功且没有警告/错误,它会删除原始文件
更多信息请参阅mkvmerge 文档以及命令提示符下的等等for /?
。if /?
答案2
谢谢,Karan,这对我也很有用。我修改了你的脚本,这样你现在可以为想要保留的字幕选择一种语言(由 3LC 指定(eng、ned、swe 等))。此外,我删除了输入文件被删除的部分,并选择为输出文件添加后缀。
这是我的版本:
:: remux all mkvs under a certain subfolder with all subitles
:: but those as specified by %language% parameter removed.
@echo off
setlocal enabledelayedexpansion
:: set your variables here
set rootfolder="C:\temp\New folder"
set language=eng
set suffix= (eng sub)
:: do the remuxing
echo Remuxing all mkvs in %rootfolder% and its subfolders.
for /r %rootfolder% %%a in (*.mkv) do (
set subs=
set mkv=%%a
for /f "tokens=3 delims=: " %%b in ('mkvmerge -I "%%a" ^| findstr /i /r ".*subtitles.*language:%language%.*"') do (
set subs=!subs!,%%b
)
for /f "tokens=*delims=," %%c in ("!subs!") do (
set subs=%%c
)
if not exist "%%~dpna%suffix%%%~xa" if not "!subs!"=="" (
mkvmerge -q -o "%%~dpna%suffix%%%~xa" -s !subs! "%%a"
if errorlevel 1 (
echo Warnings/errors generated during remuxing of "%%a".
) else (
echo Successfully remuxed to "%%~dpna (eng subs)%%~xa".
)
) else (
echo Input file "%%a" has no subtitles in %language% or output file "%%~dpna%suffix%%%~xa" already exists. Skipping this file.
)
)
pause