Created
August 17, 2009 04:46
-
-
Save julik/168916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "timecode" | |
$KCODE = 'u' | |
SRT_TIMECODE_FORMAT = /((\d{2}):(\d{2}):(\d{2}),(\d+))/ | |
class SRT_Timecode < Timecode | |
def to_s | |
with_fractional_seconds.gsub(/\.(\d+)/, ',\1') | |
end | |
def self.parse_with_fractional_seconds(some_tc, fps = Timecode::DEFAULT_FPS) | |
super(some_tc.gsub(/,/, '.'), fps) | |
end | |
end | |
# Get the slip amount | |
slip = -25 | |
subtitle_file = File.read("/path/to/srt") | |
subtitle_file.gsub!(SRT_TIMECODE_FORMAT) do | a_tc | | |
SRT_Timecode.parse_with_fractional_seconds(a_tc) + slip | |
end | |
File.open("/path/to/srt_out", "w") do | f | | |
f << subtitle_file | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment