6 Commits

Author SHA1 Message Date
eric
166ea9d603 'grok-1080p' 2025-12-28 10:25:06 -06:00
eric
69179ff709 'grok-1080p' 2025-12-28 10:18:51 -06:00
eric
53f2c77421 's' 2025-12-28 08:45:14 -06:00
eric
9107995c02 ';s' 2025-12-28 08:20:11 -06:00
eric
3ff4facd3d 's' 2025-12-28 07:52:07 -06:00
eric
34bb2b661e 's' 2025-12-28 07:50:05 -06:00
2 changed files with 248 additions and 67 deletions

View File

@@ -1,29 +1,4 @@
https://live.douyin.com/456576000931,主播: 介休〖烩饕〗大块牛肉饭「摆摊」
https://live.douyin.com/272489828538,主播: 90后摆摊卖肉夹馍
https://live.douyin.com/208318182053,主播: 小碗(创业版)
https://live.douyin.com/646935372639,主播: 小雪摆摊记
https://live.douyin.com/956877163856,主播: 饭饱饱
https://live.douyin.com/881451071780,主播: YINING一柠手打柠檬茶
https://live.douyin.com/270513395244,主播: 小喻的摆摊日记
https://live.douyin.com/742474761291,主播: 阿诺椰子•
https://live.douyin.com/820845121901,主播: 地摊闺蜜_创意寿司_(马儿努力版)
https://live.douyin.com/497155982953,主播: 想吃糖葫芦
https://live.douyin.com/349973241990,主播: 元气满满饭团(摆摊不摆烂版)
https://live.douyin.com/597618993066,主播: 婷婷的茶生活
https://live.douyin.com/782322393954,主播: 小葵(摆摊版)
https://live.douyin.com/16531926455,主播: 木黎黎
https://live.douyin.com/739670432305,主播: 干饭007
https://live.douyin.com/572442812068,主播: 小小
https://live.douyin.com/477961427964,主播: 小鱼
https://live.douyin.com/686507122231,主播: 上海少妇鲜果茶
https://live.douyin.com/50627104055,主播: 冷阿姨
https://live.douyin.com/339454333072,主播: 小安炒粉
https://live.douyin.com/72212955083,主播: 花老板回村了
https://live.douyin.com/280422307519,主播: 早餐妹
https://live.douyin.com/651293616593,主播: 会發的黄
https://live.douyin.com/114111936890,主播: 小乖早安_(小七泡面)
https://live.douyin.com/43665279648,主播: 喵喵老师
https://live.douyin.com/122383435921,主播: 婷饱饱
https://live.douyin.com/92876979328,主播: 福宝(野摊小馄饨)
https://live.douyin.com/517715534931,主播: 一只羊
https://live.douyin.com/460525712926,主播: 丽姐摆摊记
https://live.douyin.com/372551154040
https://live.douyin.com/203476627795
https://live.douyin.com/825627287092
https://live.douyin.com/61481392633

282
main.py
View File

@@ -1781,44 +1781,44 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
# 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",
# 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,
# 1080p
"-vf","fps=30,scale=1080:1920:force_original_aspect_ratio=decrease:flags=lanczos,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black",
"-c:v", "libx264",
"-preset", "veryfast",
"-tune", "zerolatency",
"-profile:v", "high",
# 1080p
"-b:v", "5200k", "-maxrate", "5800k", "-bufsize", "10400k", # 改12× bufsize真 CBR
"-vsync", "cfr",
"-g", "60", "-keyint_min", "60",
"-r", "30",
"-bf", "0",
"-sc_threshold", "0",
# "-nal-hrd", "cbr", # 改2强制 CBR
# 1080p
"-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", "aresample=async=1:first_pts=0",
# "-headers", douyin_headers,
# "-i", real_url,
# # 1080p
# "-vf","fps=30,scale=1080:1920:force_original_aspect_ratio=decrease:flags=lanczos,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black",
# "-c:v", "libx264",
# "-preset", "veryfast",
# "-tune", "zerolatency",
# "-profile:v", "high",
# # 1080p
# "-b:v", "5200k", "-maxrate", "5800k", "-bufsize", "10400k", # 改12× bufsize真 CBR
# "-vsync", "cfr",
# "-g", "60", "-keyint_min", "60",
# "-r", "30",
# "-bf", "0",
# "-sc_threshold", "0",
# # "-nal-hrd", "cbr", # 改2强制 CBR
# # 1080p
# "-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", "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
# ]
# srs内网配置
@@ -1842,8 +1842,170 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
# "-f", "flv", srs_rtmp
# ]
# # 1080p ffplay 预览命令(极致低延迟 + 全屏 HDMI已非常完美再加两项
# ffplay_cmd = [
# "ffplay",
# "-f", "flv",
# "-fflags", "nobuffer+flush_packets",
# "-flags", "low_delay",
# "-framedrop", # 关键:网络抖动时掉帧保流畅
# "-infbuf", # 防止输入端卡住
# "-probesize", "32",
# "-analyzeduration", "0",
# "-sync", "ext",
# "-vf", "transpose=2,"
# "colorspace=all=bt709:iall=bt709:fast=1," # 加 fast=1 轻微加速颜色转换
# "eq=gamma_r=0.95:gamma_g=1.0:gamma_b=1.05:"
# "brightness=0.03:saturation=0.85:contrast=1.05",
# "-fs",
# "-autoexit",
# "-threads", "8", # A733 8核用满没问题
# "-nodisp", "no", # 确保显示(某些环境需要显式)
# "-"
# ]
# # 1080p 主 ffmpeg 命令1080p 最优平衡版,小改动)
# ffmpeg_command = [
# "ffmpeg",
# "-y",
# "-loglevel", "info",
# "-nostdin",
# "-re",
# "-stats", "-stats_period", "2", # 改成 2 秒一次,减少日志刷屏,略省 CPU
# # 重连参数
# "-rw_timeout", "30000000",
# "-reconnect", "1",
# "-reconnect_at_eof", "1",
# "-reconnect_streamed", "1",
# "-reconnect_delay_max", "15", # 稍长一点,更稳
# # 极致低延迟输入
# "-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets",
# "-flags", "low_delay",
# "-err_detect", "ignore_err",
# "-headers", douyin_headers,
# "-i", real_url,
# # 视频处理1080p 竖屏lanczos 画质好A733 完全吃得住)
# "-vf", "fps=30,"
# "scale=1080:1920:force_original_aspect_ratio=decrease:flags=lanczos,"
# "pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black",
# # 编码veryfast + zerolatency 是当前最佳平衡
# "-c:v", "libx264",
# "-preset", "veryfast", # A733 上 veryfast 比 ultrafast 画质明显更好CPU 占用仅高 5-10%
# "-tune", "zerolatency",
# "-profile:v", "high",
# "-b:v", "5200k",
# "-maxrate", "5800k",
# "-bufsize", "10400k",
# "-g", "60",
# "-keyint_min", "30",
# "-r", "30",
# "-vsync", "cfr",
# "-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", "aresample=async=1:first_pts=0",
# # 输出
# "-flags", "+global_header",
# "-flvflags", "no_duration_filesize",
# "-f", "flv",
# "pipe:1"
# ]
# ==================== 最佳稳定方案720p + 极致防护 ffplay ====================
ffplay_cmd = [
"ffplay",
"-f", "flv",
"-fflags", "nobuffer+flush_packets", # 零缓冲,低延迟
"-flags", "low_delay",
"-framedrop", # 网络抖动时掉帧保流畅
"-infbuf", # 防止输入端卡住
"-probesize", "32",
"-analyzeduration", "0",
"-sync", "ext", # 外部同步,减少等待
"-vf", "transpose=2,"
"colorspace=all=bt709:iall=bt709:fast=1," # 颜色空间转换加速
"eq=gamma_r=0.95:gamma_g=1.0:gamma_b=1.05:"
"brightness=0.03:saturation=0.85:contrast=1.05", # 你喜欢的调色
"-fs", # 全屏 HDMI
# "-autoexit", # 坚决去掉!防止 ffplay 误判流结束而退出
"--loop", "0", # 关键防护:无限循环,即使短暂无数据也不退出
"-threads", "8", # A733 8核用满调度更好
"-nodisp", "no", # 确保强制显示
"-"
]
ffmpeg_command = [
"ffmpeg",
"-y",
"-loglevel", "info",
"-nostdin",
"-re",
"-stats", "-stats_period", "2", # 每2秒打印一次状态减少日志开销
# 重连参数
"-rw_timeout", "30000000",
"-reconnect", "1",
"-reconnect_at_eof", "1",
"-reconnect_streamed", "1",
"-reconnect_delay_max", "15",
# 极致低延迟输入
"-fflags", "+genpts+discardcorrupt+nobuffer+flush_packets",
"-flags", "low_delay",
"-err_detect", "ignore_err",
"-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", "ultrafast", # 最高速度,最低 CPU防止启动阶段冲垮 ffplay
"-tune", "zerolatency", # 最低延迟
"-profile:v", "high",
"-b:v", "2600k", # 720p 清晰推荐比特率
"-maxrate", "3000k",
"-bufsize", "6000k",
"-g", "60",
"-keyint_min", "30",
"-r", "30",
"-vsync", "cfr",
"-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", "aresample=async=1:first_pts=0",
# ==================== 输出 ====================
"-flags", "+global_header",
"-flvflags", "no_duration_filesize",
"-f", "flv",
"pipe:1"
]
# ---- 单层重试循环(清晰可控) ----
proc = None
ffplay_proc = None # <--- 新增这一行
stderr_q = None
reader_t = None
retry_delay = INITIAL_RETRY_DELAY
@@ -1854,6 +2016,14 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
if retry_delay > INITIAL_RETRY_DELAY:
print(f"[WARN] 防风控等待 {retry_delay}s 后重新连接抖音源...")
time.sleep(retry_delay)
# 清理旧的 ffplay 进程(防止残留)
if ffplay_proc and ffplay_proc.poll() is None:
try:
ffplay_proc.stdin.close()
ffplay_proc.wait(timeout=3)
except:
ffplay_proc.terminate()
ffplay_proc = None # 重置为 None
# 每次重连前先清理上一次的进程/线程
try:
@@ -1865,11 +2035,33 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
stderr_q = None
stderr_q = queue.Queue()
print(f"[INFO][{datetime.datetime.now():%H:%M:%S}] 启动 YouTube 推流 → {stream_title}")
# 油管直播
# print(f"[INFO][{datetime.datetime.now():%H:%M:%S}] 启动 YouTube 推流 → {stream_title}")
# proc = subprocess.Popen(
# ffmpeg_command,
# stdin=subprocess.DEVNULL,
# stdout=subprocess.DEVNULL,
# stderr=subprocess.PIPE,
# text=True,
# bufsize=1,
# universal_newlines=True
# )
# HDMI直播
print(f"[INFO][{datetime.datetime.now():%H:%M:%S}] 启动抖音拉流 → HDMI 全屏显示")
# 先启动 ffplay准备接收管道数据
ffplay_proc = subprocess.Popen(
ffplay_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
# 再启动 ffmpeg把输出直接连到 ffplay 的输入
proc = subprocess.Popen(
ffmpeg_command,
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stdout=ffplay_proc.stdin, # <--- 关键:管道直连 ffplay
stderr=subprocess.PIPE,
text=True,
bufsize=1,
@@ -1894,6 +2086,14 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
if time.time() - getattr(proc, "last_out_ts", time.time()) > STALE_OUTPUT_SECONDS:
print("[WARN] 长时间无任何日志,强制重启进程")
cleanup_proc(proc)
# 关闭 ffplay 进程
if ffplay_proc and ffplay_proc.poll() is None:
try:
ffplay_proc.stdin.close() # 关闭管道输入,让 ffplay 自然退出
ffplay_proc.wait(timeout=5)
except:
ffplay_proc.terminate()
ffplay_proc = None # <--- 加这行
break
continue
@@ -1995,6 +2195,12 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
clear_record_info(record_name, record_url)
except Exception:
pass
# 新增
if 'ffplay_proc' in locals() and ffplay_proc and ffplay_proc.poll() is None:
try:
ffplay_proc.terminate()
except:
pass
color_obj.print_colored(f"[{record_name}] YouTube 推流异常退出但已清理\n", color_obj.RED)
return