双卡加持(虽然不一定用),避免生成音视频长短不一的文件
This commit is contained in:
parent
fab9e65113
commit
30d006c1bb
@ -32,58 +32,72 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
return [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 * 3):
|
if duration > (VIDEO_CLIP_EACH_SEC * 5):
|
||||||
# qsv 压制前2段,剩余交由nvenc压制
|
# qsv 压制前2段,剩余交由nvenc压制
|
||||||
new_filename0 = base_ts_to_filename(base_ts)
|
_slices = int(duration / VIDEO_CLIP_EACH_SEC)
|
||||||
new_filename1 = base_ts_to_filename(base_ts + VIDEO_CLIP_EACH_SEC * 2)
|
new_filename0 = base_ts_to_filename(base_ts + (_slices - 1) * VIDEO_CLIP_EACH_SEC)
|
||||||
|
new_filename1 = base_ts_to_filename(base_ts)
|
||||||
|
print("[+]Use Intel QSV Acceleration")
|
||||||
encode_process0 = subprocess.Popen([
|
encode_process0 = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "qsv", "-t", str(VIDEO_CLIP_EACH_SEC * 2 + (VIDEO_CLIP_OVERFLOW_SEC * 0.8)), "-i", orig_filename, "-vf",
|
"-hwaccel", "qsv", "-ss", str((_slices - 1) * VIDEO_CLIP_EACH_SEC),
|
||||||
|
"-copyts", "-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",
|
||||||
"-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",
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename0
|
new_filename0
|
||||||
])
|
])
|
||||||
|
print("[+]Use Nvidia NvEnc Acceleration")
|
||||||
encode_process1 = subprocess.Popen([
|
encode_process1 = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-ss", str(VIDEO_CLIP_EACH_SEC * 2), "-copyts", "-i", orig_filename, "-vf",
|
"-t", str((_slices - 1) * 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_nvenc", "-ss", str(VIDEO_CLIP_EACH_SEC * 2),
|
"-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",
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename1
|
new_filename1
|
||||||
])
|
])
|
||||||
encode_process1.wait()
|
|
||||||
encode_process0.wait()
|
encode_process0.wait()
|
||||||
|
encode_process1.wait()
|
||||||
return [new_filename0, new_filename1]
|
return [new_filename0, new_filename1]
|
||||||
elif duration > (VIDEO_CLIP_EACH_SEC * 1):
|
elif duration > (VIDEO_CLIP_EACH_SEC * 3):
|
||||||
# 至少也要能切2片,才用双GPU加速
|
# 至少也要能切2片,才用双GPU加速
|
||||||
new_filename0 = base_ts_to_filename(base_ts, True)
|
_slices = int(duration / VIDEO_CLIP_EACH_SEC)
|
||||||
new_filename1 = base_ts_to_filename(base_ts + VIDEO_CLIP_EACH_SEC)
|
new_filename0 = base_ts_to_filename(base_ts + _slices * VIDEO_CLIP_EACH_SEC, True)
|
||||||
|
new_filename1 = base_ts_to_filename(base_ts)
|
||||||
|
print("[+]Use Intel QSV Acceleration")
|
||||||
encode_process0 = subprocess.Popen([
|
encode_process0 = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-hwaccel", "qsv", "-t", str(VIDEO_CLIP_EACH_SEC + (VIDEO_CLIP_OVERFLOW_SEC * 0.8)), "-i", orig_filename, "-vf",
|
"-hwaccel", "qsv", "-ss", str(_slices * VIDEO_CLIP_EACH_SEC),
|
||||||
|
"-copyts", "-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",
|
||||||
"-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",
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename0
|
new_filename0
|
||||||
])
|
])
|
||||||
|
print("[+]Use Nvidia NvEnc Acceleration")
|
||||||
encode_process1 = subprocess.Popen([
|
encode_process1 = subprocess.Popen([
|
||||||
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y",
|
||||||
"-ss", str(VIDEO_CLIP_EACH_SEC), "-copyts", "-i", orig_filename, "-vf",
|
"-t", str(_slices * 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_nvenc", "-ss", str(VIDEO_CLIP_EACH_SEC),
|
"-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",
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename1
|
new_filename1
|
||||||
])
|
])
|
||||||
@ -108,6 +122,7 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
"-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",
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename
|
new_filename
|
||||||
], stdout=subprocess.PIPE)
|
], stdout=subprocess.PIPE)
|
||||||
@ -122,6 +137,7 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
"-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",
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename
|
new_filename
|
||||||
], stdout=subprocess.PIPE)
|
], stdout=subprocess.PIPE)
|
||||||
@ -135,6 +151,7 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
"-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",
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename
|
new_filename
|
||||||
], stdout=subprocess.PIPE)
|
], stdout=subprocess.PIPE)
|
||||||
@ -148,6 +165,7 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
"-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",
|
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr",
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_filename
|
new_filename
|
||||||
], stdout=subprocess.PIPE)
|
], stdout=subprocess.PIPE)
|
||||||
@ -200,6 +218,7 @@ def quick_split_video(file):
|
|||||||
"-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),
|
||||||
|
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
||||||
"{}.mp4".format(current_dt)
|
"{}.mp4".format(current_dt)
|
||||||
], stdout=subprocess.PIPE)
|
], stdout=subprocess.PIPE)
|
||||||
handle_ffmpeg_output(split_process.stdout)
|
handle_ffmpeg_output(split_process.stdout)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user