diff --git a/douyin_youtube_ffplay.py b/douyin_youtube_ffplay.py index e0e4ad7..1dbb42a 100644 --- a/douyin_youtube_ffplay.py +++ b/douyin_youtube_ffplay.py @@ -304,69 +304,67 @@ def start_douyin_youtube_ffplay( # "-f", "flv", youtube_rtmp # ] -# 1080p 工业优化版(CPU 低负载 + 防ContentID + 稳定25fps) + +# 1080p - 极致优化版本(高质量 + YouTube直播推荐友好 + 强防Content ID) +# 视频:比特率拉高到YouTube 1080p直播推荐上限附近,preset faster 平衡质量与CPU +# 音频:采样率统一48000Hz,音高抬升5%,频率偏移加大,EQ更针对性衰减背景音乐频段,增加轻微相位/噪门处理 +# 整体:更稳定的推流参数,适合长时间直播 + ffmpeg_command = [ - "ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-re", - "-stats", "-stats_period", "1", + "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", - # 网络稳定性 - "-rw_timeout", "30000000", - "-reconnect", "1", "-reconnect_at_eof", "1", - "-reconnect_streamed", "1", - "-reconnect_delay_max", "5", + "-headers", douyin_headers, + "-i", real_url, - # 低延迟 - "-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets", - "-flags", "low_delay", - "-err_detect", "ignore_err", - "-max_delay", "80000", - "-thread_queue_size", "2048", + # 视频处理:1080p 纵屏优化 + "-vf", + "fps=25,scale=1080:1920:force_original_aspect_ratio=decrease:flags=bicubic," + "pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black", - "-headers", douyin_headers, - "-i", real_url, + "-c:v", "libx264", + "-preset", "faster", + "-tune", "zerolatency", + "-profile:v", "high", + "-level", "4.2", # 适配1080p@25fps + "-b:v", "8500k", "-maxrate", "10000k", "-bufsize", "20000k", + "-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", - # ================== 视频处理 ================== - # bilinear 降低 CPU + 保持竖屏 - "-vf", "fps=25,scale=1080:1920:force_original_aspect_ratio=decrease:flags=bilinear," - "pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black", + # 音频处理 - 防Content ID 强化版 + "-c:a", "aac", "-b:a", "192k", "-ar", "48000", "-ac", "2", + "-af", + "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:feedback=0.4," # 轻微相位扰动,进一步防检测 + "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", # 强同步 - # 编码优化 - "-c:v", "libx264", - "-preset", "ultrafast", # CPU 低负载 - "-tune", "zerolatency", - "-profile:v", "high", - "-b:v", "4500k", "-maxrate", "5000k", "-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", - "-pix_fmt", "yuv420p", - - # ================== 音频编码 ================== - "-c:a", "aac", - "-b:a", "96k", # 降码率,防ContentID - "-ar", "48000", - "-ac", "2", - - # ================== 音频轻量防ContentID ================== - "-af", - # 背景音乐削弱 + 人声强化 + 轻微变调 - "highpass=f=90,lowpass=f=4200," - "equalizer=f=180:width_type=o:width=2:g=3," - "equalizer=f=1200:width_type=o:width=1.2:g=2," - "asetrate=48000*1.006,aresample=48000," - "acompressor=threshold=-28dB:ratio=3:attack=5:release=80:makeup=3," - "volume=1.05," - "aresample=async=1:first_pts=0", - - # ================== 输出 ================== - "-flvflags", "no_duration_filesize", - "-f", "flv", youtube_rtmp -] - - + # 推流优化 + "-flvflags", "no_duration_filesize", + "-f", "flv", youtube_rtmp + ] proc = None stderr_q = None reader_t = None