From 44144a108a8c015a6764b4834730052b0eb2a20b Mon Sep 17 00:00:00 2001
From: Jerry Yan <792602257@qq.com>
Date: Fri, 22 Apr 2022 16:06:33 +0800
Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=BB=86=E5=88=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
config.py | 10 ++++----
templates/index.html | 6 ++---
workflow/video.py | 57 ++++++++++++++++++++++----------------------
3 files changed, 36 insertions(+), 37 deletions(-)
diff --git a/config.py b/config.py
index aa9aad5..1472e12 100644
--- a/config.py
+++ b/config.py
@@ -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,
},
diff --git a/templates/index.html b/templates/index.html
index a2c9f93..062e9c6 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -64,8 +64,8 @@
{{ config.ffmpeg.exec }} |
- GPU使用 |
- |
+ 嘤伟达GPU |
+ |
嘤特尔GPU |
@@ -150,7 +150,7 @@
},
ffmpeg: {
exec: "",
- gpu: false,
+ nvidia_gpu: false,
intel_gpu: false,
bitrate: "",
}
diff --git a/workflow/video.py b/workflow/video.py
index bd02f58..1ec71d3 100644
--- a/workflow/video.py
+++ b/workflow/video.py
@@ -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([