This commit is contained in:
eric
2026-03-01 09:55:59 -06:00
parent c6a180c38b
commit c1e2a039ac

View File

@@ -152,46 +152,46 @@ def start_douyin_youtube_ffplay(
print(f"[WARN] NVENC 检测失败,回退软件编码: {e}")
# 720p (最原始)
# 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_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,
# # 720p
# "-vf", "fps=30,scale=720:1280:force_original_aspect_ratio=decrease:flags=lanczos,pad=720:1280:(ow-iw)/2:(oh-ih)/2:black",
# "-c:v", "libx264",
# "-preset", "fast",
# # "-tune", "zerolatency",
# "-profile:v", "high",
# # 720p
# # "-minrate", "3200k","-b:v", "3200k", "-maxrate", "3200k", "-bufsize", "6400k", # bufsize = 2× bitrate保持真 CBR
# "-b:v", "2600k","-maxrate", "3000k","-bufsize", "5200k",
# "-vsync", "cfr",
# "-g", "60", "-keyint_min", "60",
# "-r", "30",
# "-bf", "0",
# "-sc_threshold", "0",
# # "-nal-hrd", "cbr", # 改2强制 CBR
# # 720p
# # "-x264-params", "nal-hrd=cbr:force-cfr=1:scenecut=0:filler=1", # 改3简化 params锁死 CBR
# "-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0",
# "-pix_fmt", "yuv420p",
# "-c:a", "aac", "-b:a", "128k", "-ar", "48000", "-ac", "2", # 改41080p可音频上 128kYouTube 推荐)
# "-af", "aresample=async=1:first_pts=0",
"-headers", douyin_headers,
"-i", real_url,
# 720p
"-vf", "fps=30,scale=720:1280:force_original_aspect_ratio=decrease:flags=lanczos,pad=720:1280:(ow-iw)/2:(oh-ih)/2:black",
"-c:v", "libx264",
"-preset", "fast",
# "-tune", "zerolatency",
"-profile:v", "high",
# 720p
# "-minrate", "3200k","-b:v", "3200k", "-maxrate", "3200k", "-bufsize", "6400k", # bufsize = 2× bitrate保持真 CBR
"-b:v", "2600k","-maxrate", "3000k","-bufsize", "5200k",
"-vsync", "cfr",
"-g", "60", "-keyint_min", "60",
"-r", "30",
"-bf", "0",
"-sc_threshold", "0",
# "-nal-hrd", "cbr", # 改2强制 CBR
# 720p
# "-x264-params", "nal-hrd=cbr:force-cfr=1:scenecut=0:filler=1", # 改3简化 params锁死 CBR
"-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0",
"-pix_fmt", "yuv420p",
"-c:a", "aac", "-b:a", "128k", "-ar", "48000", "-ac", "2", # 改41080p可音频上 128kYouTube 推荐)
"-af", "aresample=async=1:first_pts=0",
# "-flags", "+global_header",
# "-flvflags", "no_duration_filesize",
# "-f", "flv", youtube_rtmp
# ]
"-flags", "+global_header",
"-flvflags", "no_duration_filesize",
"-f", "flv", youtube_rtmp
]
@@ -358,70 +358,6 @@ def start_douyin_youtube_ffplay(
# "-f","flv", youtube_rtmp
# ]
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_xxx
"-multiple_requests", "1", # 启用 HTTP Keep-Alive强烈推荐
# "-http_seekable", "0", # 删除!无效,会报错
# "-http_persistent", "1", # 删除!旧名,已被 multiple_requests 取代
# 实时核心(保持)
"-re",
"-use_wallclock_as_timestamps", "1",
"-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",
"-c:v", "libx264",
"-preset", "medium",
"-tune", "zerolatency",
"-profile:v", "high",
"-level", "4.2",
"-b:v", "4500k", "-maxrate", "5500k", "-bufsize", "11000k",
"-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",
# 音频(完整链,如果之前简化过,先测试简化版)
"-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",
"-flvflags", "no_duration_filesize+no_metadata",
"-f", "flv",
youtube_rtmp
]