From 9ad58b89408793109ed8525c0a16ecc281645a2e Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 3 Sep 2022 10:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0GOP=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 7 ++++++- templates/index.html | 5 +++++ workflow/video.py | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index b568690..035b8ea 100644 --- a/config.py +++ b/config.py @@ -26,6 +26,8 @@ FFMPEG_USE_INTEL_GPU = False VIDEO_BITRATE = "2.5M" # crf VIDEO_CRF = 28 +# gop +VIDEO_GOP = 60 # [video] # enabled VIDEO_ENABLED = False @@ -85,13 +87,15 @@ 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_HEVC, FFMPEG_USE_NVIDIA_GPU, FFMPEG_USE_INTEL_GPU, VIDEO_BITRATE, VIDEO_CRF + global FFMPEG_EXEC, FFMPEG_USE_HEVC, FFMPEG_USE_NVIDIA_GPU, FFMPEG_USE_INTEL_GPU, VIDEO_BITRATE, VIDEO_CRF, \ + VIDEO_GOP FFMPEG_EXEC = section.get('exec', FFMPEG_EXEC) FFMPEG_USE_HEVC = section.getboolean('hevc', FFMPEG_USE_HEVC) 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) + VIDEO_GOP = section.getfloat('gop', VIDEO_GOP) if config.has_section("recorder"): global BILILIVE_RECORDER_DIRECTORY, XIGUALIVE_RECORDER_DIRECTORY, VIDEO_OUTPUT_DIR section = config['recorder'] @@ -128,6 +132,7 @@ def get_config(): 'intel_gpu': FFMPEG_USE_INTEL_GPU, 'bitrate': VIDEO_BITRATE, 'crf': VIDEO_CRF, + 'gop': VIDEO_GOP, }, 'recorder': { 'bili_dir': BILILIVE_RECORDER_DIRECTORY, diff --git a/templates/index.html b/templates/index.html index ed915a7..1b92eb7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -100,6 +100,10 @@ 视频CRF {{ config.ffmpeg.crf }} + + GOP + {{ config.ffmpeg.gop }} + @@ -304,6 +308,7 @@ intel_gpu: false, bitrate: "", crf: "", + gop: "", }, recorder: { bili_dir: "", diff --git a/workflow/video.py b/workflow/video.py index 603ef74..ef6cba6 100644 --- a/workflow/video.py +++ b/workflow/video.py @@ -4,7 +4,7 @@ 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 + FFMPEG_USE_INTEL_GPU, VIDEO_OUTPUT_DIR, VIDEO_CRF, VIDEO_GOP from . import LOGGER @@ -204,6 +204,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", "18", "-qmax", "38", "-crf", str(VIDEO_CRF), "-g:v", "900", + "-qmin", "18", "-qmax", "38", "-crf", str(VIDEO_CRF), "-g:v", str(VIDEO_GOP), "-fflags", "+genpts", "-shortest" )