添加output_dir

This commit is contained in:
Jerry Yan 2022-05-17 17:56:27 +08:00
parent 80bac4498e
commit f70d04f1b2
2 changed files with 19 additions and 10 deletions

View File

@ -33,6 +33,8 @@ VIDEO_CLIP_OVERFLOW_SEC = 5
BILILIVE_RECORDER_DIRECTORY = "./" BILILIVE_RECORDER_DIRECTORY = "./"
# xigua_dir # xigua_dir
XIGUALIVE_RECORDER_DIRECTORY = "./" XIGUALIVE_RECORDER_DIRECTORY = "./"
# output_dir
VIDEO_OUTPUT_DIR = "/mnt/"
def load_config(): def load_config():
@ -65,10 +67,11 @@ def load_config():
FFMPEG_USE_INTEL_GPU = section.getboolean('intel_gpu', FFMPEG_USE_INTEL_GPU) FFMPEG_USE_INTEL_GPU = section.getboolean('intel_gpu', FFMPEG_USE_INTEL_GPU)
VIDEO_BITRATE = section.get('bitrate', VIDEO_BITRATE) VIDEO_BITRATE = section.get('bitrate', VIDEO_BITRATE)
if config.has_section("recorder"): 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'] section = config['recorder']
BILILIVE_RECORDER_DIRECTORY = section.get('bili_dir', BILILIVE_RECORDER_DIRECTORY) BILILIVE_RECORDER_DIRECTORY = section.get('bili_dir', BILILIVE_RECORDER_DIRECTORY)
XIGUALIVE_RECORDER_DIRECTORY = section.get('xigua_dir', XIGUALIVE_RECORDER_DIRECTORY) XIGUALIVE_RECORDER_DIRECTORY = section.get('xigua_dir', XIGUALIVE_RECORDER_DIRECTORY)
VIDEO_OUTPUT_DIR = section.get('output_dir', VIDEO_OUTPUT_DIR)
return True return True
@ -96,6 +99,7 @@ def get_config():
'recorder': { 'recorder': {
'bili_dir': BILILIVE_RECORDER_DIRECTORY, 'bili_dir': BILILIVE_RECORDER_DIRECTORY,
'xigua_dir': XIGUALIVE_RECORDER_DIRECTORY, 'xigua_dir': XIGUALIVE_RECORDER_DIRECTORY,
'output_dir': VIDEO_OUTPUT_DIR,
}, },
} }
return config return config

View File

@ -5,7 +5,7 @@ from datetime import datetime, timedelta
from typing import IO from typing import IO
from config import FFMPEG_EXEC, VIDEO_BITRATE, FFMPEG_USE_NVIDIA_GPU, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC, \ 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: 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): 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_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): if not (FFMPEG_USE_NVIDIA_GPU and FFMPEG_USE_INTEL_GPU):
print("[!]Please Enable Both Of Encode Acceleration") print("[!]Please Enable Both Of Encode Acceleration")
print("[!]Fallback to normal") print("[!]Fallback to normal")
encode_video_with_subtitles(orig_filename, subtitles, new_filename) encode_video_with_subtitles(orig_filename, subtitles, new_fullpath)
return [new_filename] return [new_fullpath]
_duration_str = get_video_real_duration(orig_filename) _duration_str = get_video_real_duration(orig_filename)
duration = duration_str_to_float(_duration_str) duration = duration_str_to_float(_duration_str)
if duration > (VIDEO_CLIP_EACH_SEC * 5): 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) _slices = int(duration / VIDEO_CLIP_EACH_SEC)
new_filename0 = base_ts_to_filename(base_ts + (_slices - 1) * 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_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") print("[+]Use Intel QSV Acceleration")
encode_process0 = subprocess.Popen([ encode_process0 = subprocess.Popen([
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y", 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", "-qmin", "10", "-qmax", "32", "-crf", "16",
"-fflags", "+genpts", "-shortest", "-movflags", "faststart", "-fflags", "+genpts", "-shortest", "-movflags", "faststart",
# "-t", "10", # "-t", "10",
new_filename0 new_fullpath0
]) ])
print("[+]Use Nvidia NvEnc Acceleration") print("[+]Use Nvidia NvEnc Acceleration")
encode_process1 = subprocess.Popen([ 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", "-qmin", "10", "-qmax", "32", "-crf", "16",
"-fflags", "+genpts", "-shortest", "-movflags", "faststart", "-fflags", "+genpts", "-shortest", "-movflags", "faststart",
# "-t", "10", # "-t", "10",
new_filename1 new_fullpath1
]) ])
encode_process0.wait() encode_process0.wait()
encode_process1.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) _slices = int(duration / VIDEO_CLIP_EACH_SEC)
new_filename0 = base_ts_to_filename(base_ts + _slices * VIDEO_CLIP_EACH_SEC, True) new_filename0 = base_ts_to_filename(base_ts + _slices * VIDEO_CLIP_EACH_SEC, True)
new_filename1 = base_ts_to_filename(base_ts) 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") print("[+]Use Intel QSV Acceleration")
encode_process0 = subprocess.Popen([ encode_process0 = subprocess.Popen([
FFMPEG_EXEC, "-hide_banner", "-progress", "-", "-loglevel", "error", "-y", 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", "-qmin", "10", "-qmax", "32", "-crf", "16",
"-fflags", "+genpts", "-shortest", "-movflags", "faststart", "-fflags", "+genpts", "-shortest", "-movflags", "faststart",
# "-t", "10", # "-t", "10",
new_filename0 new_fullpath0
]) ])
print("[+]Use Nvidia NvEnc Acceleration") print("[+]Use Nvidia NvEnc Acceleration")
encode_process1 = subprocess.Popen([ 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", "-qmin", "10", "-qmax", "32", "-crf", "16",
"-fflags", "+genpts", "-shortest", "-movflags", "faststart", "-fflags", "+genpts", "-shortest", "-movflags", "faststart",
# "-t", "10", # "-t", "10",
new_filename1 new_fullpath1
]) ])
encode_process1.wait() encode_process1.wait()
encode_process0.wait() encode_process0.wait()
@ -107,8 +112,8 @@ def multi_gpu_encode_video_with_subtitles(orig_filename: str, subtitles: list[st
else: else:
print("[-]VideoClip to short,", duration) print("[-]VideoClip to short,", duration)
print("[-]Fallback to normal") print("[-]Fallback to normal")
encode_video_with_subtitles(orig_filename, subtitles, new_filename) encode_video_with_subtitles(orig_filename, subtitles, new_fullpath)
return [new_filename] return [new_fullpath]
def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_filename: str): def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], new_filename: str):