CRF客制化

This commit is contained in:
2022-06-01 09:22:22 +08:00
parent 5fe978cfab
commit 9761d13b6f
3 changed files with 12 additions and 3 deletions

View File

@ -20,6 +20,8 @@ FFMPEG_USE_NVIDIA_GPU = False
FFMPEG_USE_INTEL_GPU = False
# bitrate
VIDEO_BITRATE = "2.5M"
# crf
VIDEO_CRF = 28
# [video]
# title
VIDEO_TITLE = "【永恒de草薙直播录播】直播于 {}"
@ -61,11 +63,12 @@ def load_config():
VIDEO_CLIP_OVERFLOW_SEC = section.getfloat('overflow_sec', VIDEO_CLIP_OVERFLOW_SEC)
if config.has_section("ffmpeg"):
section = config['ffmpeg']
global FFMPEG_EXEC, FFMPEG_USE_NVIDIA_GPU, FFMPEG_USE_INTEL_GPU, VIDEO_BITRATE
global FFMPEG_EXEC, FFMPEG_USE_NVIDIA_GPU, FFMPEG_USE_INTEL_GPU, VIDEO_BITRATE, VIDEO_CRF
FFMPEG_EXEC = section.get('exec', FFMPEG_EXEC)
FFMPEG_USE_NVIDIA_GPU = section.getboolean('nvidia_gpu', FFMPEG_USE_NVIDIA_GPU)
FFMPEG_USE_INTEL_GPU = section.getboolean('intel_gpu', FFMPEG_USE_INTEL_GPU)
VIDEO_BITRATE = section.get('bitrate', VIDEO_BITRATE)
VIDEO_CRF = section.getfloat('crf', VIDEO_CRF)
if config.has_section("recorder"):
global BILILIVE_RECORDER_DIRECTORY, XIGUALIVE_RECORDER_DIRECTORY, VIDEO_OUTPUT_DIR
section = config['recorder']
@ -95,6 +98,7 @@ def get_config():
'nvidia_gpu': FFMPEG_USE_NVIDIA_GPU,
'intel_gpu': FFMPEG_USE_INTEL_GPU,
'bitrate': VIDEO_BITRATE,
'crf': VIDEO_CRF,
},
'recorder': {
'bili_dir': BILILIVE_RECORDER_DIRECTORY,

View File

@ -75,6 +75,10 @@
<td>视频比特率</td>
<td>{{ config.ffmpeg.bitrate }}</td>
</tr>
<tr>
<td>视频CRF</td>
<td>{{ config.ffmpeg.crf }}</td>
</tr>
</tbody>
</table>
<table class="current-config">
@ -220,6 +224,7 @@
nvidia_gpu: false,
intel_gpu: false,
bitrate: "",
crf: "",
},
recorder: {
bili_dir: "",

View File

@ -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, VIDEO_OUTPUT_DIR
FFMPEG_USE_INTEL_GPU, VIDEO_OUTPUT_DIR, VIDEO_CRF
def base_ts_to_filename(start_ts: float, is_mp4=False) -> str:
@ -164,6 +164,6 @@ def _common_ffmpeg_params():
return (
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-c:a", "copy",
"-preset:v", "fast", "-profile:v", "main", "-avoid_negative_ts", "1",
"-qmin", "12", "-qmax", "34", "-crf", "26", "-g:v", "60",
"-qmin", "18", "-qmax", "38", "-crf", str(VIDEO_CRF), "-g:v", "240",
"-fflags", "+genpts", "-shortest", "-movflags", "faststart"
)