handbrake直接切开合并
This commit is contained in:
parent
657c6bcc11
commit
f648a84bbd
@ -303,22 +303,28 @@ class WorkerThread(QThread):
|
|||||||
new_subtitle_name = danmaku_to_subtitle(danmaku, time_shift)
|
new_subtitle_name = danmaku_to_subtitle(danmaku, time_shift)
|
||||||
job.subtitles.append(new_subtitle_name)
|
job.subtitles.append(new_subtitle_name)
|
||||||
# 压制
|
# 压制
|
||||||
files_need_split = self.encode_video_with_subtitles(job.video, job.subtitles, base_start_ts)
|
self.encode_video_with_subtitles(job.video, job.subtitles, base_start_ts)
|
||||||
for _f in files_need_split:
|
|
||||||
need_delete = self.quick_split_video(_f)
|
|
||||||
if need_delete:
|
|
||||||
os.remove(_f)
|
|
||||||
for _f in job.subtitles:
|
for _f in job.subtitles:
|
||||||
if os.path.isfile(_f):
|
if os.path.isfile(_f):
|
||||||
os.remove(_f)
|
os.remove(_f)
|
||||||
|
|
||||||
def encode_video_with_subtitles(self, orig_filename: str, subtitles: list[str], base_ts: float):
|
def encode_video_with_subtitles(self, orig_filename: str, subtitles: list[str], base_ts: float):
|
||||||
new_filename = base_ts_to_filename(base_ts, False)
|
create_dt = datetime.fromtimestamp(base_ts)
|
||||||
new_fullpath = os.path.join(VIDEO_OUTPUT_DIR, new_filename)
|
duration = self.get_video_real_duration(orig_filename)
|
||||||
process = get_encode_process_use_handbrake(orig_filename, subtitles, new_fullpath)
|
current_sec = 0
|
||||||
self.handle_handbrake_output(process.stdout)
|
while current_sec < duration:
|
||||||
process.wait()
|
if (current_sec + VIDEO_CLIP_OVERFLOW_SEC * 2) > duration:
|
||||||
return [new_fullpath]
|
print("[-]Less than 2 overflow sec, skip")
|
||||||
|
break
|
||||||
|
current_dt = (create_dt + timedelta(seconds=current_sec)).strftime("%Y%m%d_%H%M_")
|
||||||
|
process = get_encode_process_use_handbrake(orig_filename,
|
||||||
|
subtitles,
|
||||||
|
os.path.join(VIDEO_OUTPUT_DIR, "{}.mp4".format(current_dt)),
|
||||||
|
current_sec,
|
||||||
|
current_sec + VIDEO_CLIP_EACH_SEC + VIDEO_CLIP_OVERFLOW_SEC)
|
||||||
|
self.handle_handbrake_output(process.stdout)
|
||||||
|
process.wait()
|
||||||
|
current_sec += VIDEO_CLIP_EACH_SEC
|
||||||
|
|
||||||
def quick_split_video(self, file):
|
def quick_split_video(self, file):
|
||||||
if not os.path.isfile(file):
|
if not os.path.isfile(file):
|
||||||
@ -429,13 +435,15 @@ def danmaku_to_subtitle(file: Union[os.PathLike[str], str], time_shift: float):
|
|||||||
return new_subtitle_name
|
return new_subtitle_name
|
||||||
|
|
||||||
|
|
||||||
def get_encode_process_use_handbrake(orig_filename: str, subtitles: list[str], new_filename: str):
|
def get_encode_process_use_handbrake(orig_filename: str, subtitles: list[str], new_filename: str, start_time: int, stop_time: int):
|
||||||
print("[+]Use HandBrakeCli")
|
print("[+]Use HandBrakeCli")
|
||||||
encode_process = subprocess.Popen([
|
encode_process = subprocess.Popen([
|
||||||
HANDBRAKE_EXEC, *_common_handbrake_setting(),
|
HANDBRAKE_EXEC, *_common_handbrake_setting(),
|
||||||
"--preset-import-file", HANDBRAKE_PRESET_FILE, "--preset", HANDBRAKE_PRESET,
|
"--preset-import-file", HANDBRAKE_PRESET_FILE, "--preset", HANDBRAKE_PRESET,
|
||||||
|
"--start-at", "seconds:{}".format(start_time), "--stop-at", "seconds:{}".format(stop_time),
|
||||||
"-i", orig_filename, "-x", HANDBRAKE_ENCOPT,
|
"-i", orig_filename, "-x", HANDBRAKE_ENCOPT,
|
||||||
"--ssa-file", ",".join(i for i in subtitles),
|
"--ssa-file", ",".join(i for i in subtitles),
|
||||||
|
"--ssa-offset", "{}000".format(start_time),
|
||||||
"--ssa-burn", ",".join("%d" % (i+1) for i in range(len(subtitles))),
|
"--ssa-burn", ",".join("%d" % (i+1) for i in range(len(subtitles))),
|
||||||
"-o",
|
"-o",
|
||||||
new_filename
|
new_filename
|
||||||
|
Loading…
x
Reference in New Issue
Block a user