Skip to content

Instantly share code, notes, and snippets.

@julik
Created August 17, 2009 04:46
Show Gist options
  • Save julik/168916 to your computer and use it in GitHub Desktop.
Save julik/168916 to your computer and use it in GitHub Desktop.
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