配置细分

This commit is contained in:
2022-04-22 16:06:33 +08:00
parent b80df83069
commit 44144a108a
3 changed files with 36 additions and 37 deletions

View File

@ -3,8 +3,8 @@ import subprocess
from datetime import datetime, timedelta
from typing import IO
from config import FFMPEG_EXEC, VIDEO_BITRATE, FFMPEG_USE_GPU, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC, PROD_ENV, \
FFMPEG_USE_INTEL_GPU
from config import FFMPEG_EXEC, VIDEO_BITRATE, FFMPEG_USE_NVIDIA_GPU, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC, \
PROD_ENV, FFMPEG_USE_INTEL_GPU
def get_video_real_duration(filename):
@ -15,33 +15,32 @@ def get_video_real_duration(filename):
def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_filename: str):
if FFMPEG_USE_GPU:
if FFMPEG_USE_INTEL_GPU:
print("[+]Use Intel VAAPI Acceleration")
encode_process = subprocess.Popen([
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
"-hwaccel", "vaapi", "-i", orig_filename, "-vf",
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload",
"-c:a", "copy", "-c:v", "h264_vaapi",
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
"-qmin", "10", "-qmax", "32", "-crf", "16",
# "-t", "10",
new_filename
], stdout=subprocess.PIPE)
else:
print("[+]Use Nvidia NvEnc Acceleration")
encode_process = subprocess.Popen([
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
"-hwaccel", "cuvid", "-i", orig_filename, "-vf",
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload_cuda",
"-c:a", "copy", "-c:v", "h264_nvenc",
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
"-qmin", "10", "-qmax", "32", "-crf", "16",
# "-t", "10",
new_filename
], stdout=subprocess.PIPE)
if FFMPEG_USE_NVIDIA_GPU:
print("[+]Use Nvidia NvEnc Acceleration")
encode_process = subprocess.Popen([
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
"-hwaccel", "cuvid", "-i", orig_filename, "-vf",
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload_cuda",
"-c:a", "copy", "-c:v", "h264_nvenc",
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
"-qmin", "10", "-qmax", "32", "-crf", "16",
# "-t", "10",
new_filename
], stdout=subprocess.PIPE)
elif FFMPEG_USE_INTEL_GPU:
print("[+]Use Intel VAAPI Acceleration")
encode_process = subprocess.Popen([
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-v", "0", "-y",
"-hwaccel", "vaapi", "-i", orig_filename, "-vf",
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload",
"-c:a", "copy", "-c:v", "h264_vaapi",
"-f", "mp4", "-preset:v", "fast", "-profile:v", "high", "-level", "4.1",
"-b:v", VIDEO_BITRATE, "-rc:v", "vbr", "-tune:v", "hq",
"-qmin", "10", "-qmax", "32", "-crf", "16",
# "-t", "10",
new_filename
], stdout=subprocess.PIPE)
else:
print("[+]Use CPU Encode")
encode_process = subprocess.Popen([