From f70d04f1b258f925a97872f8ed10ba803669ad6a Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 17 May 2022 17:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0output=5Fdir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 6 +++++- workflow/video.py | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/config.py b/config.py index 86dcc8c..4151a81 100644 --- a/config.py +++ b/config.py @@ -33,6 +33,8 @@ VIDEO_CLIP_OVERFLOW_SEC = 5 BILILIVE_RECORDER_DIRECTORY = "./" # xigua_dir XIGUALIVE_RECORDER_DIRECTORY = "./" +# output_dir +VIDEO_OUTPUT_DIR = "/mnt/" def load_config(): @@ -65,10 +67,11 @@ def load_config(): FFMPEG_USE_INTEL_GPU = section.getboolean('intel_gpu', FFMPEG_USE_INTEL_GPU) VIDEO_BITRATE = section.get('bitrate', VIDEO_BITRATE) if config.has_section("recorder"): - global BILILIVE_RECORDER_DIRECTORY, XIGUALIVE_RECORDER_DIRECTORY + global BILILIVE_RECORDER_DIRECTORY, XIGUALIVE_RECORDER_DIRECTORY, VIDEO_OUTPUT_DIR section = config['recorder'] BILILIVE_RECORDER_DIRECTORY = section.get('bili_dir', BILILIVE_RECORDER_DIRECTORY) XIGUALIVE_RECORDER_DIRECTORY = section.get('xigua_dir', XIGUALIVE_RECORDER_DIRECTORY) + VIDEO_OUTPUT_DIR = section.get('output_dir', VIDEO_OUTPUT_DIR) return True @@ -96,6 +99,7 @@ def get_config(): 'recorder': { 'bili_dir': BILILIVE_RECORDER_DIRECTORY, 'xigua_dir': XIGUALIVE_RECORDER_DIRECTORY, + 'output_dir': VIDEO_OUTPUT_DIR, }, } return config diff --git a/workflow/video.py b/workflow/video.py index c482221..90e5511 100644 --- a/workflow/video.py +++ b/workflow/video.py @@ -5,7 +5,7 @@ from datetime import datetime, timedelta from typing import IO from config import FFMPEG_EXEC, VIDEO_BITRATE, FFMPEG_USE_NVIDIA_GPU, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC, \ - FFMPEG_USE_INTEL_GPU + FFMPEG_USE_INTEL_GPU, VIDEO_OUTPUT_DIR def base_ts_to_filename(start_ts: float, is_mp4=False) -> str: @@ -25,11 +25,12 @@ def get_video_real_duration(filename): def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[str], base_ts: float): new_filename = base_ts_to_filename(base_ts) + new_fullpath = os.path.join(VIDEO_OUTPUT_DIR, new_filename) if not (FFMPEG_USE_NVIDIA_GPU and FFMPEG_USE_INTEL_GPU): print("[!]Please Enable Both Of Encode Acceleration") print("[!]Fallback to normal") - encode_video_with_subtitles(orig_filename, subtitles, new_filename) - return [new_filename] + encode_video_with_subtitles(orig_filename, subtitles, new_fullpath) + return [new_fullpath] _duration_str = get_video_real_duration(orig_filename) duration = duration_str_to_float(_duration_str) if duration > (VIDEO_CLIP_EACH_SEC * 5): @@ -37,6 +38,8 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st _slices = int(duration / VIDEO_CLIP_EACH_SEC) new_filename0 = base_ts_to_filename(base_ts + (_slices - 1) * VIDEO_CLIP_EACH_SEC) new_filename1 = base_ts_to_filename(base_ts) + new_fullpath0 = os.path.join(VIDEO_OUTPUT_DIR, new_filename0) + new_fullpath1 = os.path.join(VIDEO_OUTPUT_DIR, new_filename1) print("[+]Use Intel QSV Acceleration") encode_process0 = subprocess.Popen([ FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y", @@ -49,7 +52,7 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st "-qmin", "10", "-qmax", "32", "-crf", "16", "-fflags", "+genpts", "-shortest", "-movflags", "faststart", # "-t", "10", - new_filename0 + new_fullpath0 ]) print("[+]Use Nvidia NvEnc Acceleration") encode_process1 = subprocess.Popen([ @@ -63,7 +66,7 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st "-qmin", "10", "-qmax", "32", "-crf", "16", "-fflags", "+genpts", "-shortest", "-movflags", "faststart", # "-t", "10", - new_filename1 + new_fullpath1 ]) encode_process0.wait() encode_process1.wait() @@ -73,6 +76,8 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st _slices = int(duration / 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) + new_fullpath0 = os.path.join(VIDEO_OUTPUT_DIR, new_filename0) + new_fullpath1 = os.path.join(VIDEO_OUTPUT_DIR, new_filename1) print("[+]Use Intel QSV Acceleration") encode_process0 = subprocess.Popen([ FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y", @@ -85,7 +90,7 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st "-qmin", "10", "-qmax", "32", "-crf", "16", "-fflags", "+genpts", "-shortest", "-movflags", "faststart", # "-t", "10", - new_filename0 + new_fullpath0 ]) print("[+]Use Nvidia NvEnc Acceleration") encode_process1 = subprocess.Popen([ @@ -99,7 +104,7 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st "-qmin", "10", "-qmax", "32", "-crf", "16", "-fflags", "+genpts", "-shortest", "-movflags", "faststart", # "-t", "10", - new_filename1 + new_fullpath1 ]) encode_process1.wait() encode_process0.wait() @@ -107,8 +112,8 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st else: print("[-]VideoClip to short,", duration) print("[-]Fallback to normal") - encode_video_with_subtitles(orig_filename, subtitles, new_filename) - return [new_filename] + encode_video_with_subtitles(orig_filename, subtitles, new_fullpath) + return [new_fullpath] def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_filename: str):