Hi friends, thanks for the help.
I need to export the "timing" ("duration") of the dialogues of each subtitle.
---------- For example, export from: ----------
1
00:01:10,000 --> 00:01:50,000
Dialogue 1
2
00:07:20,840 --> 00:09:20,845
Dialogue 2
---------- Convert o export to file to result in: ----------
1
00:01:10,000 --> 00:01:50,000 = 00:00:40,000
Dialogue 1
2
00:07:20,840 --> 00:09:20,840 = 00:02:00,005
Dialogue 2
---------- Or also in: ----------
1
00:00:40,000
Dialogue 1
2
00:02:00,005
Dialogue 2
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 3 of 3
Thread
-
-
using python, save this file as totaltimes.py:
Code:def sec2time(sec): ''' Convert seconds to 'D days, HH:MM:SS.FFF' ''' m, s = divmod(sec, 60) h, m = divmod(m, 60) d, h = divmod(h, 24) pattern = '%%02d:%%02d:%%0%d.%df' % (6, 3) if d == 0: return pattern % (h, m, s) return (f'{h:d}:{m:02d}:{s:02d}') def time2sec(time): ''' converts HH:MM:SS.FFF or HH:MM:SS,FFF string to seconds ''' time = time.strip()[:12].replace(',','.') h, m, s = map(float, time.split(':')) return h * 3600 + m * 60 + s def main(old_srt, new_srt): with open(old_srt, 'r+') as f, open(new_srt, 'w') as w: for line in f: if '-->' in line: start_sec, end_sec, *_ = map(time2sec, line.split('-->')) difference_time = sec2time(end_sec - start_sec).replace('.',',') w.write(f'{line[:-1]} = {difference_time}\n') #w.write(f'{difference_time}\n') else: w.write(line) if __name__ == '__main__': ''' Using command line: python "totaltimes.py" "old.srt" "new.srt" ''' import os import sys source_paths = [] if len(sys.argv) > 1: for i, path in enumerate(sys.argv[1:]): if i < 1 and not os.path.isfile(path): raise ValueError(f'Not a valid path or file does not exist: {path}') source_paths.append(path) if i < 1: raise ValueError(f'Two path arguments needed') source_paths = source_paths[0:2] source_paths = [os.path.abspath(path) for path in source_paths] main(source_paths[0], source_paths[1])
Code:import totaltimes from pathlib import Path original = r"D:/path/my_subtitles.srt" original = Path(original) new = original.parent.joinpath(f'new_{original.name}') #just adds "new_" for a new file totaltimes.main(original, new)
Last edited by _Al_; 25th Jun 2022 at 17:29.
Similar Threads
-
Subtitle Edit - Export to SUP: Lines are badly misaligned
By Sapito in forum SubtitleReplies: 0Last Post: 12th Feb 2022, 02:27 -
How To Detect Timecode Duration Error in Subtitle Edit
By violettiong in forum SubtitleReplies: 1Last Post: 23rd Nov 2021, 10:49 -
(Subtitle Edit) Easy way to dynamically adjust sub duration?
By Asterra in forum SubtitleReplies: 1Last Post: 18th Feb 2021, 12:06 -
Tsmuxr GUI & Windows 10 does not export subtitle file?
By kpic in forum EditingReplies: 0Last Post: 7th Dec 2018, 08:03 -
Interlaced Audio Duration Longer than Video Duration (lip-sync issue)
By senlab in forum Video ConversionReplies: 7Last Post: 27th Aug 2018, 15:36