diff --git a/douyin_youtube_ffplay.py b/douyin_youtube_ffplay.py index 6af82e8..b1cbda0 100644 --- a/douyin_youtube_ffplay.py +++ b/douyin_youtube_ffplay.py @@ -254,60 +254,137 @@ def start_douyin_youtube_ffplay( # 1080p + # 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", "80000", + # "-thread_queue_size", "2048", + + # "-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", "superfast", + # "-tune", "zerolatency", + # "-profile:v", "high", + # "-b:v", "5200k", "-maxrate", "5800k", "-bufsize", "10400k", + # "-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", "128k", "-ar", "44100", "-ac", "2", + + # "-af", + # "arnndn=m=./arnndn-models/cb.rnnn:mix=0.80," + # "afftdn=nf=-18:tn=1," + # "highpass=f=120,lowpass=f=4600," + # "equalizer=f=250:width_type=o:width=2:g=-6," + # "equalizer=f=900:width_type=o:width=1.4:g=-4," + # "asetrate=48000*1.012,aresample=48000," + # "acompressor=threshold=-30dB:ratio=4:attack=10:release=120:makeup=4," + # "volume=1.10," + # "aresample=async=1:first_pts=0", + + # "-flvflags", "no_duration_filesize", + # "-f", "flv", youtube_rtmp + # ] + +# 1080p 工业优化版(稳定 + 防ContentID + 低CPU) 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", "80000", - "-thread_queue_size", "2048", + "ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-re", + "-stats", "-stats_period", "1", - "-headers", douyin_headers, - "-i", real_url, + # 网络稳定性 + "-rw_timeout", "30000000", + "-reconnect", "1", "-reconnect_at_eof", "1", + "-reconnect_streamed", "1", + "-reconnect_delay_max", "5", - # 视频:不动你原策略,只给编码喘口气 - "-vf", "fps=25,scale=1080:1920:force_original_aspect_ratio=decrease:flags=bicubic," - "pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black", + # 低延迟 + "-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets", + "-flags", "low_delay", + "-err_detect", "ignore_err", + "-max_delay", "80000", + "-thread_queue_size", "2048", - "-c:v", "libx264", - "-preset", "superfast", - "-tune", "zerolatency", - "-profile:v", "high", - "-b:v", "5200k", "-maxrate", "5800k", "-bufsize", "10400k", - "-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", + "-headers", douyin_headers, + "-i", real_url, - # 音频 - "-c:a", "aac", "-b:a", "128k", "-ar", "44100", "-ac", "2", + # ================== 视频处理 ================== + # 保留你竖屏策略,降低 CPU bicubic → bilinear + "-vf", "fps=25,scale=1080:1920:force_original_aspect_ratio=decrease:flags=bilinear," + "pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black", - "-af", - "arnndn=m=./arnndn-models/cb.rnnn:mix=0.80," - "afftdn=nf=-18:tn=1," - "highpass=f=120,lowpass=f=4600," - "equalizer=f=250:width_type=o:width=2:g=-6," - "equalizer=f=900:width_type=o:width=1.4:g=-4," - "asetrate=48000*1.012,aresample=48000," - "acompressor=threshold=-30dB:ratio=4:attack=10:release=120:makeup=4," - "volume=1.10," - "aresample=async=1:first_pts=0", + # 编码优化 + "-c:v", "libx264", + "-preset", "veryfast", # superfast→veryfast(画质更稳) + "-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", - "-flvflags", "no_duration_filesize", - "-f", "flv", youtube_rtmp + # ================== 音频编码 ================== + "-c:a", "aac", + "-b:a", "96k", # 降码率,降低ContentID指纹精度 + "-ar", "48000", + "-ac", "2", + + # ================== 音频防ContentID链 ================== + "-af", + # 深度降噪(可选,模型路径必须绝对路径) + # "arnndn=m=/home/eric/ffmpeg/arnndn-models/cb.rnnn:mix=0.6," + + # 背景音乐削弱(关键防ContentID) + "afftdn=nf=-25:tn=1:om=o," + + # 人声带通(强化人声) + "highpass=f=90,lowpass=f=4200," + + # 人声EQ + "equalizer=f=180:width_type=o:width=2:g=3," # 低频增强 + "equalizer=f=1200:width_type=o:width=1.2:g=2,"# 清晰度 + + # 轻微变调(ContentID杀手) + "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 ] - - - # ====================== 主重试循环(原样保留) ====================== + # ====================== 主重试循环(原样保留) ====================== + proc = None stderr_q = None reader_t = None