AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Subtitle framerate changer (Srt, FPS)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Fri Feb 27, 2009 6:54 pm    Post subject: Subtitle framerate changer (Srt, FPS) Reply with quote

Subtitle (.srt) framerate changer v1.0

With this you can convert between different subtitle framerates.

Features:
- batch convert (single file mode/multiple files mode)
- drag and drop mode
- supported formats: Subrip (.srt) !!
- built-in framerates: 30.000, 29.97, 25.000, 24.000, 23.99, 23.978, 23.976, 20, 15.000, 12.000, custom

Todo: add more supported formats, add synchronization feature

Download the compiled exe from here: http://www.autohotkey.net/~gahks/subframerate.exe

Download the source from here: http://www.autohotkey.net/~gahks/subframerate.ahk
It works through srtrate.exe (http://subtools.sf.net/) with FileInstall, so if you're gonna compile it from source you're gonna need srtrate.exe.
Srtrate.exe for compiling: http://www.autohotkey.net/~gahks/srtrate.exe or http://subtools.sf.net/
The Ico file: http://www.autohotkey.net/~gahks/subframerate.ico

Tested on WindowsXP Pro SP2.

Full Code:
Code:

;///////////////////////////////////////////////////////
; Script created by GAHKS (2009) http://www.autohotkey.net/~gahks/
; Core exe (srtrate.exe) created by http://subtools.sf.net/
; Subtitle framerate converter v 1.0
;///////////////////////////////////////////////////////

;///////////////////
; INCLUDES VARS AND OPTIONS
script_name = Subtitle framerate changer
SetTitleMatchMode, 3
dragdropmode_active = 0
about_exists = 0
help_exists = 0
FileInstall, srtratesrc.exe, %A_ScriptDir%\srtrate.exe
;///////////////////
; TRAY MENU
Menu, tray, NoStandard
Menu, TrayFileMenu, add, &Select a single file, InputBrowse
Menu, TrayFileMenu, add, Select &multiple files, Input2Browse
Menu, tray, add, &File, :TrayFileMenu
Menu, tray, add,
Menu, tray, add, &Drag and drop mode, DragDrop
Menu, TrayHelpMenu, add, &Help, Help
Menu, TrayHelpMenu, add, &About, About
Menu, tray, add, &Help, :TrayHelpMenu
Menu, tray, add,
Menu, tray, add, E&xit, Ex
;///////////////////
; GUI
Menu, FileMenu, add, &Select a single file, InputBrowse
Menu, FileMenu, add, Select &multiple files, Input2Browse
Menu, FileMenu, add,
Menu, FileMenu, add, E&xit, Ex
Menu, GuiMenuBar, add, &File, :FileMenu
Menu, DragDropMenu, add, A&ctivate, DragDrop
Menu, GuiMenuBar, add, &Drag and Drop, :DragDropMenu
Menu, HelpMenu, add, &Help, Help
Menu, HelpMenu, add, &About, About
Menu, GuiMenuBar, add, &Help, :HelpMenu
;TABS, FIRST TAB
Gui, Add, Tab2, w330 h430 vGuiTab, &Single file|&Multiple Files|
Gui, Add, Text, x+10 y+10, Select an input file
Gui, Add, Edit, vinput_b_input xp+10 yp+20 w240 h20,
Gui, Add, Button, gInputBrowse vbutton_b_input xp+240 yp+0 w50 h20, &Browse
GuiControl, Focus, button_b_input
Gui, Add, Text, xp-250 y+10, Select an output folder
Gui, Add, Edit, vinput_b_output xp+10 yp+20 w240 h20,
Gui, Add, Button, gOutputBrowse vbutton_b_output xp+240 yp+0 w50 h20, B&rowse
Gui, Add, ComboBox, vinput_fps_input xp-240 y+30 w100, 30.000|29.97|25.000||24.000|23.99|23.978|23.976|20|15.000|12.000
Gui, Add, Text, xp+110 yp+0, Choose Input FPS
Gui, Add, ComboBox, vinput_fps_output xp-110 yp+30 w100, 30.000|29.97|25.000||24.000|23.99|23.978|23.976|20|15.000|12.000
Gui, Add, Text, xp+110 yp+0, Choose Output FPS
Gui, Add, Button, gConvert vbutton_ok xp-110 yp+50 w70 h20, Conver&t
Gui, Add, Button, gEx vbutton_cancel xp+90 yp+0 w70 h20, Cance&l
;TABS, 2ND TAB
Gui, Tab, 2
Gui, Add, Text, x+10 y+10, Select input files (All files must be the same FPS)
Gui, Add, Button, gInput2Browse vbutton2_b_input xp+250 yp+0 w50 h20, Browse
Gui, Add, Edit, vinput2_b_input xp-240 yp+30 w290 h150 -Wrap Multi,
GuiControl, Focus, button2_b_input
Gui, Add, Text, xp-10 yp+170, Select an output folder
Gui, Add, Edit, vinput2_b_output xp+10 yp+20 w240 h20,
Gui, Add, Button, gOutput2Browse vbutton2_b_output xp+240 yp+0 w50 h20, Browse
Gui, Add, ComboBox, vinput2_fps_input xp-240 y+30 w100, 30.000|29.97|25.000||24.000|23.99|23.978|23.976|20|15.000|12.000
Gui, Add, Text, xp+110 yp+0, Choose Input FPS
Gui, Add, ComboBox, vinput2_fps_output xp-110 yp+30 w100, 30.000|29.97|25.000||24.000|23.99|23.978|23.976|20|15.000|12.000
Gui, Add, Text, xp+110 yp+0, Choose Output FPS
Gui, Add, Button, gConvert2 vbutton2_ok xp-110 yp+50 w70 h20, Convert
Gui, Add, Button, gEx vbutton2_cancel xp+90 yp+0 w70 h20, Cancel
;SHOW MENU, SHOW GUI
Gui, Menu, GuiMenuBar
Gui, Show, w350 h450, %script_name%
return

;ON DRAG AND DROP EVENT
GuiDropFiles:
Gui +OwnDialogs
If dropped_file_list <>
{
   MsgBox, 35, Warning!, The list isn't blank. Should I add the files to the list?`n`nAdd the files to the list (Press YES)`nReplace the files on the list with the new ones (Press NO)`nNeither one / I don't know (Press CANCEL)
   IfMsgBox, Cancel
    return
   IfMsgBox, No
    dropped_file_list =
}
Loop, parse, A_GuiEvent, `n
{
   dropped_file_list = %dropped_file_list%%A_LoopField%`n
}
GuiControl, Choose, GuiTab, 2
GuiControl,, input2_b_input, %dropped_file_list%
return

;GUI-> ABOUT
About:
If about_exists = 1
   WinActivate, About %script_name%
Else
{
about_exists = 1
Gui, 1:+Disabled
Gui, 3:Destroy
help_exists = 0
Gui, 2:+owner1
Gui, 2:Add, Text,xp+10 yp+10,2009 (C) Gahks, subtools
Gui, 2:Add, Text,xp+0 yp+30, Core exe - srtrate.exe - created by:
Gui, 2:Add, Text, cBlue g2LaunchSubtools, http://subtools.sourceforge.net/
Gui, 2:Add, Text, xp+0 yp+30, GUI created by GAHKS in Autoit scripting language
Gui, 2:Add, Text, cBlue g2LaunchGahks, http://www.autohotkey.net/~gahks/
Gui, 2:Add, Button, g2CloseAbout vbutton3_cancel x+50 yp+30 w70 h20, Cancel
Gui, 2:Show, w330 h200, About %script_name%
GuiControl, 2:Focus, button3_cancel
}
return

2CloseAbout:
2GuiClose:
Gui, 1:-Disabled
Gui, 2:Destroy
about_exists = 0
return

2LaunchSubtools:
Run, http://subtools.sourceforge.net/
return

2LaunchGahks:
Run, http://www.autohotkey.net/~gahks/
return

;GUI-> HELP
Help:
If help_exists = 1
   WinActivate, %script_name% Help
Else
{
help_exists = 1
Gui, 1:+Disabled
Gui, 2:Destroy
about_exists = 0
Gui, 3:+owner1
Gui, 3:Add, Text,xp+10 yp+10 w300, Single file mode:`nSelect the subtitle file you want to convert.`nThe file format must be .srt!`nSelect a folder: the program will put the converted subtitles here.`nSet the framerate - FPS - of the input sub. and the framerate of the movie to which you want to adjust your subtitle file.`nIf you don't select an output folder, the program will put the converted subtitle files here: [Input_subtitle_files_folder]\converted_subtitles.
Gui, 3:Add, Text,xp+0 yp+140 w300, Multiple files mode:`nSame as above, only here  you can select and convert multiple subtitle files at once. You can Drag'N'Drop srt files to the list.
Gui, 3:Add, Text,xp+0 yp+50 w300, File menu, Drag and drop mode:`nIf you activate this option, the windows will be always on top, until you deactivate it.
Gui, 3:Add, Text,xp+0 yp+50 w300, More about subtitles and framerates:
Gui, 3:Add, Text,yp+15 cBlue g3LaunchSubinfo, http://www.doom9.org/sub.htm
Gui, 3:Add, Button, g3CloseHelp vbutton4_cancel x+50 yp+70 w70 h20, Cancel
Gui, 3:Show, w330 h380, %script_name% Help
GuiControl, 3:Focus, button4_cancel
}
return

3CloseHelp:
3GuiClose:
Gui, 1:-Disabled
Gui, 3:Destroy
help_exists = 0
return

3LaunchSubinfo:
Run, http://www.doom9.org/sub.htm
return

;DRAG AND DROP ACTIVATE/DEACTIVATE
DragDrop:
If dragdropmode_active = 0
{
dragdropmode_active = 1
Menu, DragDropMenu, Check, A&ctivate
Menu, Tray, Check, &Drag and drop mode
WinSet, AlwaysOnTop, On, %script_name%
GuiControl, Choose, GuiTab, 2
}
Else
{
dragdropmode_active = 0
Menu, DragDropMenu, Uncheck, A&ctivate
Menu, Tray, Uncheck, &Drag and drop mode
WinSet, AlwaysOnTop, Off, %script_name%
}
return
;/////////////////////////
; MAINGUI FUNCTIONS   
; SINGLE FILE TAB FUNCTIONS
;/////////////////////////
InputBrowse:
Gui +OwnDialogs
WinSet, AlwaysOnTop, Off
FileSelectFile, dialog_b_input, 3, %A_Desktop%, Select input subtitle file..., Subtitle files (*.srt)
If dialog_b_input =
   Return
GuiControl,, input_b_input, %dialog_b_input%
If dialog_b_input <>
   GuiControl, Focus, button_b_output
WinActivate, %script_name%
If dragdropmode_active = 1
   WinSet, AlwaysOnTop, On
GuiControl, Choose, GuiTab, 1
return ;END InputBrowse

OutPutBrowse:
Gui +OwnDialogs
WinSet, AlwaysOnTop, Off
FileSelectFolder, dialog_b_output,, 1, Select output folder...
If dialog_b_output =
   Return
GuiControl,, input_b_output, %dialog_b_output%
GuiControlGet, read_input_b_input,, input_b_input
GuiControlGet, read_input_b_output,, input_b_output
If read_input_b_input =
   GuiControl, Focus, button_b_input
Else If read_input_b_output =
   GuiControl, Focus, button_b_output   
Else
   GuiControl, Focus, input_fps_input
WinActivate, %script_name%
If dragdropmode_active = 1
   WinSet, AlwaysOnTop, On
GuiControl, Choose, GuiTab, 1
return ;END OutPutBrowse

Convert:
Gui +OwnDialogs
WinSet, AlwaysOnTop, Off, %script_name%
GuiControlGet, convert_file_input,, input_b_input
GuiControlGet, convert_file_output,, input_b_output
GuiControlGet, convert_fps_input,, input_fps_input
GuiControlGet, convert_fps_output,, input_fps_output
If convert_file_input =
{
   MsgBox, 48, Cannot proceed, Select a subtitle file (.srt) to convert and an output folder!
   Return
}
StringSplit, substrings_inputpath, convert_file_input, \
substrings_inputpath_last = %substrings_inputpath0%
output_filename := substrings_inputpath%substrings_inputpath_last%
nr_of_loops := substrings_inputpath_last
convert_file_out =
Loop
{
   If a_index >= %nr_of_loops%
      break
      convert_file_out := convert_file_out "\" substrings_inputpath%a_index%
}
StringTrimLeft, convert_file_out_trimmed, convert_file_out, 1
If convert_file_output =
{
   convert_file_output = %convert_file_out_trimmed%\converted_subtitles
   FileCreateDir, %convert_file_output%
}
Else If convert_file_output = %convert_file_out_trimmed%
{
   MsgBox, 52, Warning!, The input folder and the output folder is the same. This way the selected subtitle file will be overwritten.`nDo you proceed?
   IfMsgBox, No
   {
      convert_file_output = %convert_file_out_trimmed%\converted_subtitles
      MsgBox, 64, Output folder changed, The subtitle file will be converted to this folder:`n%convert_file_output%
      FileCreateDir, %convert_file_output%
   }
}
convert_filepath_output := convert_file_output "\" output_filename
Gui, 1:+Disabled
Menu, Tray, Disable, &File
Menu, Tray, Disable, &Help
Menu, Tray, Disable, &Drag and drop mode
WinGetPos, X,Y, Width,, %script_name%
Gui, 4:+owner1
Gui, 4:-0xC00000
Gui, 4:+0x800000
Gui, 4:Font, s12,
Gui, 4:Add,Text,x+80 y+50,Conversion in progress...
Gui, 4:Show, x%X% y%Y% w%Width% h130,Conversion in progress...
WinSet, AlwaysOnTop, Off,,Conversion in progress...
WinMove,,Conversion in progress..., %X%, Y+140,
WinActivate,, Conversion in progress...
RunWait, %A_ScriptDir%\srtrate.exe "%convert_fps_input%" "%convert_fps_output%" "%convert_file_input%" "%convert_filepath_output%",,Hide
Gui, 4:Destroy
Gui, 1:-Disabled
Menu, Tray, Enable, &File
Menu, Tray, Enable, &Help
Menu, Tray, Enable, &Drag and drop mode
MsgBox, 68, Done!, Conversion done. Your converted file is in:`n%convert_file_output%`nWould you like to open the folder now?
IfMsgBox, Yes
   Run, explorer.exe %convert_file_output%
WinActivate, %script_name%
If dragdropmode_active = 1
   WinSet, AlwaysOnTop, On, %script_name%
return ;END Convert
;/////////////////////////
; MAINGUI FUNCTIONS   
; MULTIPLE FILES TAB FUNCTIONS
;/////////////////////////
Input2Browse:
Gui +OwnDialogs
WinSet, AlwaysOnTop, Off
FileSelectFile, dialog2_b_input, M3, %A_Desktop%, Selext two or more subtitle files..., Subtitle files (*.srt)
If dialog2_b_input =
   Return
GuiControlGet, i2_b_i_blank,, input2_b_input
add_to_list =
If i2_b_i_blank <>
{
   MsgBox, 35, Warning!, The list isn't blank. Should I add the files to the list?`n`nAdd the files to the list (Press YES)`nReplace the files on the list with the new ones (Press NO)`nNeither one / I don't know (Press CANCEL)
   IfMsgBox, Cancel
    return
   IfMsgBox, Yes
    add_to_list = yes
}
fullpath =
Loop, parse, dialog2_b_input, `n
{
   If a_index = 0
   {
      dialog2_b_input_substrings_nr = %A_LoopField%
      Continue
   }
   Else If a_index = 1
   {
      dialog2_b_input_folder = %A_LoopField%
      Continue
   }
   fullpath = %fullpath%%dialog2_b_input_folder%\%A_LoopField%`n
}
If add_to_list = yes
   fullpath = %i2_b_i_blank%%fullpath%
GuiControl,, input2_b_input, %fullpath%
GuiControl, Focus, button2_b_output
WinActivate, %script_name%
If dragdropmode_active = 1
   WinSet, AlwaysOnTop, On
GuiControl, Choose, GuiTab, 2
return ;END Input2Browse

Output2Browse:
Gui +OwnDialogs
WinSet, AlwaysOnTop, Off
FileSelectFolder, dialog2_b_output,, 1, Select output folder...
If dialog2_b_output =
   Return
GuiControl,, input2_b_output, %dialog2_b_output%
GuiControlGet, read_input2_b_input,, input2_b_input
GuiControlGet, read_input2_b_output,, input2_b_output
If read_input2_b_input =
   GuiControl, Focus, button2_b_input
Else If read_input2_b_output =
   GuiControl, Focus, button2_b_output   
Else
   GuiControl, Focus, input2_fps_input
WinActivate, %script_name%
If dragdropmode_active = 1
   WinSet, AlwaysOnTop, On
GuiControl, Choose, GuiTab, 2
return ;END Output2Browse

Convert2:
Gui +OwnDialogs
WinSet, AlwaysOnTop, Off, %script_name%
GuiControlGet, convert2_file_input,, input2_b_input
GuiControlGet, convert2_file_output,, input2_b_output
GuiControlGet, convert2_fps_input,, input2_fps_input
GuiControlGet, convert2_fps_output,, input2_fps_output
If convert2_file_input =
{
   MsgBox, 48, Cannot proceed, Select a subtitle file (.srt) to convert and an output folder!
   Return
}
StringSplit, splitrows_c2_f_i, convert2_file_input, `n
StringSplit, splitunits_splitrows_c2_f_i, splitrows_c2_f_i1, \
convert2_file_inpath =
Loop {
   If a_index = %splitunits_splitrows_c2_f_i0%
      Break
   convert2_file_inpath := convert2_file_inpath "\" splitunits_splitrows_c2_f_i%a_index%
}
StringTrimLeft, convert2_file_inpath_trimmed, convert2_file_inpath, 1
If convert2_file_output =
{
   convert2_file_output = %convert2_file_inpath_trimmed%\converted_subtitles ;
   FileCreateDir, %convert2_file_output%
}
Else If convert2_file_output = %convert2_file_inpath_trimmed%
{
   MsgBox, 52, Warning!, The input files are in the output folder. They will be overwritten this way. Do you proceed?
   IfMsgBox, No
   {
      convert2_file_output = %convert2_file_inpath_trimmed%\converted_subtitles ;
      MsgBox, 64, Changed output folder, The output folder is changed to:`n%convert2_file_output%`n
      FileCreateDir, %convert2_file_output%
   }
}
Gui, 1:+Disabled
Menu, Tray, Disable, &File
Menu, Tray, Disable, &Help
Menu, Tray, Disable, &Drag and drop mode
WinGetPos, X,Y, Width,, %script_name%
Gui, 4:+owner1
Gui, 4:-0xC00000
Gui, 4:+0x800000
Gui, 4:Font, s12,
Gui, 4:Add,Text,x+80 y+50,Conversion in progress...
Gui, 4:Show, x%X% y%Y% w%Width% h130,Conversion in progress...
WinSet, AlwaysOnTop, Off,,Conversion in progress...
WinMove,,Conversion in progress..., %X%, Y+140,
WinActivate,, Conversion in progress...
Loop
{
   If a_index > %splitrows_c2_f_i0%
      Break
   current_loop_item := splitrows_c2_f_i%a_index%
   StringSplit, splitunits_current_loop_item, current_loop_item, \
   last_loop_unit_nr = %splitunits_current_loop_item0%
   filename_output := splitunits_current_loop_item%last_loop_unit_nr%
   convert2_file_output_with_filename = %convert2_file_output%\%filename_output%
   RunWait, %A_ScriptDir%\srtrate.exe "%convert2_fps_input%" "%convert2_fps_output%" "%current_loop_item%" "%convert2_file_output_with_filename%",, Hide
}
Gui, 4:Destroy
Gui, 1:-Disabled
Menu, Tray, Enable, &File
Menu, Tray, Enable, &Help
Menu, Tray, Enable, &Drag and drop mode
MsgBox, 68, Done!, Conversion done. Your converted files are in:`n%convert2_file_output%`nWould you like to open the folder now?
IfMsgBox, Yes
   Run, explorer.exe "%convert2_file_output%"
WinActivate, %script_name%
If dragdropmode_active = 1
   WinSet, AlwaysOnTop, On, %script_name%
Return ;END Convert2

;On Exit
Ex:
GuiClose:
FileDelete, %A_ScriptDir%\srtrate.exe
ExitApp
Back to top
Hezzu



Joined: 08 Aug 2008
Posts: 116
Location: Raahe, Finland

PostPosted: Fri Feb 27, 2009 9:00 pm    Post subject: Reply with quote

I´ve been looking for custom framerate changer that I can MODIFY

Thanks!
_________________
Hezzu - excuse the english!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PeaceL
Guest





PostPosted: Sun Mar 01, 2009 12:57 am    Post subject: wow Reply with quote

clearly i am a noob at AHK

did u actually type all of this?!?? thats some neat stuff
Back to top
gahks



Joined: 10 Jan 2009
Posts: 16

PostPosted: Mon Mar 02, 2009 4:37 pm    Post subject: SrtSynch Function Reply with quote

SrtSynch function
This is a subtitle framerate changer and timing adjuster function, I created it to replace the FileInstall-embedded converter solution with a pure ahk one. It can:
- convert between subtitle framerates
- set (+,-) delay on subtitles
- it works on subtitles in SubRip (.srt) format hence the name

Download it from here: http://www.autohotkey.net/~gahks/SrtSynch.ahk
Check out the Documentation here: http://www.autohotkey.net/~gahks/SrtSynch.htm
Back to top
View user's profile Send private message
gahks



Joined: 10 Jan 2009
Posts: 16

PostPosted: Tue Mar 03, 2009 7:29 pm    Post subject: Subframerate v1.1 Reply with quote

Subframerate v1.1
- new feature: set delay
- now supports converting with command line switches (without using the gui)
- the script now uses the above SrtSynch function to synchronize subtitles instead of srtrate.exe

Screenshot: http://www.autohotkey.net/~gahks/subframerate-vista.jpg

v1.1
Exe: http://www.autohotkey.net/~gahks/subframerate.exe
Source: http://www.autohotkey.net/~gahks/subframerate.ahk

v1.0
Exe and source: http://www.autohotkey.net/~gahks/old/

Command line usage:
changing the framerate:
subframerate.exe delay_or_framerate input_subtitle output_subtitle input_fps output_fps
setting a delay:
subframerate.exe delay_or_framerate input_subtitle output_subtitle delay is_delay_positive

delay_or_framerate - 0 if setting delay 1 if changing the framerate
input_subtitle - full path of the input subtitle file enclosed in quotation marks, if contains a whitespace
output_subtitle - full path of the input subtitle file enclosed in quotation marks, if contains a whitespace
delay - value of delay in ms
is_delay_positive - 0 if negative (if the subtitles are too slow) 1 if positive (if the subtitles are too fast)
input_fps - the framerate of the input subtitles to three decimal places without decimal separator (e.g. 25.000 will be 25000, 29.97 will be 29970 etc.)
output_fps - the framerate of the output subtitles to three decimal places without decimal separator

For further info see the Remarks section of the documentation of SrtSynch function.

@PeaceL I did.
Back to top
View user's profile Send private message
black_matadoor@yahoo.com



Joined: 03 Aug 2009
Posts: 1

PostPosted: Mon Aug 03, 2009 5:51 pm    Post subject: Reply with quote

it worked.
Back to top
View user's profile Send private message
locolo
Guest





PostPosted: Fri Jan 15, 2010 7:26 pm    Post subject: Reply with quote

fantastic program... works perfectly
Back to top
Joana
Guest





PostPosted: Sun Jan 17, 2010 4:17 pm    Post subject: Subtitle Framerate Changer Reply with quote

Thanks, it works perfectly end is too easy to use.

Joana
Back to top
andi87
Guest





PostPosted: Wed Jan 27, 2010 10:02 am    Post subject: Reply with quote

unicode support would be nice Very Happy
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group