Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

把水印文本替换空文本时,如果出现空字幕的时间轴,移除空字幕时间轴 #359

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def run(self):
self.generate_subtitle_file()
if config.WORD_SEGMENTATION:
reformat.execute(os.path.join(os.path.splitext(self.video_path)[0] + '.srt'), config.REC_CHAR_TYPE)
# 去除空字幕的时间轴
if config.DELETE_EMPTY_TIMESTAMP:
reformat.remove_empty_timestamp(os.path.join(os.path.splitext(self.video_path)[0] + '.srt'))

print(config.interface_config['Main']['FinishGenerateSub'], f"{round(time.time() - start_time, 2)}s")
self.update_progress(ocr=100, frame_extract=100)
self.isFinished = True
Expand Down
13 changes: 13 additions & 0 deletions backend/tools/reformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ def remove_invalid_segment(seg, text):
sub.text = ss.strip()
subs.save(path, encoding='utf-8')

# remove_empty_timestamp 去除空字幕的时间轴
def remove_empty_timestamp(path):
subs = pysrt.open(path)
# 过滤掉空字幕
non_empty_subs = [sub for sub in subs if sub.text.strip()]

# 重新编号
for i, sub in enumerate(non_empty_subs, start=1):
sub.index = i

# 保存更新后的字幕文件
pysrt.SubRipFile(items=non_empty_subs).save(path, encoding='utf-8')


if __name__ == '__main__':
path = "/home/yao/Videos/null.srt"
Expand Down