From f4044c0455533b840425fd7645a9a6d97493e6a4 Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 1 Mar 2026 09:52:08 -0600 Subject: [PATCH] 's' --- douyin_youtube_ffplay.py | 83 ++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/douyin_youtube_ffplay.py b/douyin_youtube_ffplay.py index 8e6f92a..2190408 100644 --- a/douyin_youtube_ffplay.py +++ b/douyin_youtube_ffplay.py @@ -358,80 +358,71 @@ def start_douyin_youtube_ffplay( # "-f","flv", youtube_rtmp # ] - # gpt版本 ffmpeg_command = [ - "ffmpeg", "-y", - "-loglevel", "info", - "-nostdin", + "ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-stats", "-stats_period", "1", - # ───────────── 网络稳定 ───────────── + # 网络重连(保持) "-rw_timeout", "60000000", - "-reconnect", "1", - "-reconnect_streamed", "1", - "-reconnect_at_eof", "1", + "-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1", "-reconnect_delay_max", "10", - "-http_persistent", "1", + "-http_seekable", "0", # 直播流通常不可 seek,设 0 防问题 - # ───────────── 实时核心(关键) ───────────── + # 持久连接:替换 http_persistent + "-multiple_requests", "1", # 启用 Keep-Alive,推荐加这个 + + # 实时 & 防超速(保持) "-re", "-use_wallclock_as_timestamps", "1", - "-fflags", "+genpts+discardcorrupt", - "-avoid_negative_ts", "make_zero", - "-thread_queue_size", "512", - "-probesize", "1M", - "-analyzeduration", "1M", + "-thread_queue_size", "64", + "-probesize", "32K", "-analyzeduration", "500000", + "-fflags", "+genpts+discardcorrupt+igndts", - # 输入源 "-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", + # 视频处理(保持) + "-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 稳定优先 + "-preset", "medium", "-tune", "zerolatency", "-profile:v", "high", "-level", "4.2", + "-b:v", "4500k", "-maxrate", "5500k", "-bufsize", "11000k", - # YouTube 推荐 1080p 码率区间 - "-b:v", "4500k", - "-maxrate", "4500k", - "-bufsize", "9000k", - - # 关键帧 & 延迟 - "-g", "50", - "-keyint_min", "50", + "-fps_mode", "cfr", + "-r", "25", + "-g", "50", "-keyint_min", "25", "-bf", "0", "-sc_threshold", "0", + "-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0:rc-lookahead=0:nal-hrd=cbr", "-pix_fmt", "yuv420p", + "-flags", "+global_header", - # 输出恒帧模式(必须在 -i 后面才生效) - "-fps_mode", "cfr", + # 音频(如果之前简化过,先用这个测试;成功后再加回完整链) + "-c:a", "aac", "-b:a", "192k", "-ar", "48000", "-ac", "2", + "-af", "aformat=sample_fmts=fltp:sample_rates=48000:channel_layouts=stereo," + "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," + "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", - # ───────────── 音频(轻量稳定版) ───────────── - "-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", + "-flvflags", "no_duration_filesize+no_metadata", "-f", "flv", youtube_rtmp ] -