我有两个srt文件,cd1.srt和cd2.srt。不幸的是,srtool在任何地方都没有了,这是几年前被问到的同一个问题的答案。
但却短了下来。我尝试了https://tracker.debian.org/pkg/pysrt,它除了连接srt文件之外,什么都做了:
我甚至查过github,但只找到了这样的条目-
https://github.com/malfroid/merge-srt-subtitles
如果有人知道更好的方法,请分享。我还看了一些在线解决方案,但遗憾的是,它们都没有得到解决。
发布于 2022-12-14 14:34:49
我就是这样做的:
我首先检查了第一个srt文件的结束时间戳。在我的例子中,第二个时标的第一个时间戳是紧接着开始的,所以移动的时隙很容易推断。
有了这一点,正如@aviro在您回答的评论中所提到的,我在上面推导的timespan中使用了比斯特。
pip install pysrt
srt -i shift 1h2m58s cd2.srt然后,在合并两个srt文件之前,我们需要在cd2.srt处偏移子计数器以使它们正常工作。
为此,我使用这个python脚本生成完全偏移的cd2.srt:(用(cd1.srt中的字幕和)+1替换$numX )
# Open the input file for reading
with open('cd2.srt', 'r') as input_file:
# Open the output file for writing
with open('cd2.output.srt', 'w') as output_file:
# Iterate over each line in the input file
for line in input_file:
# Check if the line contains a single integer
if line.strip().isdigit():
# Convert the line to an integer
number = int(line)
# Add $numX to the number
number += $numX
# Write the resulting number to the output file
output_file.write(str(number) + '\n')
else:
# Write the original line to the output file
output_file.write(line)然后通过:cat cd1.srt cd2.output.srt > final.srt执行最后的合并
现在,字幕应该与您新合并的视频文件一起工作得很好!
https://unix.stackexchange.com/questions/687658
复制相似问题