支持vaapi、支持定义使用哪种弹幕转换工具

This commit is contained in:
2022-10-10 14:35:28 +08:00
parent 7dbf9822c9
commit b74c6f0ef7
5 changed files with 98 additions and 18 deletions

View File

@ -3,8 +3,9 @@ import subprocess
from datetime import datetime, timedelta
from typing import IO
from config import FFMPEG_EXEC, FFMPEG_USE_HEVC, VIDEO_BITRATE, FFMPEG_USE_NVIDIA_GPU, VIDEO_CLIP_EACH_SEC, VIDEO_CLIP_OVERFLOW_SEC, \
FFMPEG_USE_INTEL_GPU, VIDEO_OUTPUT_DIR, VIDEO_CRF, VIDEO_GOP
from config import FFMPEG_EXEC, FFMPEG_USE_HEVC, VIDEO_BITRATE, FFMPEG_USE_NVIDIA_GPU, VIDEO_CLIP_EACH_SEC, \
VIDEO_CLIP_OVERFLOW_SEC, \
FFMPEG_USE_INTEL_GPU, VIDEO_OUTPUT_DIR, VIDEO_CRF, VIDEO_GOP, FFMPEG_USE_VAAPI
from . import LOGGER
@ -29,6 +30,8 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], base_t
if FFMPEG_USE_HEVC:
if FFMPEG_USE_NVIDIA_GPU:
process = get_encode_hevc_process_use_nvenc(orig_filename, subtitles, new_fullpath)
elif FFMPEG_USE_VAAPI:
process = get_encode_hevc_process_use_vaapi(orig_filename, subtitles, new_fullpath)
elif FFMPEG_USE_INTEL_GPU:
process = get_encode_hevc_process_use_intel(orig_filename, subtitles, new_fullpath)
else:
@ -36,6 +39,8 @@ def encode_video_with_subtitles(orig_filename: str, subtitles: list[str], base_t
else:
if FFMPEG_USE_NVIDIA_GPU:
process = get_encode_process_use_nvenc(orig_filename, subtitles, new_fullpath)
elif FFMPEG_USE_VAAPI:
process = get_encode_process_use_vaapi(orig_filename, subtitles, new_fullpath)
elif FFMPEG_USE_INTEL_GPU:
process = get_encode_process_use_intel(orig_filename, subtitles, new_fullpath)
else:
@ -73,6 +78,20 @@ def get_encode_process_use_intel(orig_filename: str, subtitles: list[str], new_f
return encode_process
def get_encode_process_use_vaapi(orig_filename: str, subtitles: list[str], new_filename: str):
print("[+]Use VAAPI Acceleration")
encode_process = subprocess.Popen([
FFMPEG_EXEC, *_common_ffmpeg_setting(),
"-hwaccel", "vaapi", "-hwaccel_output_format", "vaapi", "-i", orig_filename, "-vf",
",".join("subtitles=%s" % i for i in subtitles),
"-c:v", "h264_vaapi",
*_common_ffmpeg_params(),
# "-t", "10",
new_filename
], stdout=subprocess.PIPE)
return encode_process
def get_encode_process_use_cpu(orig_filename: str, subtitles: list[str], new_filename: str):
print("[+]Use CPU Encode")
encode_process = subprocess.Popen([
@ -101,6 +120,20 @@ def get_encode_hevc_process_use_nvenc(orig_filename: str, subtitles: list[str],
return encode_process
def get_encode_hevc_process_use_vaapi(orig_filename: str, subtitles: list[str], new_filename: str):
print("[+]Use VAAPI Acceleration")
encode_process = subprocess.Popen([
FFMPEG_EXEC, *_common_ffmpeg_setting(),
"-hwaccel", "vaapi", "-hwaccel_output_format", "vaapi", "-i", orig_filename, "-vf",
",".join("subtitles=%s" % i for i in subtitles),
"-c:v", "hevc_vaapi",
*_common_ffmpeg_params(),
# "-t", "10",
new_filename
], stdout=subprocess.PIPE)
return encode_process
def get_encode_hevc_process_use_intel(orig_filename: str, subtitles: list[str], new_filename: str):
print("[+]Use Intel QSV Acceleration")
encode_process = subprocess.Popen([