AutoHotkey Community

It is currently May 25th, 2012, 10:41 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: January 18th, 2008, 11:02 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
My fav site for subtitles is <External Link : Movies And Subtitles.net> and almost 90% of the time I find an exact match for my videos.
When I do not get a perfect match, I use the following script to synchronise:

Code:
SetBatchlines -1
IniRead, LastFolder, %A_ScriptDir%\SRT.INI, Settings, LastFolder, %A_Desktop%
SetWorkingDir, %LastFolder%
SetFormat, Float, 0.3

Gui, Font, s9
Gui, Margin, 15,7
Gui, Add, GroupBox, X5 y5 w500 h250, Original
Gui, Add, Edit  , x18 yp+19 w439 h20 vSrtFile
Gui, Add, Button, x+5 w30 h20 vSource gSelectSRT, ...
Gui, Add, Edit  , x15 y+5  w480 h200 +ReadOnly vSubtitles
Gui, Add, GroupBox, X5 y+10 w500 h261, Rectified
Gui, Add, Edit  , x15 yP+19 w480 h200 vNewSubs
Gui, Add, Text  , x15 y+14 w150 h18 +0x200 +Right, Time to adjust ( in Seconds ) :
Gui, Add, Text  , x+5     h18 w15 vMinus  gAdjusts +0x201 +Border, -
Gui, Add, Edit  , x+0 w50 h18 +Center vAdjusts -E0x200 +Border, 0.000
Gui, Add, Text  , x+0     h18 w15 vPlus   gAdjusts +0x201 +Border, +
Gui, Add, Button, x+41 w180 h24 yp-4 gSynchronise, Synchronise && Overwrite SRT File
Gui, Show, x50 y50 w510, SubRipText Synchroniser
Return

Adjusts:
  AGc := A_GuiControl, AdjustValue := GetKeyState("LCTRL","P") ? 1.0 : 0.1
  GuiControlGet, Adjusts
  If ( AGC = "Minus" )
       Adjusts -= %AdjustValue%
  Else
  If ( AGC = "Plus"  )
       Adjusts += %AdjustValue%
  Else Adjusts += 0.00
  GuiControl,, Adjusts, %Adjusts%
Return

SelectSRT:
  FileSelectFile, SelFile,3 , %A_WorkingDir%, Select a SRT File, Subtitles (*.SRT;*.TXT)
  IfEqual,SelFile,, Return
  SplitPath, SelFile,, SelDir
  IniWrite, %SelDir%, %A_ScriptDir%\SRT.INI, Settings, LastFolder
  GuiControl,,SrtFile,%SelFile%
  FileRead, SubTitles, %SelFile%
  GuiControl, ,SubTitles, %SubTitles%
  GuiControl, ,NewSubs  ,
  GuiControl, ,adjusts  , 0.000
Return

Synchronise:
  GoSub, Adjusts
  NewSubs := ""
  Loop, Parse, SubTitles, `n, `r
  {
    If InStr( A_LoopField, " --> " ) {
    StringSplit, T, A_LoopField, %A_Space%, `r`n
    NewSubs .= FS( ((SubStr(T1,1,2)*60*60)+(SubStr(T1,4,2)*60)+(SubStr(T1,7,2)+0)) "."
            . SubStr(T1,10,3) ) " --> "  FS( ((SubStr(T3,1,2)*60*60)+(SubStr(T3,4,2)*60)
            + (SubStr(T3,7,2)+0)) "." SubStr(T3,10,3) ) "`n"
  } Else NewSubs .= A_LoopField . "`n", T1:="", T2:="", T3:=""
}   GuiControl,, NewSubs, %NewSubs%
  GuiControlGet, SrtFile
  FileDelete, %SrtFile%
  IfEqual,ErrorLevel,0, FileAppend, %NewSubs%, %SrtFile%
  IfNotEqual,ErrorLevel,0,  MsgBox,16,SRT File error !, Unable to overwrite File!, 5
Return

FS(Secs) {
 Global adjusts
 Secs += adjusts
 IfLess,Secs,0, Return, % "00:00:00,000"
 StringSplit, Sec, Secs, .
 Time = 19990101
 Time += %Sec1%, Seconds
 FormatTime, mmss, %Time%, mm:ss
Return SubStr( "0" Round(Secs//3600),-1) ":" mmss "," Sec2
}

GuiClose:
  ExitApp


ImageImage
Seen in the above snapshot is a real case where the subtitle lags by 49+ seconds.
I run the script side by side with the player ( windowed mode )
Open the SRT file with the script.
Keep adjusting the value and overwrite the SRT until it is synchronised.

    Points to note:
  • Everytime the Overwrite button is pressed, the Text from the Edit1 will be processed into Edit2 and also the SRT wil be overwritten. DirectVobSub would detect the FileTimeStamp change and would auto-sync the subtitles with the player on the fly.
  • I repeat, the calculations are being done based on the text available in Edit1 control and not from the SRT file. For example, you test synchronise by -49 seconds and find the subtitle still lags by half a second. Then, try it again with -49.500 seconds ( not .500 )
  • You may want a backup copy of the SRT file as it is being overwritten everytime.
  • In case you want to revert to the original file, just synchronise it to 0 seconds and overwrite.


:)


Last edited by SKAN on January 19th, 2008, 8:33 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2008, 3:29 am 
Good Job!
Maybe English-speaker are not be interested in ii, I like that!
Thanks.
By the way, I guess Skan you don't need subtitle to see movies, do you?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2008, 8:32 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Charles wrote:
Skan you don't need subtitle to see movies, do you?


I cannot understand 100% of the present day Hollywood movie without rewinding occasionally, but I would prefer to manage without subtitles instead of going through the trouble.
I do it for my Spouse who is otherwise not interested in watching a non-tamil movie.

:)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: ELengefeld and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group