cdown/srt

Niche offset merging for subtitles with same timestamps

Closed this issue · 4 comments

kjfun commented

First of all, thanks for the great program. An issue I'm having is that tvs and some video players won't properly display dual language subtitles muxed with the srt-mux tool. When there are two subtitles of different languages and with the same timestamps, only the second subtitle will be displayed. If I go in and manually edit the subtitles so that there is only one timestamp, the issue goes away. For increased compatibility and usefulness, it'd be great if there was an option in the srt-mux tool to combine subtitles with the same timestamps so that there is only one subtitle per timestamp with the content from both languages. Thanks.

cdown commented

Hey! That sounds... not great, but yes, it shouldn't be too hard to add that functionality. I suppose we can do it as part of the sliding window check.

kjfun commented

I know little of coding. That said, an approach that I came up with is to run the muxed file through the script below. I've tested the regex substitution in the script quite a bit and it has worked every time. After running the script, I can then remux the file to properly renumber all the subtitles. Thought I'd share. Perhaps it helps you come up with a more elegant solution.

#!/usr/bin/env python

import re
import sys
import fileinput

filename = sys.argv[-1]
with open(filename, 'r') as fin:
file1 = fin.read() # read entire file as file1
fout = open("1.tmp", 'w') # outfile
p = re.compile("([0-9]+)\n([0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9] --> [0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9])\n(.)\n\n[0-9]+\n\2\n(.)") # pattern
newlines = p.sub("\1\n\2\n\3\n\4",file1) # replace with capture groups
fout.write(newlines)
fin.close()
fout.close()

cdown commented

The trouble is that works at the character level, but we need to work at the subtitle level.

Realistically I'm unlikely to implement this soon, but patches are welcome :-)

cdown commented

Closing without prejudice since this seems fairly specific to a single person's needs, feel free to submit a PR still.