From c6889d4917876856057e686dfa97633c223fafec Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 1 Mar 2026 09:26:14 -0600 Subject: [PATCH] 's' --- douyin_youtube_ffplay.py | 68 ++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/douyin_youtube_ffplay.py b/douyin_youtube_ffplay.py index 9dcaf25..787605e 100644 --- a/douyin_youtube_ffplay.py +++ b/douyin_youtube_ffplay.py @@ -365,52 +365,53 @@ def start_douyin_youtube_ffplay( "ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-stats", "-stats_period", "1", - # 网络 & 重连(防抖音源不稳) - "-rw_timeout", "60000000", # 更长超时,防网络抖动 + # 网络 & 重连(加强防抖音源不稳/延迟) + "-rw_timeout", "60000000", "-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1", - "-reconnect_delay_max", "10", # 渐进重试 - "-http_persistent", "1", # 持久 HTTP 连接(对 HLS/HTTP-FLV 好) + "-reconnect_delay_max", "10", + "-http_persistent", "1", + "-http_seekable", "0", # 新加:防 HLS/FLV 源 seek 问题 - # ─────────────── 防超速 & 实时核心 ─────────────── - "-re", # 实时读取输入(必须在 -i 前) - "-use_wallclock_as_timestamps", "1", # 系统时钟时间戳,防源乱戳 - "-thread_queue_size", "64", # 极致缩小预读(从 4096 → 64,防预取太多) - "-probesize", "32K", "-analyzeduration", "500000", # 小探测,减少初始缓冲 - "-fflags", "+genpts+discardcorrupt", # 只留必要,删 nobuffer/flush_packets + # 防超速 & 实时核心(已优化) + "-re", + "-use_wallclock_as_timestamps", "1", + "-thread_queue_size", "64", + "-probesize", "32K", "-analyzeduration", "500000", + "-fflags", "+genpts+discardcorrupt", "-flags", "low_delay", - "-max_delay", "300000", # 0.3秒,平衡延迟与稳定 - # ─────────────────────────────────────────────── + "-max_delay", "300000", "-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", # 低延迟调优 + "-preset", "medium", + "-tune", "zerolatency", "-profile:v", "high", - "-level", "4.2", # 支持 1080p 高帧/高码率 + "-level", "4.2", - # 码率:贴近 YouTube 1080p@30fps 推荐(你的 25fps 接近),CBR 风格 - "-b:v", "4500k", # 目标码率(保守,防掉线) - "-maxrate", "5500k", # 峰值 ≤ 推荐上限 - "-bufsize", "11000k", # 2x maxrate,CBR 更稳(YouTube 偏好) + # 码率(YouTube 1080p@25-30fps 推荐:CBR 风格,4500-6000k 安全) + "-b:v", "4500k", + "-maxrate", "5500k", + "-bufsize", "11000k", + + # ─── 关键修复:替换 -vsync 为 -fps_mode ─── + "-fps_mode", "cfr", # Constant Frame Rate:强制恒定帧率,YouTube 最佳 + # "-vsync", "cfr", # 删除或注释掉,避免 deprecated 警告 + # ───────────────────────────────────────────── - "-vsync", "cfr", # 强制恒帧 "-r", "25", - "-g", "50", "-keyint_min", "25", # 关键帧 2 秒(50/25=2s),符合 YouTube 推荐 ≤4s - "-bf", "0", # 无 B 帧(zerolatency 常见,减少延迟) - "-sc_threshold", "0", # 禁用场景切检测 + "-g", "50", "-keyint_min", "25", # 2秒关键帧,YouTube 推荐 ≤4s + "-bf", "0", + "-sc_threshold", "0", "-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0:rc-lookahead=0", - "-pix_fmt", "yuv420p", # YouTube 标准 + "-pix_fmt", "yuv420p", - # 音频:你的防ID链 + YouTube 推荐 AAC 128-192k - "-c:a", "aac", - "-b:a", "192k", # 高质量立体声(YouTube 支持) - "-ar", "48000", - "-ac", "2", + # 音频(你的防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," @@ -419,16 +420,15 @@ def start_douyin_youtube_ffplay( "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% 音高移位 + "asetrate=48000*1.05,atempo=1.0,aresample=48000," "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 同步 + "aresample=async=1:first_pts=0:min_hard_comp=0.100000:first_pts=0", - # 输出 FLV 到 YouTube(RTMPS 推荐,但 ffmpeg 默认支持) "-flvflags", "no_duration_filesize", "-f", "flv", - youtube_rtmp # 确保是 rtmps://a.rtmp.youtube.com/live2/xxx 如果可用 + youtube_rtmp ]