's'
This commit is contained in:
@@ -8,3 +8,6 @@ key = qxvb-r47b-r5ju-6ud3-6k7z
|
|||||||
|
|
||||||
# 可选:视频比特率 kbps,YouTube 推荐 2500,可填 3000-4500 提高画质
|
# 可选:视频比特率 kbps,YouTube 推荐 2500,可填 3000-4500 提高画质
|
||||||
; bitrate = 2500
|
; bitrate = 2500
|
||||||
|
|
||||||
|
# 可选:软编 speed 长期小于 1 时开启——轻量音频链(无 arnndn/长 EQ),减轻 CPU。填 1 或 是
|
||||||
|
fast_audio = 1
|
||||||
@@ -84,8 +84,10 @@ def start_douyin_youtube_ffplay(
|
|||||||
rtmps_base = "rtmps://a.rtmp.youtube.com/live2/"
|
rtmps_base = "rtmps://a.rtmp.youtube.com/live2/"
|
||||||
rtmp_base = "rtmp://a.rtmp.youtube.com/live2/"
|
rtmp_base = "rtmp://a.rtmp.youtube.com/live2/"
|
||||||
use_rtmps = True
|
use_rtmps = True
|
||||||
b_v, maxrate, bufsize = "2500k", "3000k", "5000k"
|
# 720p 竖屏 YouTube 建议 4–6 Mbps,偏低易触发「数据不足/卡顿」提示
|
||||||
|
b_v, maxrate, bufsize = "4000k", "4500k", "8000k"
|
||||||
stream_key = None
|
stream_key = None
|
||||||
|
fast_audio = False # config: fast_audio=1 可跳过 arnndn+长 EQ,显著减轻 CPU
|
||||||
|
|
||||||
if os.path.exists(config_file):
|
if os.path.exists(config_file):
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
@@ -95,6 +97,8 @@ def start_douyin_youtube_ffplay(
|
|||||||
v = (v or "").strip()
|
v = (v or "").strip()
|
||||||
if k == "rtmps" and v.lower() in ("0", "false", "否"):
|
if k == "rtmps" and v.lower() in ("0", "false", "否"):
|
||||||
use_rtmps = False
|
use_rtmps = False
|
||||||
|
elif k == "fast_audio" and v.lower() in ("1", "true", "yes", "是", "开", "on"):
|
||||||
|
fast_audio = True
|
||||||
elif k == "bitrate" and v:
|
elif k == "bitrate" and v:
|
||||||
try:
|
try:
|
||||||
n = int(v)
|
n = int(v)
|
||||||
@@ -155,7 +159,8 @@ def start_douyin_youtube_ffplay(
|
|||||||
|
|
||||||
# ====================== NVENC 检测(符合 YouTube 推荐比特率)======================
|
# ====================== NVENC 检测(符合 YouTube 推荐比特率)======================
|
||||||
codec_v = "libx264"
|
codec_v = "libx264"
|
||||||
video_args = ["-preset", "fast", "-profile:v", "high", "-level", "4.0",
|
# ultrafast+zerolatency:在软编下尽量让 speed≥1.0;画质略降、直播可接受
|
||||||
|
video_args = ["-preset", "ultrafast", "-tune", "zerolatency", "-profile:v", "high", "-level", "4.0",
|
||||||
"-b:v", b_v, "-maxrate", maxrate, "-bufsize", bufsize]
|
"-b:v", b_v, "-maxrate", maxrate, "-bufsize", bufsize]
|
||||||
try:
|
try:
|
||||||
if platform.system().lower() in ["windows", "linux"]:
|
if platform.system().lower() in ["windows", "linux"]:
|
||||||
@@ -172,8 +177,13 @@ def start_douyin_youtube_ffplay(
|
|||||||
print(f"[WARN] NVENC 检测失败,回退软件编码: {e}")
|
print(f"[WARN] NVENC 检测失败,回退软件编码: {e}")
|
||||||
|
|
||||||
# ====================== 开源音频处理:背景音乐弱化 + 防版权 ======================
|
# ====================== 开源音频处理:背景音乐弱化 + 防版权 ======================
|
||||||
# 优先 RNNoise(arnndn),无模型则用 afftdn;aphaser 相位扰动可干扰 Content ID 指纹
|
|
||||||
_script_dir = os.path.dirname(os.path.abspath(__file__))
|
_script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
_ffmpeg_cwd = None
|
||||||
|
if fast_audio:
|
||||||
|
print("[INFO] fast_audio=开:轻量音频链(无 arnndn/长 EQ),减轻 CPU 以利 speed≥1.0")
|
||||||
|
_af_chain = "afftdn=nf=-26:tn=1,aresample=async=1:first_pts=0"
|
||||||
|
else:
|
||||||
|
# 优先 RNNoise(arnndn),无模型则用 afftdn;aphaser 相位扰动可干扰 Content ID 指纹
|
||||||
_arnndn_paths = [
|
_arnndn_paths = [
|
||||||
os.path.join(_script_dir, "arnndn-models", "cb.rnnn"),
|
os.path.join(_script_dir, "arnndn-models", "cb.rnnn"),
|
||||||
os.path.join(os.path.dirname(_script_dir), "arnndn-models", "cb.rnnn"),
|
os.path.join(os.path.dirname(_script_dir), "arnndn-models", "cb.rnnn"),
|
||||||
@@ -184,10 +194,8 @@ def start_douyin_youtube_ffplay(
|
|||||||
if os.path.isfile(_p):
|
if os.path.isfile(_p):
|
||||||
_arnndn_model = os.path.normpath(_p)
|
_arnndn_model = os.path.normpath(_p)
|
||||||
break
|
break
|
||||||
_ffmpeg_cwd = None
|
|
||||||
if _arnndn_model:
|
if _arnndn_model:
|
||||||
print(f"[INFO] 使用 RNNoise 降噪模型: {_arnndn_model}")
|
print(f"[INFO] 使用 RNNoise 降噪模型: {_arnndn_model}")
|
||||||
# 跨平台:用相对路径避免 Windows 下 C: 冒号破坏 FFmpeg 滤镜解析;FFmpeg 以模型所在父目录为 cwd
|
|
||||||
_arnndn_base = os.path.dirname(os.path.dirname(os.path.abspath(_arnndn_model)))
|
_arnndn_base = os.path.dirname(os.path.dirname(os.path.abspath(_arnndn_model)))
|
||||||
_af_denoise = "arnndn=m=arnndn-models/cb.rnnn:mix=0.82,"
|
_af_denoise = "arnndn=m=arnndn-models/cb.rnnn:mix=0.82,"
|
||||||
_ffmpeg_cwd = _arnndn_base
|
_ffmpeg_cwd = _arnndn_base
|
||||||
@@ -198,16 +206,16 @@ def start_douyin_youtube_ffplay(
|
|||||||
# 强化版:收紧带通 + 频率偏移 + 音高微调 + 多段EQ + 相位扰动(纯 FFmpeg 理论上限 ~70%)
|
# 强化版:收紧带通 + 频率偏移 + 音高微调 + 多段EQ + 相位扰动(纯 FFmpeg 理论上限 ~70%)
|
||||||
_af_chain = (
|
_af_chain = (
|
||||||
_af_denoise
|
_af_denoise
|
||||||
+ "highpass=f=200,lowpass=f=3800," # 收紧人声区 200-3800Hz,削弱更多音乐
|
+ "highpass=f=200,lowpass=f=3800,"
|
||||||
+ "equalizer=f=150:width_type=o:width=2.5:g=-14," # 强衰减低频
|
+ "equalizer=f=150:width_type=o:width=2.5:g=-14,"
|
||||||
+ "equalizer=f=350:width_type=o:width=2:g=-10,"
|
+ "equalizer=f=350:width_type=o:width=2:g=-10,"
|
||||||
+ "equalizer=f=600:width_type=o:width=1.8:g=-8,"
|
+ "equalizer=f=600:width_type=o:width=1.8:g=-8,"
|
||||||
+ "equalizer=f=1000:width_type=o:width=1.5:g=-6,"
|
+ "equalizer=f=1000:width_type=o:width=1.5:g=-6,"
|
||||||
+ "equalizer=f=2500:width_type=o:width=1.2:g=-4," # 多段 EQ 破坏音乐结构
|
+ "equalizer=f=2500:width_type=o:width=1.2:g=-4,"
|
||||||
+ "acompressor=threshold=-26dB:ratio=5:attack=8:release=80:makeup=5,"
|
+ "acompressor=threshold=-26dB:ratio=5:attack=8:release=80:makeup=5,"
|
||||||
+ "afreqshift=shift=22," # 频率整体偏移,破坏指纹
|
+ "afreqshift=shift=22,"
|
||||||
+ "asetrate=48000*1.035,aresample=48000," # 音高微升 3.5%
|
+ "asetrate=48000*1.035,aresample=48000,"
|
||||||
+ "aphaser=type=t:decay=0.4:delay=3:speed=0.7," # 加强相位扰动
|
+ "aphaser=type=t:decay=0.4:delay=3:speed=0.7,"
|
||||||
+ "volume=1.12,"
|
+ "volume=1.12,"
|
||||||
+ "aresample=async=1:first_pts=0"
|
+ "aresample=async=1:first_pts=0"
|
||||||
)
|
)
|
||||||
@@ -217,20 +225,23 @@ def start_douyin_youtube_ffplay(
|
|||||||
"-bf", "0", "-sc_threshold", "0"]
|
"-bf", "0", "-sc_threshold", "0"]
|
||||||
if codec_v == "libx264":
|
if codec_v == "libx264":
|
||||||
_video_mid += ["-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0"]
|
_video_mid += ["-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0"]
|
||||||
|
# -re:按源时间戳节奏拉流,避免突发过快;不用 realtime/arealtime(输入抖动时易让 YouTube 判为数据不足)
|
||||||
ffmpeg_command = [
|
ffmpeg_command = [
|
||||||
"ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-re",
|
"ffmpeg", "-y", "-loglevel", "info", "-nostdin",
|
||||||
"-stats", "-stats_period", "1",
|
"-stats", "-stats_period", "1",
|
||||||
"-rw_timeout", "50000000",
|
"-rw_timeout", "50000000",
|
||||||
"-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1",
|
"-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1",
|
||||||
"-reconnect_delay_max", str(RECONNECT_DELAY_MAX),
|
"-reconnect_delay_max", str(RECONNECT_DELAY_MAX),
|
||||||
"-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets",
|
"-fflags", "+genpts+discardcorrupt",
|
||||||
"-flags", "low_delay",
|
|
||||||
"-err_detect", "ignore_err",
|
"-err_detect", "ignore_err",
|
||||||
"-max_delay", "80000",
|
"-max_delay", "500000",
|
||||||
"-thread_queue_size", "2048",
|
"-thread_queue_size", "2048",
|
||||||
|
"-filter_threads", "4",
|
||||||
"-headers", douyin_headers,
|
"-headers", douyin_headers,
|
||||||
|
"-re",
|
||||||
"-i", real_url,
|
"-i", real_url,
|
||||||
"-vf", "fps=30,scale=720:1280:force_original_aspect_ratio=decrease:flags=lanczos,pad=720:1280:(ow-iw)/2:(oh-ih)/2:black",
|
# bilinear 比 lanczos 轻很多,利于 speed 稳定在 ≥1.0x
|
||||||
|
"-vf", "fps=30,scale=720:1280:force_original_aspect_ratio=decrease:flags=bilinear,pad=720:1280:(ow-iw)/2:(oh-ih)/2:black",
|
||||||
"-c:v", codec_v,
|
"-c:v", codec_v,
|
||||||
*video_args,
|
*video_args,
|
||||||
*_video_mid,
|
*_video_mid,
|
||||||
|
|||||||
Reference in New Issue
Block a user