避免添加了反向偏移过大的弹幕文件
This commit is contained in:
parent
87eb208669
commit
fcd61d7a09
@ -11,6 +11,9 @@ from model.DanmakuClip import DanmakuClip
|
||||
from model.VideoClip import VideoClip
|
||||
from model.Workflow import Workflow
|
||||
from worker.danmaku import do_workflow
|
||||
from workflow.danmaku import get_file_start
|
||||
from workflow.video import get_video_real_duration
|
||||
from exception.danmaku import DanmakuException
|
||||
|
||||
blueprint = Blueprint("api_bilirecorder", __name__, url_prefix="/api/bilirecorder")
|
||||
|
||||
@ -86,6 +89,7 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
|
||||
full_path = clip.full_path
|
||||
pre_file_name = os.path.splitext(full_path)[0]
|
||||
# 理论上也只有一个结果
|
||||
start_time_ts = None
|
||||
for danmaku_file in glob("{}*xml".format(pre_file_name)):
|
||||
relpath = os.path.relpath(danmaku_file, BILILIVE_RECORDER_DIRECTORY)
|
||||
danmaku = DanmakuClip.query.filter(
|
||||
@ -93,6 +97,10 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
|
||||
DanmakuClip.base_path == BILILIVE_RECORDER_DIRECTORY
|
||||
).first()
|
||||
if danmaku is None:
|
||||
try:
|
||||
start_time_ts = get_file_start(danmaku_file)
|
||||
except DanmakuException:
|
||||
start_time_ts = None
|
||||
danmaku = DanmakuClip()
|
||||
danmaku.file = relpath
|
||||
danmaku.base_path = BILILIVE_RECORDER_DIRECTORY
|
||||
@ -100,6 +108,10 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
|
||||
danmaku.workflow = workflow
|
||||
db.session.add(danmaku)
|
||||
workflow.danmaku_clips.append(danmaku)
|
||||
if start_time_ts is None:
|
||||
if clip.duration is None or clip.duration == 0:
|
||||
clip.duration = get_video_real_duration(clip.full_path)
|
||||
start_time_ts = datetime.now().timestamp() - clip.duration
|
||||
for danmaku_file in glob(os.path.join(XIGUALIVE_RECORDER_DIRECTORY, "*.xml")):
|
||||
relpath = os.path.relpath(danmaku_file, XIGUALIVE_RECORDER_DIRECTORY)
|
||||
danmaku = DanmakuClip.query.filter(
|
||||
@ -107,10 +119,17 @@ def collect_danmaku_files(workflow: Optional[Workflow]):
|
||||
DanmakuClip.base_path == XIGUALIVE_RECORDER_DIRECTORY
|
||||
).first()
|
||||
if danmaku is None:
|
||||
try:
|
||||
start_time_xg = get_file_start(danmaku_file)
|
||||
except DanmakuException:
|
||||
continue
|
||||
bias = start_time_xg - start_time_ts
|
||||
if bias < -600:
|
||||
print("弹幕文件", danmaku_file, "反向偏移超过10分钟")
|
||||
danmaku = DanmakuClip()
|
||||
danmaku.file = relpath
|
||||
danmaku.base_path = XIGUALIVE_RECORDER_DIRECTORY
|
||||
danmaku.offset = 0
|
||||
danmaku.offset = bias
|
||||
danmaku.workflow = workflow
|
||||
db.session.add(danmaku)
|
||||
workflow.danmaku_clips.append(danmaku)
|
||||
|
@ -14,11 +14,14 @@ def do_workflow(video_file, danmaku_base_file, *danmaku_files):
|
||||
base_start = datetime.fromtimestamp(start_ts)
|
||||
new_file_name = base_start.strftime("%Y%m%d_%H%M.flv")
|
||||
result.append(danmaku_to_subtitle(danmaku_base_file, 0))
|
||||
for file in danmaku_files:
|
||||
for danmaku_file in danmaku_files:
|
||||
try:
|
||||
result.append(danmaku_to_subtitle(file, diff_danmaku_files(danmaku_base_file, file)))
|
||||
bias = diff_danmaku_files(danmaku_base_file, danmaku_file)
|
||||
if bias < -600:
|
||||
print("弹幕文件", danmaku_file, "反向偏移超过10分钟")
|
||||
result.append(danmaku_to_subtitle(danmaku_file, bias))
|
||||
except DanmakuException:
|
||||
print("弹幕文件", file, "异常")
|
||||
print("弹幕文件", danmaku_file, "异常")
|
||||
continue
|
||||
print(result)
|
||||
encode_video_with_subtitles(video_file, result, new_file_name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user