3

Oh boy! I don't know even know what to start with) So, I have a folder with a lot of videos. What I need is to create subtitles with the names of those videos also minding their length to create subtitles in .srt format.

I have already look up some info and copied some code

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

As a result i got this in result.txt

 videoname1
 videoname2
 videoname3

What I need is to make them look like this (And of course in the end to create .srt file with the result.)

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

Hope I got everything, please help! Thanks in advance!

  • How long do each of the subtitles need to be? Their durations vary in your example. – SomethingDark Dec 24 '15 at 21:56
  • Well, every video has a different duration, so it is necessary first to determine the duration of every video in the folder, and then to create sequent timeline. so i guess everytime a piece of code should check every video's length –  Dec 24 '15 at 22:54
  • Maybe [this answer](http://stackoverflow.com/a/31864121/1683264) will give you some ideas? – rojo Dec 25 '15 at 04:27

1 Answers1

2

Using VBS to get the video length of each video files (using Folder.GetDetailsOf method) and to sum the lengths for the timers in the .srt file (using the FormatDateTime Function).

This script get the name of the videos in your result.txt file (so you have to include your code in this BAT or run the bat, that generate it, before.

I already include it in my code but with REM before. So remove the REMs if needed.

The result is displayed on the CMD and writing in the file Output.srt(In the same directory of the BAT file)

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

This will create a file Output.srt like this :

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
SachaDee
  • 9,245
  • 3
  • 23
  • 33
  • it works for videofiles named completely in english and if it has any sort of symbols such as ☺ or ♪ ♣ in its name or if it's in another language then it shows Microsoft VBScript error. –  Dec 25 '15 at 19:52
  • 2
    SO is an English forum ! And in your question i can't see anywhere that you''ll work with unicode filename. I think my answer resolve your problem ! Now its is another question to resolve this unicode problem. – SachaDee Dec 26 '15 at 14:42
  • I'm sorry, I completely forgot about unicode, anyways, Thank you very much for your help! –  Dec 26 '15 at 15:31