配置细分

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

View File

@ -17,8 +17,8 @@ VIDEO_RESOLUTION = "1280x720"
# [ffmpeg]
# exec
FFMPEG_EXEC = "ffmpeg"
# gpu
FFMPEG_USE_GPU = False
# nvidia_gpu
FFMPEG_USE_NVIDIA_GPU = False
# intel_gpu
FFMPEG_USE_INTEL_GPU = False
# bitrate
@ -62,9 +62,9 @@ def load_config():
VIDEO_CLIP_OVERFLOW_SEC = section.getfloat('overflow_sec', VIDEO_CLIP_OVERFLOW_SEC)
if config.has_section("ffmpeg"):
section = config['ffmpeg']
global FFMPEG_EXEC, FFMPEG_USE_GPU, FFMPEG_USE_INTEL_GPU, VIDEO_BITRATE
global FFMPEG_EXEC, FFMPEG_USE_NVIDIA_GPU, FFMPEG_USE_INTEL_GPU, VIDEO_BITRATE
FFMPEG_EXEC = section.get('exec', FFMPEG_EXEC)
FFMPEG_USE_GPU = section.getboolean('gpu', FFMPEG_USE_GPU)
FFMPEG_USE_NVIDIA_GPU = section.getboolean('nvidia_gpu', FFMPEG_USE_NVIDIA_GPU)
FFMPEG_USE_INTEL_GPU = section.getboolean('intel_gpu', FFMPEG_USE_INTEL_GPU)
VIDEO_BITRATE = section.get('bitrate', VIDEO_BITRATE)
if config.has_section("recorder"):
@ -92,7 +92,7 @@ def get_config():
},
'ffmpeg': {
'exec': FFMPEG_EXEC,
'gpu': FFMPEG_USE_GPU,
'nvidia_gpu': FFMPEG_USE_NVIDIA_GPU,
'intel_gpu': FFMPEG_USE_INTEL_GPU,
'bitrate': VIDEO_BITRATE,
},

View File

@ -64,8 +64,8 @@
<td>{{ config.ffmpeg.exec }}</td>
</tr>
<tr>
<td>GPU使用</td>
<td :class="{warning: !config.ffmpeg.gpu, success: config.ffmpeg.gpu}"></td>
<td>嘤伟达GPU</td>
<td :class="{warning: !config.ffmpeg.nvidia_gpu, success: config.ffmpeg.nvidia_gpu}"></td>
</tr>
<tr v-if="config.ffmpeg.gpu">
<td>嘤特尔GPU</td>
@ -150,7 +150,7 @@
},
ffmpeg: {
exec: "",
gpu: false,
nvidia_gpu: false,
intel_gpu: false,
bitrate: "",
}

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([