双编码逻辑更新
This commit is contained in:
parent
ea2de8270b
commit
f1729ffc32
@ -18,7 +18,7 @@ def base_ts_to_filename(start_ts: float, is_mp4=False) -> str:
|
|||||||
|
|
||||||
def get_video_real_duration(filename):
|
def get_video_real_duration(filename):
|
||||||
ffmpeg_process = subprocess.Popen([
|
ffmpeg_process = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-i", filename, "-c", "copy", "-f", "null", "-"
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-i", filename, "-c", "copy", "-f", "null", "-"
|
||||||
], stdout=subprocess.PIPE)
|
], stdout=subprocess.PIPE)
|
||||||
return handle_ffmpeg_output(ffmpeg_process.stdout)
|
return handle_ffmpeg_output(ffmpeg_process.stdout)
|
||||||
|
|
||||||
@ -28,16 +28,17 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
if not (FFMPEG_USE_NVIDIA_GPU and FFMPEG_USE_INTEL_GPU):
|
if not (FFMPEG_USE_NVIDIA_GPU and FFMPEG_USE_INTEL_GPU):
|
||||||
print("[!]Please Enable Both Of Encode Acceleration")
|
print("[!]Please Enable Both Of Encode Acceleration")
|
||||||
print("[!]Fallback to normal")
|
print("[!]Fallback to normal")
|
||||||
return encode_video_with_subtitles(orig_filename, subtitles, new_filename)
|
encode_video_with_subtitles(orig_filename, subtitles, new_filename)
|
||||||
|
return [new_filename]
|
||||||
_duration_str = get_video_real_duration(orig_filename)
|
_duration_str = get_video_real_duration(orig_filename)
|
||||||
duration = duration_str_to_float(_duration_str)
|
duration = duration_str_to_float(_duration_str)
|
||||||
if duration >= (VIDEO_CLIP_EACH_SEC * 5):
|
if duration > (VIDEO_CLIP_EACH_SEC * 3):
|
||||||
# qsv 压制前2段,剩余交由nvenc压制
|
# qsv 压制前2段,剩余交由nvenc压制
|
||||||
new_filename0 = base_ts_to_filename(base_ts)
|
new_filename0 = base_ts_to_filename(base_ts)
|
||||||
new_filename1 = base_ts_to_filename(base_ts + VIDEO_CLIP_EACH_SEC * 2)
|
new_filename1 = base_ts_to_filename(base_ts + VIDEO_CLIP_EACH_SEC * 2)
|
||||||
encode_process0 = subprocess.Popen([
|
encode_process0 = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "qsv", "-t", str(VIDEO_CLIP_EACH_SEC * 2 + VIDEO_CLIP_OVERFLOW_SEC), "-i", orig_filename, "-vf",
|
"-hwaccel", "qsv", "-t", str(VIDEO_CLIP_EACH_SEC * 2 + (VIDEO_CLIP_OVERFLOW_SEC * 0.8)), "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles),
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
"-c:a", "copy", "-c:v", "h264_qsv",
|
"-c:a", "copy", "-c:v", "h264_qsv",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
||||||
@ -45,26 +46,28 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename0
|
new_filename0
|
||||||
], stdout=subprocess.PIPE)
|
])
|
||||||
encode_process1 = subprocess.Popen([
|
encode_process1 = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "cuvid", "-ss", str(VIDEO_CLIP_EACH_SEC * 2), "-i", orig_filename, "-vf",
|
"-ss", str(VIDEO_CLIP_EACH_SEC * 2), "-copyts", "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload_cuda",
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
"-c:a", "copy", "-c:v", "h264_nvenc",
|
"-c:a", "copy", "-c:v", "h264_nvenc", "-ss", str(VIDEO_CLIP_EACH_SEC * 2),
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename1
|
new_filename1
|
||||||
], stdout=subprocess.PIPE)
|
])
|
||||||
|
encode_process1.wait()
|
||||||
|
encode_process0.wait()
|
||||||
return [new_filename0, new_filename1]
|
return [new_filename0, new_filename1]
|
||||||
elif duration >= (VIDEO_CLIP_EACH_SEC * 3):
|
elif duration > (VIDEO_CLIP_EACH_SEC * 1):
|
||||||
# 至少也要能切3片,才用双GPU加速
|
# 至少也要能切2片,才用双GPU加速
|
||||||
new_filename0 = base_ts_to_filename(base_ts, True)
|
new_filename0 = base_ts_to_filename(base_ts, True)
|
||||||
new_filename1 = base_ts_to_filename(base_ts + VIDEO_CLIP_EACH_SEC)
|
new_filename1 = base_ts_to_filename(base_ts + VIDEO_CLIP_EACH_SEC)
|
||||||
encode_process0 = subprocess.Popen([
|
encode_process0 = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "qsv", "-t", str(VIDEO_CLIP_EACH_SEC + VIDEO_CLIP_OVERFLOW_SEC), "-i", orig_filename, "-vf",
|
"-hwaccel", "qsv", "-t", str(VIDEO_CLIP_EACH_SEC + (VIDEO_CLIP_OVERFLOW_SEC * 0.8)), "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles),
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
"-c:a", "copy", "-c:v", "h264_qsv",
|
"-c:a", "copy", "-c:v", "h264_qsv",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
||||||
@ -72,18 +75,20 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename0
|
new_filename0
|
||||||
], stdout=subprocess.PIPE)
|
])
|
||||||
encode_process1 = subprocess.Popen([
|
encode_process1 = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "cuvid", "-ss", str(VIDEO_CLIP_EACH_SEC), "-i", orig_filename, "-vf",
|
"-ss", str(VIDEO_CLIP_EACH_SEC), "-copyts", "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload_cuda",
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
"-c:a", "copy", "-c:v", "h264_nvenc",
|
"-c:a", "copy", "-c:v", "h264_nvenc", "-ss", str(VIDEO_CLIP_EACH_SEC),
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename1
|
new_filename1
|
||||||
], stdout=subprocess.PIPE)
|
])
|
||||||
|
encode_process1.wait()
|
||||||
|
encode_process0.wait()
|
||||||
return [new_filename1]
|
return [new_filename1]
|
||||||
else:
|
else:
|
||||||
print("[-]VideoClip to short,", duration)
|
print("[-]VideoClip to short,", duration)
|
||||||
@ -96,8 +101,8 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
if FFMPEG_USE_NVIDIA_GPU:
|
if FFMPEG_USE_NVIDIA_GPU:
|
||||||
print("[+]Use Nvidia NvEnc Acceleration")
|
print("[+]Use Nvidia NvEnc Acceleration")
|
||||||
encode_process = subprocess.Popen([
|
encode_process = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "cuvid", "-i", orig_filename, "-vf",
|
"-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload_cuda",
|
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload_cuda",
|
||||||
"-c:a", "copy", "-c:v", "h264_nvenc",
|
"-c:a", "copy", "-c:v", "h264_nvenc",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
||||||
@ -110,7 +115,7 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
if platform.system().lower() == "windows":
|
if platform.system().lower() == "windows":
|
||||||
print("[+]Use Intel QSV Acceleration")
|
print("[+]Use Intel QSV Acceleration")
|
||||||
encode_process = subprocess.Popen([
|
encode_process = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "qsv", "-i", orig_filename, "-vf",
|
"-hwaccel", "qsv", "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles),
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
"-c:a", "copy", "-c:v", "h264_qsv",
|
"-c:a", "copy", "-c:v", "h264_qsv",
|
||||||
@ -123,7 +128,7 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
else:
|
else:
|
||||||
print("[+]Use Intel VAAPI Acceleration")
|
print("[+]Use Intel VAAPI Acceleration")
|
||||||
encode_process = subprocess.Popen([
|
encode_process = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "vaapi", "-i", orig_filename, "-vf",
|
"-hwaccel", "vaapi", "-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload",
|
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload",
|
||||||
"-c:a", "copy", "-c:v", "h264_vaapi",
|
"-c:a", "copy", "-c:v", "h264_vaapi",
|
||||||
@ -136,7 +141,7 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
else:
|
else:
|
||||||
print("[+]Use CPU Encode")
|
print("[+]Use CPU Encode")
|
||||||
encode_process = subprocess.Popen([
|
encode_process = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-i", orig_filename, "-vf",
|
"-i", orig_filename, "-vf",
|
||||||
",".join("subtitles=%s" % i for i in subtitles),
|
",".join("subtitles=%s" % i for i in subtitles),
|
||||||
"-c:a", "copy", "-c:v", "h264",
|
"-c:a", "copy", "-c:v", "h264",
|
||||||
@ -187,7 +192,7 @@ def quick_split_video(file):
|
|||||||
print("CUR_DT", current_dt)
|
print("CUR_DT", current_dt)
|
||||||
print("BIAS_T", current_sec)
|
print("BIAS_T", current_sec)
|
||||||
split_process = subprocess.Popen([
|
split_process = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-y", "-hide_banner", "-progress", "-", "-v", "0",
|
FFMPEG_EXEC, "-y", "-hide_banner", "-progress", "-", "-loglevel", "error",
|
||||||
"-ss", str(current_sec),
|
"-ss", str(current_sec),
|
||||||
"-i", file_name, "-c", "copy", "-f", "mp4",
|
"-i", file_name, "-c", "copy", "-f", "mp4",
|
||||||
"-t", str(VIDEO_CLIP_EACH_SEC + VIDEO_CLIP_OVERFLOW_SEC),
|
"-t", str(VIDEO_CLIP_EACH_SEC + VIDEO_CLIP_OVERFLOW_SEC),
|
||||||
|
@ -25,6 +25,7 @@ def do_workflow(video_file, danmaku_base_file, *danmaku_files):
|
|||||||
for filename in file_need_split:
|
for filename in file_need_split:
|
||||||
quick_split_video(filename)
|
quick_split_video(filename)
|
||||||
# clean files
|
# clean files
|
||||||
|
for filename in file_need_split:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
for file in result:
|
for file in result:
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user