批处理以正确的时间创建视频 .srt 字幕

Batch to Create video .srt Subtitles with right timing

天哪!我什至不知道从什么开始)所以,我有一个包含很多视频的文件夹。我需要的是用这些视频的名称创建字幕,同时注意它们的长度以 .srt 格式创建字幕。

我已经查了一些资料,复制了一些代码

@echo off  
set dirpath=%1 
dir C:\FolderwithVideos /O:S /b /-p /o:gn > "C:\result.txt"
call replacer.bat result.txt ".mp4" ""
exit

结果我在 result.txt

中得到了这个
 videoname1
 videoname2
 videoname3

我需要的是让它们看起来像这样(当然最后要用结果创建 .srt 文件。)

1
00:00:0,000 --> 00:00:25,000
videoname1

2
00:00:25,000 --> 00:00:35,000
videoname2

3
00:00:35,000 --> 00:00:55,000
videoname3

希望我得到了一切,请帮忙!提前致谢!

使用VBS获取每个视频文件的视频长度(使用Folder.GetDetailsOf method) and to sum the lengths for the timers in the .srt file (using the FormatDateTime Function)

此脚本获取您的 result.txt 文件中的视频名称(因此您必须在此 BAT 或 运行 蝙蝠中包含您的代码,然后生成它.

我已经将其包含在我的代码中,但之前包含 REM。因此,如果需要,请删除 REMs

结果显示在CMD上并写入文件Output.srt(与BAT文件同目录)

BuildSrt.bat

@echo off&cls

::The Path of your Videos files

set "$VideoPath=C:\FolderwithVideos"

::If you want your Code in this BAT remove the REMs Below :

rem dir "%$VideoPath%" /O:S /b /-p /o:gn > "C:\result.txt"
rem call replacer.bat result.txt ".mp4" ""

setlocal enabledelayedexpansion
set /a $Count=1
set "$Timer=00:00:00"


(for /f "delims=" %%a in (result.txt) do (
  call:getVideolength "%%a.mp4"
  for /f "delims=" %%x in ('cscript //nologo getvideolength.vbs') do (
       call:SumTime !$Timer! %%x
       for /f "delims=" %%y in ('cscript //nologo SumTime.vbs') do set "$NewTimer=%%y"
       echo !$Count!
       echo !$Timer!,000 --^> !$NewTimer!,000
       echo %%a
       Set $Timer=!$NewTimer!
  )
  set /a $Count+=1
))>Output.srt

echo Done !!!
type Output.srt
pause
exit/b

:GetVideoLength
(echo dim objShell
echo dim objFolder
echo dim objFolderItem
echo set objShell = CreateObject("shell.application"^)
echo set objFolder = objShell.NameSpace("%$videoPath%"^)
echo set objFolderItem = objFolder.ParseName(%1^)
echo dim objInfo
echo objInfo = objFolder.GetDetailsOf(objFolderItem, 27^)
echo wscript.echo objinfo)>GetVideoLength.vbs
exit/b


:SumTime
echo wscript.echo FormatDateTime(CDate("%1"^) + CDate("%2"^),3^) >SumTime.vbs
exit/b

这将创建一个文件 Output.srt,如下所示:

1
00:00:00,000 --> 01:28:28,000
Film1
2
01:28:28,000 --> 02:49:39,000
Film2
3
02:49:39,000 --> 04:45:25,000
Film3