恢复使用CRF,nvenc压制时,使用slowest预设

This commit is contained in:
Jerry Yan 2023-02-09 02:26:31 +08:00
parent bde4531b3b
commit 0e8cbba577
3 changed files with 13 additions and 13 deletions

View File

@ -28,8 +28,8 @@ FFMPEG_USE_NVIDIA_GPU = False
FFMPEG_USE_INTEL_GPU = False FFMPEG_USE_INTEL_GPU = False
# vaapi # vaapi
FFMPEG_USE_VAAPI = False FFMPEG_USE_VAAPI = False
# bitrate # crf
VIDEO_BITRATE = "2.5M" VIDEO_CRF = 28
# gop # gop
VIDEO_GOP = 60 VIDEO_GOP = 60
# [video] # [video]
@ -94,14 +94,14 @@ def load_config():
VIDEO_CLIP_OVERFLOW_SEC = section.getfloat('overflow_sec', VIDEO_CLIP_OVERFLOW_SEC) VIDEO_CLIP_OVERFLOW_SEC = section.getfloat('overflow_sec', VIDEO_CLIP_OVERFLOW_SEC)
if config.has_section("ffmpeg"): if config.has_section("ffmpeg"):
section = config['ffmpeg'] section = config['ffmpeg']
global FFMPEG_EXEC, FFMPEG_USE_HEVC, FFMPEG_USE_NVIDIA_GPU, FFMPEG_USE_INTEL_GPU, VIDEO_BITRATE, \ global FFMPEG_EXEC, FFMPEG_USE_HEVC, FFMPEG_USE_NVIDIA_GPU, FFMPEG_USE_INTEL_GPU, VIDEO_CRF, \
VIDEO_GOP, FFMPEG_USE_VAAPI VIDEO_GOP, FFMPEG_USE_VAAPI
FFMPEG_EXEC = section.get('exec', FFMPEG_EXEC) FFMPEG_EXEC = section.get('exec', FFMPEG_EXEC)
FFMPEG_USE_HEVC = section.getboolean('hevc', FFMPEG_USE_HEVC) FFMPEG_USE_HEVC = section.getboolean('hevc', FFMPEG_USE_HEVC)
FFMPEG_USE_NVIDIA_GPU = section.getboolean('nvidia_gpu', FFMPEG_USE_NVIDIA_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) FFMPEG_USE_INTEL_GPU = section.getboolean('intel_gpu', FFMPEG_USE_INTEL_GPU)
FFMPEG_USE_VAAPI = section.getboolean('vaapi', FFMPEG_USE_VAAPI) FFMPEG_USE_VAAPI = section.getboolean('vaapi', FFMPEG_USE_VAAPI)
VIDEO_BITRATE = section.get('bitrate', VIDEO_BITRATE) VIDEO_CRF = section.getfloat('crf', VIDEO_CRF)
VIDEO_GOP = section.getfloat('gop', VIDEO_GOP) VIDEO_GOP = section.getfloat('gop', VIDEO_GOP)
if config.has_section("recorder"): if config.has_section("recorder"):
global BILILIVE_RECORDER_DIRECTORY, XIGUALIVE_RECORDER_DIRECTORY, VIDEO_OUTPUT_DIR global BILILIVE_RECORDER_DIRECTORY, XIGUALIVE_RECORDER_DIRECTORY, VIDEO_OUTPUT_DIR
@ -140,7 +140,7 @@ def get_config():
'nvidia_gpu': FFMPEG_USE_NVIDIA_GPU, 'nvidia_gpu': FFMPEG_USE_NVIDIA_GPU,
'intel_gpu': FFMPEG_USE_INTEL_GPU, 'intel_gpu': FFMPEG_USE_INTEL_GPU,
'vaapi': FFMPEG_USE_VAAPI, 'vaapi': FFMPEG_USE_VAAPI,
'bitrate': VIDEO_BITRATE, 'crf': VIDEO_CRF,
'gop': VIDEO_GOP, 'gop': VIDEO_GOP,
}, },
'recorder': { 'recorder': {

View File

@ -101,8 +101,8 @@
<td :class="{warning: !config.ffmpeg.intel_gpu, success: config.ffmpeg.intel_gpu}"></td> <td :class="{warning: !config.ffmpeg.intel_gpu, success: config.ffmpeg.intel_gpu}"></td>
</tr> </tr>
<tr> <tr>
<td>视频比特率</td> <td>视频CRF</td>
<td>{{ config.ffmpeg.bitrate }}</td> <td>{{ config.ffmpeg.crf }}</td>
</tr> </tr>
<tr> <tr>
<td>GOP</td> <td>GOP</td>
@ -323,7 +323,7 @@
nvidia_gpu: false, nvidia_gpu: false,
intel_gpu: false, intel_gpu: false,
vaapi: false, vaapi: false,
bitrate: "", crf: "",
gop: "", gop: "",
}, },
recorder: { recorder: {

View File

@ -3,7 +3,7 @@ import subprocess
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import IO from typing import IO
from config import FFMPEG_EXEC, FFMPEG_USE_HEVC, VIDEO_BITRATE, FFMPEG_USE_NVIDIA_GPU, VIDEO_CLIP_EACH_SEC, \ from config import FFMPEG_EXEC, FFMPEG_USE_HEVC, VIDEO_CRF, FFMPEG_USE_NVIDIA_GPU, VIDEO_CLIP_EACH_SEC, \
VIDEO_CLIP_OVERFLOW_SEC, \ VIDEO_CLIP_OVERFLOW_SEC, \
FFMPEG_USE_INTEL_GPU, VIDEO_OUTPUT_DIR, VIDEO_GOP, FFMPEG_USE_VAAPI FFMPEG_USE_INTEL_GPU, VIDEO_OUTPUT_DIR, VIDEO_GOP, FFMPEG_USE_VAAPI
from . import LOGGER from . import LOGGER
@ -56,7 +56,7 @@ def get_encode_process_use_nvenc(orig_filename: str, subtitles: list[str], new_f
FFMPEG_EXEC, *_common_ffmpeg_setting(), FFMPEG_EXEC, *_common_ffmpeg_setting(),
"-i", orig_filename, "-vf", "-i", orig_filename, "-vf",
",".join("subtitles=%s" % i for i in subtitles) + ",hwupload_cuda", ",".join("subtitles=%s" % i for i in subtitles) + ",hwupload_cuda",
"-c:v", "h264_nvenc", "-c:v", "h264_nvenc", "-preset:v", "p7",
*_common_ffmpeg_params(), *_common_ffmpeg_params(),
# "-t", "10", # "-t", "10",
new_filename new_filename
@ -113,7 +113,7 @@ def get_encode_hevc_process_use_nvenc(orig_filename: str, subtitles: list[str],
FFMPEG_EXEC, *_common_ffmpeg_setting(), FFMPEG_EXEC, *_common_ffmpeg_setting(),
"-i", orig_filename, "-vf", "-i", orig_filename, "-vf",
"".join("subtitles=%s," % i for i in subtitles) + "hwupload_cuda", "".join("subtitles=%s," % i for i in subtitles) + "hwupload_cuda",
"-c:v", "hevc_nvenc", "-c:v", "hevc_nvenc", "-preset:v", "p7",
*_common_ffmpeg_params(), *_common_ffmpeg_params(),
# "-t", "10", # "-t", "10",
new_filename new_filename
@ -238,7 +238,7 @@ def _common_ffmpeg_setting():
def _common_ffmpeg_params(): def _common_ffmpeg_params():
return ( return (
"-vsync", "1", "-async", "1", "-avoid_negative_ts", "1", "-vsync", "1", "-async", "1", "-avoid_negative_ts", "1",
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-c:a", "aac", "-f", "mp4", "-c:a", "aac",
"-qmin", "18", "-qmax", "38", "-g:v", str(VIDEO_GOP), "-crf", str(VIDEO_CRF), "-g:v", str(VIDEO_GOP),
"-fflags", "+genpts", "-shortest" "-fflags", "+genpts", "-shortest"
) )