Created
September 14, 2016 06:33
-
-
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.
This file contains 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
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