长时间读者第一次问问.
我正在编写一些我需要编辑时间戳的vtt(隐藏式字幕)文件.该文件的格式如下:
177
00:07:37.450 --> 00:07:39.690
- [Liz] How would you suggest an organization devise
178
00:07:39.690 --> 00:07:41.719
the accountabilities for culture?
179
00:07:41.719 --> 00:07:43.690
- [Tamara] It is a shared accountability
我编写了以下代码来读取文件,计算新的时间戳(慢5%)并吐出新的时间戳:
from sys import argv
script, filename = argv
adjustment = input("Adjustment multiplier: ")
video = open(filename, "r+")
lines = video.readlines()
video.seek(0)
for l in lines:
if l[:2] == "00":
#here I've omitted a lot of calculations to turn the timestamps
#into milliseconds, apply the adjustment multiplier, and turn them back into
#minutes, seconds, and milliseconds.
new_line = str(#concatenation of new values into timestamp format)
video.write(new_line)
video.close()
计算效果很好,但问题是它将所有新行转储到文件的开头,而不是写入每个时间戳行并跳过其余的.
我很想听听你们的想法!我已经和它搏斗了一段时间并尝试了很多东西但是还没能完成它.
谢谢!