14 Commits

Author SHA1 Message Date
eric
e4e68477dd 's' 2025-12-21 18:14:27 -06:00
eric
cc366c0cba 's' 2025-12-21 17:34:30 -06:00
eric
bb87be9ccd 's' 2025-12-21 10:08:57 -06:00
eric
3ea170f8dc 's' 2025-12-21 09:37:41 -06:00
eric
0df754ee45 'd' 2025-12-21 09:32:44 -06:00
eric
f54c324364 's' 2025-12-21 01:17:48 -06:00
eric
e4b0c082b2 's' 2025-12-20 09:31:36 -06:00
eric
7aa77cb473 's' 2025-12-20 09:28:42 -06:00
eric
5770049fbc 's' 2025-12-13 07:19:06 -06:00
eric
b7ad10bb8d 's' 2025-12-13 02:39:43 -06:00
eric
7b3438ad25 s 2025-12-13 08:36:45 +00:00
eric
4385003c24 's' 2025-12-13 02:26:02 -06:00
eric
4f585eea8e 's' 2025-12-13 02:14:58 -06:00
eric
cd4f4f4514 'vlog' 2025-12-13 01:50:49 -06:00
3 changed files with 55 additions and 283 deletions

View File

@@ -1,4 +1,14 @@
https://live.douyin.com/372551154040
https://live.douyin.com/203476627795
https://live.douyin.com/825627287092
https://live.douyin.com/61481392633
https://live.douyin.com/174360482665
https://live.douyin.com/651493903077
https://live.douyin.com/503988877962
https://live.douyin.com/664793904394
https://live.douyin.com/162450932525
https://live.douyin.com/182011399880
https://live.douyin.com/473695498831
https://live.douyin.com/210443559964
https://live.douyin.com/21146786242
https://live.douyin.com/210443559964
https://live.douyin.com/369626255042
https://live.douyin.com/41148117948

291
main.py
View File

@@ -1672,7 +1672,7 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
# ========== 参数配置(保留你原始配置) ==========
# YT_STREAM_KEY = "qxvb-r47b-r5ju-6ud3-6k7z"
youtube_rtmp = f"rtmp://a.rtmp.youtube.com/live2/x04z-564w-aks7-embw-30y4"
youtube_rtmp = f"rtmp://a.rtmp.youtube.com/live2/ue78-1c3e-mr9g-14mz-9r4z" #没有ypp的美食频道
# youtube_rtmp="rtmp://192.168.31.184/live/douyin"
# # ←←←← 在这块代码的上方先定义你要推的多个地址 ←←←←
@@ -1693,7 +1693,7 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
NO_FRAME_TIMEOUT = 120
START_CHECK_AFTER = 25
STALE_OUTPUT_SECONDS = 120 #120
STALE_OUTPUT_SECONDS = 40 #120
@@ -1737,47 +1737,48 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None:
"Origin: https://live.douyin.com\r\n"
)
# 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
]
# 1080p
@@ -1842,170 +1843,8 @@ 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
@@ -2016,14 +1855,6 @@ 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:
@@ -2035,33 +1866,11 @@ 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}")
# 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 的输入
print(f"[INFO][{datetime.datetime.now():%H:%M:%S}] 启动 YouTube 推流 → {stream_title}")
proc = subprocess.Popen(
ffmpeg_command,
stdin=subprocess.DEVNULL,
stdout=ffplay_proc.stdin, # <--- 关键:管道直连 ffplay
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
text=True,
bufsize=1,
@@ -2086,14 +1895,6 @@ 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
@@ -2195,12 +1996,6 @@ 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

View File

@@ -1,36 +1,3 @@
ue78-1c3e-mr9g-14mz-9r4z # 没有ypp的美食
qxvb-r47b-r5ju-6ud3-6k7z # vlog频道
x04z-564w-aks7-embw-30y4 #美食ypp
; https://live.douyin.com/745606325880,主播: w、(摆摊日记_)
; https://live.douyin.com/675343045974,主播: 张子沐的串串(你的电子榨菜)
; https://live.douyin.com/673565298571,主播: 轻舟已撞大冰山(摆摊vlog)
; https://live.douyin.com/835571459859,主播: 海绵饱饱
; https://live.douyin.com/152358755212,主播: 大美_红烧肉
; https://live.douyin.com/990825651731,主播: 王同学摆摊日记(蜜汁烤鸡腿)
; https://live.douyin.com/591442402624,主播: 76696515302
; https://live.douyin.com/967381081829,主播: 憨憨的摆摊日记
; https://live.douyin.com/78012762575,主播: 摆摊儿去划水
; https://live.douyin.com/163813589919,主播: 不要熬夜(摆摊中)
; https://live.douyin.com/498368994814,主播: 剪头发的小帆帆
; https://live.douyin.com/617848099204,主播: 果妈要努力
; https://live.douyin.com/821525628944,主播: 李熙雨⭐
; https://live.douyin.com/993102287144,主播: 小茗早餐(薪笼记助创官)
; https://live.douyin.com/701547125568,主播: 悠悠包
; https://live.douyin.com/816130992220,主播: 甜昕冰冰的摆摊日记
; https://live.douyin.com/876468215361,主播: 晓晓和凡凡
; https://live.douyin.com/511335278313,主播: 秘书(摆摊休息版)
; https://live.douyin.com/483160615952,主播: 小胡同学你好(饭团版)
; https://live.douyin.com/525514386431,主播: 阿闯烤肉夹馍
; https://live.douyin.com/8687122573,主播: 小彤炒粉
; https://live.douyin.com/642534242822,主播: (小王_)煎饼果子
; https://live.douyin.com/743565594721,主播: 汪汪汪小妞
; https://live.douyin.com/249578288248,主播: 思思努力版
; https://live.douyin.com/472140253414,主播: 戴盘龙
; https://live.douyin.com/700846653732,主播: 三哥大锅菜_炒鸡(国基路店)官方号
; https://live.douyin.com/81849868631,主播: 纯儿²¹(休息勿跑空哦)
; https://live.douyin.com/690114366322,主播: 卤味鲜(东大)
; https://live.douyin.com/469980190666,主播: 茜茜柠檬茶(小米茶档_)
; https://live.douyin.com/388066418744,主播: 加速姐的摆摊日记