视频通用参数抽象
This commit is contained in:
parent
6af1d66120
commit
bc516973bc
@ -27,8 +27,7 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
new_filename = base_ts_to_filename(base_ts)
|
new_filename = base_ts_to_filename(base_ts)
|
||||||
new_fullpath = os.path.join(VIDEO_OUTPUT_DIR, new_filename)
|
new_fullpath = os.path.join(VIDEO_OUTPUT_DIR, new_filename)
|
||||||
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("[!]Not Enabled Both GPU")
|
||||||
print("[!]Fallback to normal")
|
|
||||||
encode_video_with_subtitles(orig_filename, subtitles, new_fullpath)
|
encode_video_with_subtitles(orig_filename, subtitles, new_fullpath)
|
||||||
return [new_fullpath]
|
return [new_fullpath]
|
||||||
_duration_str = get_video_real_duration(orig_filename)
|
_duration_str = get_video_real_duration(orig_filename)
|
||||||
@ -47,10 +46,8 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
"-copyts", "-i", orig_filename, "-vf",
|
"-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", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
|
||||||
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_fullpath0
|
new_fullpath0
|
||||||
])
|
])
|
||||||
@ -61,10 +58,8 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
"-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_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", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
|
||||||
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_fullpath1
|
new_fullpath1
|
||||||
])
|
])
|
||||||
@ -85,10 +80,8 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
"-copyts", "-i", orig_filename, "-vf",
|
"-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", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
|
||||||
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_fullpath0
|
new_fullpath0
|
||||||
])
|
])
|
||||||
@ -99,10 +92,8 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
|
|||||||
"-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_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", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-qmin", "10", "-qmax", "32", "-crf", "16",
|
|
||||||
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
|
||||||
# "-t", "10",
|
# "-t", "10",
|
||||||
new_fullpath1
|
new_fullpath1
|
||||||
])
|
])
|
||||||
@ -124,10 +115,8 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
"-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", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-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)
|
||||||
@ -139,10 +128,8 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
"-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",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-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)
|
||||||
@ -153,10 +140,8 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
"-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",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
||||||
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
|
*_common_ffmpeg_params(),
|
||||||
"-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)
|
||||||
@ -167,10 +152,8 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_fi
|
|||||||
"-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",
|
||||||
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
"-f", "mp4", "-b:v", VIDEO_BITRATE,
|
||||||
"-b:v", VIDEO_BITRATE,
|
*_common_ffmpeg_params(),
|
||||||
"-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)
|
||||||
@ -231,3 +214,11 @@ def quick_split_video(file):
|
|||||||
], stdout=subprocess.PIPE)
|
], stdout=subprocess.PIPE)
|
||||||
handle_ffmpeg_output(split_process.stdout)
|
handle_ffmpeg_output(split_process.stdout)
|
||||||
current_sec += VIDEO_CLIP_EACH_SEC
|
current_sec += VIDEO_CLIP_EACH_SEC
|
||||||
|
|
||||||
|
|
||||||
|
def _common_ffmpeg_params():
|
||||||
|
return (
|
||||||
|
"-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
|
||||||
|
"-qmin", "10", "-qmax", "48", "-crf", "26",
|
||||||
|
"-fflags", "+genpts", "-shortest"
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user