This commit is contained in:
eric
2026-03-01 09:12:41 -06:00
parent 89037d6786
commit 03b8d52326

View File

@@ -253,63 +253,63 @@ def start_douyin_youtube_ffplay(
ffmpeg_command = [
"ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-re",
"-stats", "-stats_period", "1",
"-rw_timeout", "30000000",
"-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1",
"-reconnect_delay_max", "5",
"-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets",
"-flags", "low_delay",
"-err_detect", "ignore_err",
"-max_delay", "50000",
"-thread_queue_size", "4096",
# ffmpeg_command = [
# "ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-re",
# "-stats", "-stats_period", "1",
# "-rw_timeout", "30000000",
# "-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1",
# "-reconnect_delay_max", "5",
# "-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets",
# "-flags", "low_delay",
# "-err_detect", "ignore_err",
# "-max_delay", "50000",
# "-thread_queue_size", "4096",
"-headers", douyin_headers,
"-i", real_url,
# "-headers", douyin_headers,
# "-i", real_url,
# 视频处理1080p 纵屏优化,黑边填充
"-vf",
"fps=25,scale=1080:1920:force_original_aspect_ratio=decrease:flags=bicubic,"
"pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black",
# # 视频处理1080p 纵屏优化,黑边填充
# "-vf",
# "fps=25,scale=1080:1920:force_original_aspect_ratio=decrease:flags=bicubic,"
# "pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black",
"-c:v", "libx264",
"-preset", "medium", # Ubuntu server CPU通常能承受质量比faster好很多若掉帧可回退到faster或veryfast
"-tune", "zerolatency",
"-profile:v", "high",
"-level", "4.2", # 支持1080p@25fps
# "-b:v", "8500k", "-maxrate", "10000k", "-bufsize", "20000k",
"-b:v", "4500k", "-maxrate", "5500k", "-bufsize", "9000k",
"-vsync", "cfr",
"-g", "50", "-keyint_min", "50",
"-r", "25",
"-bf", "0",
"-sc_threshold", "0",
"-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0:rc-lookahead=0",
"-pix_fmt", "yuv420p",
# "-c:v", "libx264",
# "-preset", "medium", # Ubuntu server CPU通常能承受质量比faster好很多若掉帧可回退到faster或veryfast
# "-tune", "zerolatency",
# "-profile:v", "high",
# "-level", "4.2", # 支持1080p@25fps
# # "-b:v", "8500k", "-maxrate", "10000k", "-bufsize", "20000k",
# "-b:v", "4500k", "-maxrate", "5500k", "-bufsize", "9000k",
# "-vsync", "cfr",
# "-g", "50", "-keyint_min", "50",
# "-r", "25",
# "-bf", "0",
# "-sc_threshold", "0",
# "-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0:rc-lookahead=0",
# "-pix_fmt", "yuv420p",
# 音频处理 - 防Content ID 强化版(多维度修改音频指纹)
"-c:a", "aac", "-b:a", "192k", "-ar", "48000", "-ac", "2",
"-af",
"arnndn=m=./arnndn-models/cb.rnnn:mix=0.85,"
"afftdn=nf=-24:tn=1," # 中等降噪,保留人声清晰度
"highpass=f=100,lowpass=f=5200," # 切除低频鼓/贝斯 & 高频镲/噪音,聚焦人声区
"equalizer=f=180:width_type=o:width=2.2:g=-12," # 强衰减低频(背景音乐基础层)
"equalizer=f=350:width_type=o:width=1.8:g=-9," # 衰减低中频(常见旋律区)
"equalizer=f=750:width_type=o:width=1.6:g=-7," # 中频衰减,破坏音乐结构
"equalizer=f=2800:width_type=o:width=1.2:g=-5," # 高中频轻衰减,保持人声自然
"acompressor=threshold=-26dB:ratio=5.5:attack=7:release=90:makeup=6," # 强压缩,改变动态指纹
"asetrate=48000*1.05,atempo=1.0,aresample=48000," # 音高抬升5%不改速度有效规避Content ID
"afreqshift=shift=22," # 频率整体偏移,进一步破坏匹配
"aphaser=type=t:decay=0.35:delay=3.0:speed=0.5," # 正确参数轻微相位扰动triangular类型防检测
# "anlmdn=s=0.00012:p=0.0008:r=0.002," # 轻量非线性噪门,清理残余背景音乐
"volume=1.08," # 补偿音量衰减
"aresample=async=1:first_pts=0:min_hard_comp=0.100000:first_pts=0", # 强制音视频同步
# # 音频处理 - 防Content ID 强化版(多维度修改音频指纹)
# "-c:a", "aac", "-b:a", "192k", "-ar", "48000", "-ac", "2",
# "-af",
# "arnndn=m=./arnndn-models/cb.rnnn:mix=0.85,"
# "afftdn=nf=-24:tn=1," # 中等降噪,保留人声清晰度
# "highpass=f=100,lowpass=f=5200," # 切除低频鼓/贝斯 & 高频镲/噪音,聚焦人声区
# "equalizer=f=180:width_type=o:width=2.2:g=-12," # 强衰减低频(背景音乐基础层)
# "equalizer=f=350:width_type=o:width=1.8:g=-9," # 衰减低中频(常见旋律区)
# "equalizer=f=750:width_type=o:width=1.6:g=-7," # 中频衰减,破坏音乐结构
# "equalizer=f=2800:width_type=o:width=1.2:g=-5," # 高中频轻衰减,保持人声自然
# "acompressor=threshold=-26dB:ratio=5.5:attack=7:release=90:makeup=6," # 强压缩,改变动态指纹
# "asetrate=48000*1.05,atempo=1.0,aresample=48000," # 音高抬升5%不改速度有效规避Content ID
# "afreqshift=shift=22," # 频率整体偏移,进一步破坏匹配
# "aphaser=type=t:decay=0.35:delay=3.0:speed=0.5," # 正确参数轻微相位扰动triangular类型防检测
# # "anlmdn=s=0.00012:p=0.0008:r=0.002," # 轻量非线性噪门,清理残余背景音乐
# "volume=1.08," # 补偿音量衰减
# "aresample=async=1:first_pts=0:min_hard_comp=0.100000:first_pts=0", # 强制音视频同步
# 推流优化FLV适合YouTube RTMP/RTMPS
"-flvflags", "no_duration_filesize",
"-f", "flv", youtube_rtmp
]
# # 推流优化FLV适合YouTube RTMP/RTMPS
# "-flvflags", "no_duration_filesize",
# "-f", "flv", youtube_rtmp
# ]
@@ -359,6 +359,148 @@ def start_douyin_youtube_ffplay(
# ]
# grok版本
# ffmpeg_command = [
# "ffmpeg", "-y", "-loglevel", "info", "-nostdin",
# "-stats", "-stats_period", "1",
# # 网络 & 重连(防抖音源不稳)
# "-rw_timeout", "60000000", # 更长超时,防网络抖动
# "-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1",
# "-reconnect_delay_max", "10", # 渐进重试
# "-http_persistent", "1", # 持久 HTTP 连接(对 HLS/HTTP-FLV 好)
# # ─────────────── 防超速 & 实时核心 ───────────────
# "-re", # 实时读取输入(必须在 -i 前)
# "-use_wallclock_as_timestamps", "1", # 系统时钟时间戳,防源乱戳
# "-thread_queue_size", "64", # 极致缩小预读(从 4096 → 64防预取太多
# "-probesize", "32K", "-analyzeduration", "500000", # 小探测,减少初始缓冲
# "-fflags", "+genpts+discardcorrupt", # 只留必要,删 nobuffer/flush_packets
# "-flags", "low_delay",
# "-max_delay", "300000", # 0.3秒,平衡延迟与稳定
# # ───────────────────────────────────────────────
# "-headers", douyin_headers,
# "-i", real_url,
# # 视频处理:纵屏 1080x1920黑边填充YouTube 支持 portrait但 ingestion 仍是 1080x1920
# "-vf", "fps=25,scale=1080:1920:force_original_aspect_ratio=decrease:flags=bicubic,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black",
# "-c:v", "libx264",
# "-preset", "medium", # 质量 & 速度平衡;若 CPU 强可 slow进一步吃速
# "-tune", "zerolatency", # 低延迟调优
# "-profile:v", "high",
# "-level", "4.2", # 支持 1080p 高帧/高码率
# # 码率:贴近 YouTube 1080p@30fps 推荐(你的 25fps 接近CBR 风格
# "-b:v", "4500k", # 目标码率(保守,防掉线)
# "-maxrate", "5500k", # 峰值 ≤ 推荐上限
# "-bufsize", "11000k", # 2x maxrateCBR 更稳YouTube 偏好)
# "-vsync", "cfr", # 强制恒帧
# "-r", "25",
# "-g", "50", "-keyint_min", "25", # 关键帧 2 秒50/25=2s符合 YouTube 推荐 ≤4s
# "-bf", "0", # 无 B 帧zerolatency 常见,减少延迟)
# "-sc_threshold", "0", # 禁用场景切检测
# "-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0:rc-lookahead=0",
# "-pix_fmt", "yuv420p", # YouTube 标准
# # 音频你的防ID链 + YouTube 推荐 AAC 128-192k
# "-c:a", "aac",
# "-b:a", "192k", # 高质量立体声YouTube 支持)
# "-ar", "48000",
# "-ac", "2",
# "-af", "arnndn=m=./arnndn-models/cb.rnnn:mix=0.85,"
# "afftdn=nf=-24:tn=1,"
# "highpass=f=100,lowpass=f=5200,"
# "equalizer=f=180:width_type=o:width=2.2:g=-12,"
# "equalizer=f=350:width_type=o:width=1.8:g=-9,"
# "equalizer=f=750:width_type=o:width=1.6:g=-7,"
# "equalizer=f=2800:width_type=o:width=1.2:g=-5,"
# "acompressor=threshold=-26dB:ratio=5.5:attack=7:release=90:makeup=6,"
# "asetrate=48000*1.05,atempo=1.0,aresample=48000," # 5% 音高移位
# "afreqshift=shift=22,"
# "aphaser=type=t:decay=0.35:delay=3.0:speed=0.5,"
# "volume=1.08,"
# "aresample=async=1:first_pts=0:min_hard_comp=0.100000:first_pts=0", # 强制 AV 同步
# # 输出 FLV 到 YouTubeRTMPS 推荐,但 ffmpeg 默认支持)
# "-flvflags", "no_duration_filesize",
# "-f", "flv",
# youtube_rtmp # 确保是 rtmps://a.rtmp.youtube.com/live2/xxx 如果可用
# ]
# gpt版本
ffmpeg_command = [
"ffmpeg", "-y",
"-loglevel", "info",
"-nostdin",
"-stats", "-stats_period", "1",
# ───────────── 网络稳定 ─────────────
"-rw_timeout", "60000000",
"-reconnect", "1",
"-reconnect_streamed", "1",
"-reconnect_at_eof", "1",
"-reconnect_delay_max", "10",
"-http_persistent", "1",
# ───────────── 实时核心(关键) ─────────────
"-re",
"-use_wallclock_as_timestamps", "1",
"-fflags", "+genpts+discardcorrupt",
"-avoid_negative_ts", "make_zero",
"-thread_queue_size", "512",
"-probesize", "1M",
"-analyzeduration", "1M",
"-fps_mode", "cfr",
"-headers", douyin_headers,
"-i", real_url,
# ───────────── 视频处理 ─────────────
"-vf",
"fps=25,"
"scale=1080:1920:force_original_aspect_ratio=decrease:flags=bicubic,"
"pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black",
"-c:v", "libx264",
"-preset", "veryfast", # 24h 稳定优先medium 长时间可能吃满CPU
"-tune", "zerolatency",
"-profile:v", "high",
"-level", "4.2",
# YouTube 推荐 1080p 码率区间
"-b:v", "4500k",
"-maxrate", "4500k",
"-bufsize", "9000k",
# 2 秒关键帧
"-g", "50",
"-keyint_min", "50",
"-bf", "0",
"-sc_threshold", "0",
"-pix_fmt", "yuv420p",
# ───────────── 音频(稳定轻量版) ─────────────
"-c:a", "aac",
"-b:a", "160k",
"-ar", "48000",
"-ac", "2",
"-af",
"highpass=f=100,"
"lowpass=f=5200,"
"asetrate=48000*1.03,"
"aresample=48000:async=1:first_pts=0",
# ───────────── 输出 ─────────────
"-flvflags", "no_duration_filesize",
"-f", "flv",
youtube_rtmp
]
proc = None
stderr_q = None
reader_t = None