34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
import os.path
|
|
|
|
from exception.danmaku import DanmakuException
|
|
from workflow.danmaku import get_file_start, diff_danmaku_files, danmaku_to_subtitle
|
|
from workflow.video import multi_gpu_encode_video_with_subtitles, quick_split_video
|
|
|
|
|
|
def do_workflow(video_file, danmaku_base_file, *danmaku_files):
|
|
if not os.path.exists(danmaku_base_file):
|
|
...
|
|
result = []
|
|
start_ts = get_file_start(danmaku_base_file)
|
|
result.append(danmaku_to_subtitle(danmaku_base_file, 0))
|
|
for danmaku_file in danmaku_files:
|
|
try:
|
|
bias = diff_danmaku_files(danmaku_base_file, danmaku_file)
|
|
if bias < -600:
|
|
print("弹幕文件", danmaku_file, "反向偏移超过10分钟")
|
|
continue
|
|
result.append(danmaku_to_subtitle(danmaku_file, bias))
|
|
except DanmakuException:
|
|
print("弹幕文件", danmaku_file, "异常")
|
|
continue
|
|
print(result)
|
|
file_need_split = multi_gpu_encode_video_with_subtitles(video_file, result, start_ts)
|
|
for filename in file_need_split:
|
|
quick_split_video(filename)
|
|
# clean files
|
|
for filename in file_need_split:
|
|
os.remove(filename)
|
|
for file in result:
|
|
os.remove(file)
|
|
|