This commit is contained in:
eric
2026-03-01 09:36:26 -06:00
parent 96a183f350
commit 391f0f2b40

View File

@@ -152,46 +152,46 @@ def start_douyin_youtube_ffplay(
print(f"[WARN] NVENC 检测失败,回退软件编码: {e}") print(f"[WARN] NVENC 检测失败,回退软件编码: {e}")
# 720p (最原始) # 720p (最原始)
ffmpeg_command = [ # ffmpeg_command = [
"ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-re", # "ffmpeg", "-y", "-loglevel", "info", "-nostdin", "-re",
"-stats", "-stats_period", "1", # "-stats", "-stats_period", "1",
"-rw_timeout", "30000000", # "-rw_timeout", "30000000",
"-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1", # "-reconnect", "1", "-reconnect_at_eof", "1", "-reconnect_streamed", "1",
"-reconnect_delay_max", "5", # "-reconnect_delay_max", "5",
"-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets", # "-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets",
"-flags", "low_delay", # "-flags", "low_delay",
"-err_detect", "ignore_err", # "-err_detect", "ignore_err",
"-max_delay", "80000", # "-max_delay", "80000",
"-thread_queue_size", "2048", # "-thread_queue_size", "2048",
"-headers", douyin_headers, # "-headers", douyin_headers,
"-i", real_url, # "-i", real_url,
# 720p # # 720p
"-vf", "fps=30,scale=720:1280:force_original_aspect_ratio=decrease:flags=lanczos,pad=720:1280:(ow-iw)/2:(oh-ih)/2:black", # "-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", # "-c:v", "libx264",
"-preset", "fast", # "-preset", "fast",
# "-tune", "zerolatency", # # "-tune", "zerolatency",
"-profile:v", "high", # "-profile:v", "high",
# 720p # # 720p
# "-minrate", "3200k","-b:v", "3200k", "-maxrate", "3200k", "-bufsize", "6400k", # bufsize = 2× bitrate保持真 CBR # # "-minrate", "3200k","-b:v", "3200k", "-maxrate", "3200k", "-bufsize", "6400k", # bufsize = 2× bitrate保持真 CBR
"-b:v", "2600k","-maxrate", "3000k","-bufsize", "5200k", # "-b:v", "2600k","-maxrate", "3000k","-bufsize", "5200k",
"-vsync", "cfr", # "-vsync", "cfr",
"-g", "60", "-keyint_min", "60", # "-g", "60", "-keyint_min", "60",
"-r", "30", # "-r", "30",
"-bf", "0", # "-bf", "0",
"-sc_threshold", "0", # "-sc_threshold", "0",
# "-nal-hrd", "cbr", # 改2强制 CBR # # "-nal-hrd", "cbr", # 改2强制 CBR
# 720p # # 720p
# "-x264-params", "nal-hrd=cbr:force-cfr=1:scenecut=0:filler=1", # 改3简化 params锁死 CBR # # "-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", # "-x264-params", "force-cfr=1:scenecut=0:open_gop=0:sync-lookahead=0",
"-pix_fmt", "yuv420p", # "-pix_fmt", "yuv420p",
"-c:a", "aac", "-b:a", "128k", "-ar", "48000", "-ac", "2", # 改41080p可音频上 128kYouTube 推荐) # "-c:a", "aac", "-b:a", "128k", "-ar", "48000", "-ac", "2", # 改41080p可音频上 128kYouTube 推荐)
"-af", "aresample=async=1:first_pts=0", # "-af", "aresample=async=1:first_pts=0",
"-flags", "+global_header", # "-flags", "+global_header",
"-flvflags", "no_duration_filesize", # "-flvflags", "no_duration_filesize",
"-f", "flv", youtube_rtmp # "-f", "flv", youtube_rtmp
] # ]
@@ -358,6 +358,78 @@ def start_douyin_youtube_ffplay(
# "-f","flv", youtube_rtmp # "-f","flv", youtube_rtmp
# ] # ]
# gpt版本
ffmpeg_command = [
"ffmpeg", "-y",
"-loglevel", "info",
"-nostdin",
"-stats", "-stats_period", "1",
# ───────────── 网络稳定 ─────────────
"-rw_timeout", "60000000",
"-reconnect", "1",
"-reconnect_streamed", "1",
"-reconnect_at_eof", "1",
"-reconnect_delay_max", "10",
"-http_persistent", "1",
# ───────────── 实时核心(关键) ─────────────
"-re",
"-use_wallclock_as_timestamps", "1",
"-fflags", "+genpts+discardcorrupt",
"-avoid_negative_ts", "make_zero",
"-thread_queue_size", "512",
"-probesize", "1M",
"-analyzeduration", "1M",
# 输入源
"-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", "veryfast", # 24h 稳定优先
"-tune", "zerolatency",
"-profile:v", "high",
"-level", "4.2",
# YouTube 推荐 1080p 码率区间
"-b:v", "4500k",
"-maxrate", "4500k",
"-bufsize", "9000k",
# 关键帧 & 延迟
"-g", "50",
"-keyint_min", "50",
"-bf", "0",
"-sc_threshold", "0",
"-pix_fmt", "yuv420p",
# 输出恒帧模式(必须在 -i 后面才生效)
"-fps_mode", "cfr",
# ───────────── 音频(轻量稳定版) ─────────────
"-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",
"-f", "flv",
youtube_rtmp
]