使用QP作为码率控制策略
This commit is contained in:
parent
c3993965a9
commit
a13f732321
15
config.py
15
config.py
@ -28,10 +28,10 @@ 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
|
|
||||||
VIDEO_BITRATE = "2.5M"
|
|
||||||
# gop
|
# gop
|
||||||
VIDEO_GOP = 60
|
VIDEO_GOP = 30
|
||||||
|
# qp
|
||||||
|
VIDEO_QP = 28
|
||||||
# [video]
|
# [video]
|
||||||
# enabled
|
# enabled
|
||||||
VIDEO_ENABLED = False
|
VIDEO_ENABLED = False
|
||||||
@ -94,15 +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_QP, 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_GOP = section.getint('gop', VIDEO_GOP)
|
||||||
VIDEO_GOP = section.getfloat('gop', VIDEO_GOP)
|
VIDEO_QP = section.getint('qp', VIDEO_QP)
|
||||||
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
|
||||||
section = config['recorder']
|
section = config['recorder']
|
||||||
@ -140,7 +139,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,
|
'qp': VIDEO_QP,
|
||||||
'gop': VIDEO_GOP,
|
'gop': VIDEO_GOP,
|
||||||
},
|
},
|
||||||
'recorder': {
|
'recorder': {
|
||||||
|
@ -3,9 +3,9 @@ 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, 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, VIDEO_QP, FFMPEG_USE_VAAPI
|
||||||
from . import LOGGER
|
from . import LOGGER
|
||||||
|
|
||||||
|
|
||||||
@ -216,7 +216,6 @@ def quick_split_video(file):
|
|||||||
"-ss", str(current_sec),
|
"-ss", str(current_sec),
|
||||||
"-i", file, "-c:v", "copy", "-c:a", "copy", "-f", "mp4",
|
"-i", file, "-c:v", "copy", "-c:a", "copy", "-f", "mp4",
|
||||||
"-t", str(VIDEO_CLIP_EACH_SEC + VIDEO_CLIP_OVERFLOW_SEC),
|
"-t", str(VIDEO_CLIP_EACH_SEC + VIDEO_CLIP_OVERFLOW_SEC),
|
||||||
"-fflags", "+genpts", "-shortest", "-movflags", "faststart",
|
|
||||||
os.path.join(VIDEO_OUTPUT_DIR, "{}.mp4".format(current_dt))
|
os.path.join(VIDEO_OUTPUT_DIR, "{}.mp4".format(current_dt))
|
||||||
], stdout=subprocess.PIPE)
|
], stdout=subprocess.PIPE)
|
||||||
handle_ffmpeg_output(split_process.stdout)
|
handle_ffmpeg_output(split_process.stdout)
|
||||||
@ -237,8 +236,8 @@ def _common_ffmpeg_setting():
|
|||||||
|
|
||||||
def _common_ffmpeg_params():
|
def _common_ffmpeg_params():
|
||||||
return (
|
return (
|
||||||
"-f", "mp4", "-b:v", VIDEO_BITRATE, "-c:a", "aac",
|
"-f", "mp4", "-c:a", "copy",
|
||||||
"-preset:v", "fast", "-profile:v", "main", "-avoid_negative_ts", "1",
|
"-preset:v", "fast", "-profile:v", "main", "-avoid_negative_ts", "1",
|
||||||
"-qmin", "18", "-qmax", "38", "-g:v", str(VIDEO_GOP),
|
"-qp", str(VIDEO_QP), "-g:v", str(VIDEO_GOP),
|
||||||
"-fflags", "+genpts", "-shortest"
|
"-fflags", "+genpts", "-shortest"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user