You've already forked my-video-workflow
添加output_dir
This commit is contained in:
@ -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):
|
||||
|
Reference in New Issue
Block a user