Skip to content

Instantly share code, notes, and snippets.

@maurcs
Created September 14, 2016 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maurcs/577b3d5a8a1b3096b154d26947c2c93f to your computer and use it in GitHub Desktop.
Save maurcs/577b3d5a8a1b3096b154d26947c2c93f to your computer and use it in GitHub Desktop.
cleans up timecodes on subtitle text files to trim one frame from the in-point of each line. Adobe Encore was giving me PGC errors on my timeline. Putting a frame of space between each subtitle was the only fix that worked for me.
new_file_path = "path/to/subtitle_fixed_file.txt"
File.truncate(new_file_path, 0)
new_file = File.open(new_file_path, "w")
file = File.open("path/to/subtitle_file.txt", "r").readlines.each do |line|
reg = /;(\d{2}) \d{2};/
match = line.match(reg)
if match.class == MatchData
m = match[1]
frame_number = m.to_i
if frame_number < 23
frame_number += 1
end
new_frame = frame_number.to_s.rjust(2, "0")
new_line = line.gsub(/(;)(#{m})(\s\d{2})/, "\\1#{new_frame}\\3")
else
new_line = line
end
new_file.puts new_line
end
new_file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment