's'
This commit is contained in:
45
d2ypp2/docs/ARCHITECTURE.md
Normal file
45
d2ypp2/docs/ARCHITECTURE.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Live Platform 四层架构
|
||||
|
||||
## 分层
|
||||
|
||||
| 层 | 职责 | 代码/路径 |
|
||||
|----|------|-----------|
|
||||
| Core OS | 用户、SSH、mDNS、Wi‑Fi、WebTTY、Docker、systemd、日志 | `scripts/linux/install_hub.sh` 及系统包 |
|
||||
| Infra Service | ShellCrash、Caddy、Netdata、SRS、Neko、ws-scrcpy、FRP、WireGuard 占位 | `services/*`、`scripts/linux/service_ctl.sh` |
|
||||
| Business | 无人直播 douyinyoutube(FFmpeg/HDMI/推流),可脱离控制台运行 | 仓库根业务脚本、`install-live.sh` |
|
||||
| Web Console | 仅通过 API 与配置中心「控制」,不实现业务算法 | `web.py`、`web-console`、`/hub/*` API |
|
||||
|
||||
## 配置中心
|
||||
|
||||
- 安装目标:`/opt/live/config/`
|
||||
- 默认模板:`live-platform/config/defaults/`
|
||||
- 文件:`system.json`、`network.json`、`services/*.json`、`business/*.json`
|
||||
- 生成兼容层:`live-platform/tools/render_stack_env.py` → `/opt/live/generated/system-stack.env`(供现有 shell 读取,逐步淘汰分散 `.env`)
|
||||
|
||||
## 一键脚本(幂等)
|
||||
|
||||
| 脚本 | 作用 |
|
||||
|------|------|
|
||||
| `./install-core.sh` | 同步 JSON → `/opt/live/config`,生成 env,调用 `install_hub.sh`(无业务) |
|
||||
| `./install-live.sh` | 仅业务模块,调用 `install_business.sh` |
|
||||
| `./doctor.sh` | 网络、端口、adb、ffmpeg、docker、API 健康检查 |
|
||||
|
||||
## API
|
||||
|
||||
- `GET /hub/dashboard`:快照 + 服务 + 安卓 + 直播进程状态
|
||||
- `GET /hub/config`:配置中心只读聚合
|
||||
- `POST /hub/business/douyinyoutube`:业务元数据(如抖音 URL 声明)
|
||||
- 既有:`/service_action`、`/android/*`、`/process_monitor`、`/save_url_config` 等
|
||||
|
||||
## 前端
|
||||
|
||||
- `/`:`LiveControlApp` 产品壳(总览、服务、直播、安卓、网络、设置)
|
||||
- `/console`:高级遗留控制台(全功能)
|
||||
- 开发:`middleware` 将 `/hub` 代理到本机 FastAPI
|
||||
|
||||
## live.local(无端口验收)
|
||||
|
||||
- **`install_hub.sh` 末尾**执行 **`install_live_edge_proxy`**:安装/启用 **`live-edge.service`(Caddy)**,将 **`http://live.local`(:80)** 反代到 **`127.0.0.1:${PORT}`**(默认 8001)。
|
||||
- **Homepage** 默认改绑 **`HOMEPAGE_PORT=3080`**,避免与 Caddy 抢 80。
|
||||
- 仅更新反代:`sudo bash scripts/linux/reinstall_live_edge.sh`
|
||||
- `ENABLE_LIVE_EDGE_PROXY=0` 可关闭(`system-stack.env`)。
|
||||
119
d2ypp2/docs/REALTIME_AUDIO_DEMUCS.md
Normal file
119
d2ypp2/docs/REALTIME_AUDIO_DEMUCS.md
Normal file
@@ -0,0 +1,119 @@
|
||||
# 实时音频处理最佳方案(Demucs + RTX 3060)
|
||||
|
||||
## 一、方案对比
|
||||
|
||||
| 方案 | 版权规避率 | 延迟 | 算力 | 复杂度 |
|
||||
|------|------------|------|------|--------|
|
||||
| **FFmpeg 纯滤波**(当前) | 60-70% | 0 | 低 | 低 |
|
||||
| **Demucs 人声分离** | 90%+ | 4-8s | RTX 3060 | 中高 |
|
||||
|
||||
---
|
||||
|
||||
## 二、推荐架构:Demucs 实时管道
|
||||
|
||||
```
|
||||
抖音流 ─┬─ FFmpeg 解复用 ─┬─ 视频 ─────────────────────────────┐
|
||||
│ │ │
|
||||
│ └─ 音频 ─→ Python Demucs ─→ 人声 ────┼─→ FFmpeg 复用 ─→ YouTube RTMP
|
||||
│ (分块处理) │
|
||||
└────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 核心参数(RTX 3060 12GB)
|
||||
|
||||
| 参数 | 推荐值 | 说明 |
|
||||
|------|--------|------|
|
||||
| **模型** | `htdemucs`(单模型,非 _ft) | 速度最快,质量够用 |
|
||||
| **chunk 长度** | 2.5-3 秒 | 延迟 ≈ 2×chunk ≈ 5-6s |
|
||||
| **overlap** | 0.25 | 减少接缝,质量更好 |
|
||||
| **shifts** | 0 | 降低算力,实时必需 |
|
||||
| **segment** | 7.8(默认)或更小 | 显存不足时减小 |
|
||||
|
||||
### RTX 3060 算力
|
||||
|
||||
- 约 13 TFLOPS,高于 Demucs 实时所需 2 TFLOPS
|
||||
- 12GB 显存足够 htdemucs(约 6-8GB)
|
||||
- 预期:**2-4× 实时速度**,可满足直播
|
||||
|
||||
---
|
||||
|
||||
## 三、实现方式
|
||||
|
||||
### 方式 A:Python 自建管道(推荐)
|
||||
|
||||
```python
|
||||
# 伪代码流程
|
||||
# 1. FFmpeg 从抖音拉流,输出: -vn -acodec pcm_s16le -ar 44100 -ac 1 pipe:1
|
||||
# 2. 主进程读取音频块(2.5s = 110250 samples @ 44.1kHz)
|
||||
# 3. 调用 demucs.separate_audio(model, chunk) 得到 vocals
|
||||
# 4. 人声写入 pipe,FFmpeg 另一进程读取并与视频复用推流
|
||||
```
|
||||
|
||||
**依赖**:
|
||||
```
|
||||
demucs
|
||||
torch
|
||||
torchaudio
|
||||
```
|
||||
|
||||
**模型加载**:
|
||||
```python
|
||||
from demucs.pretrained import get_model
|
||||
model = get_model('htdemucs') # 单模型,非 htdemucs_ft
|
||||
```
|
||||
|
||||
### 方式 B:GStreamer(若可用)
|
||||
|
||||
GStreamer 1.28+ 内置 demucs 元素,CPU 约 8× 实时:
|
||||
|
||||
```bash
|
||||
# 需安装 gst-plugins-rs (含 demucs)
|
||||
gst-launch-1.0 uridecodebin uri=抖音流 ! audioconvert ! demucs ! ...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 四、分块处理要点
|
||||
|
||||
1. **重叠**:chunk 之间 25% 重叠,避免接缝
|
||||
2. **队列**:双缓冲,一块处理时另一块接收
|
||||
3. **采样率**:Demucs 默认 44100 Hz,与 FFmpeg 输出一致
|
||||
4. **延迟**:总延迟 ≈ 2 × chunk 长度(约 5-6 秒可接受)
|
||||
|
||||
---
|
||||
|
||||
## 五、快速验证(离线测试)
|
||||
|
||||
```bash
|
||||
# 安装
|
||||
pip install demucs torch torchaudio
|
||||
|
||||
# 测试 30 秒音频分离速度
|
||||
demucs -n htdemucs --two-stems=vocals -j 1 test_30s.mp3 -o output/
|
||||
|
||||
# 若 30s 在 10s 内完成 → 可实时
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 六、与当前方案的关系
|
||||
|
||||
- **当前**:`douyin_youtube_ffplay.py` 纯 FFmpeg,60-70% 规避率
|
||||
- **升级**:可新增 `douyin_youtube_demucs.py`,集成 Demucs 管道
|
||||
- **切换**:通过 config 选择 `mode = ffmpeg` 或 `mode = demucs`
|
||||
|
||||
---
|
||||
|
||||
## 七、配置建议(config/youtube.ini)
|
||||
|
||||
```ini
|
||||
[youtube]
|
||||
key = xxx
|
||||
|
||||
# 音频模式: ffmpeg | demucs
|
||||
; audio_mode = ffmpeg
|
||||
|
||||
# Demucs 专用
|
||||
; demucs_chunk = 2.5
|
||||
; demucs_model = htdemucs
|
||||
```
|
||||
50
d2ypp2/docs/YOUTUBE_LIVE_SEO.md
Normal file
50
d2ypp2/docs/YOUTUBE_LIVE_SEO.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# YouTube Live 转播优化与 SEO 指南
|
||||
|
||||
## 一、推流技术参数(已自动优化)
|
||||
|
||||
- **分辨率**:720p 竖屏 (720×1280)
|
||||
- **比特率**:4.5 Mbps(可在 config/youtube.ini 的 bitrate 调整)
|
||||
- **关键帧**:2 秒(符合 YouTube 推荐)
|
||||
- **音频**:AAC 128kbps 48kHz 立体声
|
||||
- **协议**:RTMPS 加密推流(推荐)
|
||||
- **防版权**:开源音频处理链(降噪 + 带通 + EQ + 相位扰动)
|
||||
|
||||
## 二、YouTube 直播 SEO 与推荐权重
|
||||
|
||||
直播标题、描述、标签在 **YouTube 工作室** 创建直播时设置,推流程序无法修改。以下为提升推荐权重的建议:
|
||||
|
||||
### 标题(前 60 字最关键)
|
||||
|
||||
- 主关键词放前面,如:`LIVE 摆摊日常 | 路边直播`
|
||||
- 可加实时感词汇:LIVE、直播、实时、正在直播
|
||||
- 避免堆砌关键词,保持可读性
|
||||
|
||||
### 描述(前 125 字影响搜索)
|
||||
|
||||
- 首段包含主关键词和内容概要
|
||||
- 可说明:转播自抖音、直播内容类型、时间等
|
||||
|
||||
### 标签
|
||||
|
||||
- 5–15 个相关标签,如:live stream, 摆摊, 路边直播, 抖音转播
|
||||
- 与标题、描述语义一致
|
||||
|
||||
### 算法相关因素
|
||||
|
||||
- **观看时长**:用户停留越久,推荐越高
|
||||
- **互动**:点赞、评论、分享
|
||||
- **画质与音质**:清晰稳定的流有助于留存
|
||||
|
||||
## 三、config/youtube.ini 配置说明
|
||||
|
||||
| 配置项 | 说明 | 示例 |
|
||||
|--------|------|------|
|
||||
| key | 必填,YouTube stream key | key = xxxx-xxxx-xxxx |
|
||||
| rtmps | 是否用 RTMPS(默认是) | rtmps = 否 |
|
||||
| bitrate | 视频比特率 kbps | bitrate = 4500 |
|
||||
|
||||
## 四、稳定性建议
|
||||
|
||||
1. 网络:上行带宽 ≥ 6 Mbps,建议有线
|
||||
2. 推流前在 YouTube 工作室完成标题、描述、标签设置
|
||||
3. 定期检查 config/youtube.ini 中的 stream key 是否有效
|
||||
120
d2ypp2/docs/install-profiles.md
Normal file
120
d2ypp2/docs/install-profiles.md
Normal file
@@ -0,0 +1,120 @@
|
||||
# Linux Install Profiles
|
||||
|
||||
## Quick Start
|
||||
|
||||
Use one of these entrypoints from the repo root on Debian, Ubuntu, or Armbian:
|
||||
|
||||
```bash
|
||||
sudo bash install-hub.sh
|
||||
sudo bash install-business.sh
|
||||
sudo bash install-all.sh
|
||||
```
|
||||
|
||||
### After `git pull` (no full reinstall)
|
||||
|
||||
刷新依赖、重建前端、重启 `live-console` 与 `live-edge`(**不要**为此再跑 `install-all.sh`,除非你要重做整机栈):
|
||||
|
||||
```bash
|
||||
cd /home/live/douyinyoutube # 或你的克隆路径
|
||||
sudo bash upgrade-live.sh
|
||||
```
|
||||
|
||||
若仓库只更新了 **`live-console.service` 模板**(例如 `StartLimitIntervalSec`),可单独刷新单元:
|
||||
|
||||
```bash
|
||||
sudo bash refresh-live-unit.sh
|
||||
```
|
||||
|
||||
## What Each Script Does
|
||||
|
||||
### `install-hub.sh`
|
||||
|
||||
Use this when the Linux device should become the reusable super hub first.
|
||||
|
||||
- Creates and refreshes the `live` account
|
||||
- Installs the shared control plane runtime
|
||||
- Enables `live.local`
|
||||
- Creates the default Wi-Fi profile `live / 12345678` when `wlan0` exists
|
||||
- Installs ShellCrash, WebTTY, Cockpit, File Browser, Homepage, and Netdata
|
||||
- Installs the Android web panel based on `web-scrcpy`
|
||||
- Builds the web console and enables `live-console.service`
|
||||
|
||||
### `install-business.sh`
|
||||
|
||||
Use this when the device should only run the Douyin or YouTube business stack.
|
||||
|
||||
- Creates and refreshes the `live` account
|
||||
- Installs the shared control plane runtime
|
||||
- Installs ffmpeg, mpv, ADB, Chromium
|
||||
- Installs the Android web panel based on `web-scrcpy`
|
||||
- Starts SRS
|
||||
- Builds the web console and enables `live-console.service`
|
||||
- Installs **Caddy** `live-edge.service` so **`http://live.local`** (port 80) reverse-proxies to the control plane (same as hub)
|
||||
- Generates the hardware profile for adaptive ARM or X86 defaults
|
||||
|
||||
### `http://live.local` returns 502
|
||||
|
||||
502 means the edge proxy reached nothing usable on the upstream port (default `127.0.0.1:8001`).
|
||||
|
||||
1. Check the control plane: `sudo systemctl status live-console.service` and `journalctl -u live-console.service -n 80 --no-pager`.
|
||||
2. Check the edge: `sudo systemctl status live-edge.service` and confirm `config/system-stack.env` **`PORT`** matches what Caddy uses (regenerate with `sudo bash scripts/linux/reinstall_live_edge.sh` from the repo root).
|
||||
3. Quick probe: `curl -sf http://127.0.0.1:8001/health` — if this fails, fix `live-console` first (Python venv, `web-console/out`, or `scripts/launch.py` errors in the journal).
|
||||
|
||||
**Older business installs** (before `install_live_edge_proxy` was included) never installed Caddy; if you still see 502 on port 80, you likely had a prior hub/edge install—run `sudo bash scripts/linux/reinstall_live_edge.sh` after pulling the latest repo.
|
||||
|
||||
### Browser: `live.local` — **refused to connect** (not 502)
|
||||
|
||||
That means the TCP connection was **rejected or nothing listens** on the address you used (often **port 80** on the box’s IP).
|
||||
|
||||
1. On the **device**, run: `sudo bash probe-live.sh` (or `scripts/linux/probe_live_access.sh`) and read the `:80` / `:8001` lines.
|
||||
2. If **`:8001` works** but **`:80` fails**: `live-edge` (Caddy) is down — `sudo systemctl restart live-edge.service` or `sudo bash scripts/linux/reinstall_live_edge.sh`.
|
||||
3. If **both fail**: `live-console` is down — `sudo systemctl restart live-console.service` and `journalctl -u live-console.service -n 80`.
|
||||
4. From a **laptop/phone**, open **`http://<device-LAN-IP>:8001/`** first (same Wi‑Fi). If that works but `http://live.local` does not, the problem is **mDNS** (Windows often needs Bonjour) or you’re not on the same LAN — use the IP bookmark.
|
||||
5. **Firewall** (nftables/ufw) blocking **80/8001** from Wi‑Fi will also show as “refused” from other hosts while loopback still works.
|
||||
|
||||
### PM2:单频道与多频道 Pro(Linux ARM / x86_64)
|
||||
|
||||
- **单频道**:在项目根启用一个业务进程即可,例如取消注释 `ecosystem.config.cjs` 里的 `youtube` 或 `tiktok`,执行 `pm2 start ecosystem.config.cjs && pm2 save`。
|
||||
- **多频道 Pro**:每路直播需要**独立的** `config/youtube.ini` 与 `config/URL_config.ini`(或整份独立工作目录)。为第二路及以后各复制一份目录(或符号链接脚本外的配置),在 PM2 里为每个 app 设置不同的 `cwd`,`name` 与 Web 控制台 Pro 线路建议名一致(如 `youtube2__<channelId>`)。
|
||||
- **硬件编码**:`sudo python3 scripts/hardware_probe.py --write` 会写入 `config/hardware.env` 与 `hardware-profile.json`;推流侧可选 `LIVE_VIDEO_ENCODER`(RKMPP / V4L2M2M / VA-API / QSV 等,见 `config/hardware.env.example`)。NVIDIA 一般由 `douyin_youtube_ffplay.py` 自动走 NVENC。
|
||||
- **音频链**:与 GitLab 分支 `ffmpegAudioRMFoode` 中 `douyin_youtube_ffplay.py` 的 FFmpeg 处理思路一致(`fast_audio`、arnndn、EQ 等);当前主线在 Linux 上还包含板载编码探测与推流稳定性增强,以前端无需对齐 Electron 为准。
|
||||
|
||||
### `install-all.sh`
|
||||
|
||||
Use this when the node should be both the super hub and the livestream business node.
|
||||
|
||||
- Runs `install-hub.sh`
|
||||
- Runs `install-business.sh`
|
||||
- Reuses shared modules instead of replacing them
|
||||
|
||||
## Shared Config
|
||||
|
||||
All install profiles read the same shared file:
|
||||
|
||||
- `config/system-stack.env`
|
||||
|
||||
If the file does not exist, the installer copies:
|
||||
|
||||
- `config/system-stack.env.example`
|
||||
|
||||
This keeps host identity, ports, Wi-Fi, ShellCrash path, and module toggles centralized.
|
||||
|
||||
## Default Access URLs
|
||||
|
||||
With the default hostname and ports, a fresh hub exposes:
|
||||
|
||||
- `http://live.local:8001` main control plane
|
||||
- `http://live.local:8001/shellcrash` ShellCrash editor route
|
||||
- `http://live.local:8001/android` Android device center route
|
||||
- `http://live.local:7681` WebTTY
|
||||
- `http://live.local:8082` File Browser, default login `live / 12345678`
|
||||
- `http://live.local:19999` Netdata
|
||||
|
||||
The ShellCrash and Android pages are separate routes on purpose, so they can be bookmarked directly instead of sharing the same tabbed root URL.
|
||||
|
||||
## Separation Rules
|
||||
|
||||
- The hub profile must keep working without SRS.
|
||||
- The business profile must keep working without Cockpit, Homepage, File Browser, or Netdata.
|
||||
- The control plane should show degraded modules as unavailable instead of crashing.
|
||||
- Every service must be removable by systemd or compose boundaries.
|
||||
103
d2ypp2/docs/super-hub-architecture.md
Normal file
103
d2ypp2/docs/super-hub-architecture.md
Normal file
@@ -0,0 +1,103 @@
|
||||
# Super Hub Architecture
|
||||
|
||||
## Goal
|
||||
|
||||
Build the ARM or X86 node as a reusable Linux super hub instead of a single-purpose
|
||||
streaming box. The Douyin or YouTube workflow is one optional business module that can
|
||||
be installed alone or layered on top of the hub later.
|
||||
|
||||
## Install Profiles
|
||||
|
||||
- `install-hub.sh`
|
||||
- Base Linux super hub
|
||||
- Web control plane
|
||||
- mDNS `live.local`
|
||||
- Wi-Fi onboarding profile
|
||||
- ShellCrash
|
||||
- WebTTY
|
||||
- Cockpit
|
||||
- File Browser
|
||||
- Homepage
|
||||
- Netdata
|
||||
- Hardware probe
|
||||
|
||||
- `install-business.sh`
|
||||
- Shared control plane runtime
|
||||
- ffmpeg, mpv, ADB, Chromium
|
||||
- SRS
|
||||
- Hardware probe and adaptive decode defaults
|
||||
- Douyin or YouTube business orchestration
|
||||
|
||||
- `install-all.sh`
|
||||
- Runs the hub profile first
|
||||
- Runs the business profile second
|
||||
- Safe to rerun because the shared pieces are idempotent
|
||||
|
||||
## Layers
|
||||
|
||||
1. Base Node
|
||||
- Debian / Ubuntu / Armbian
|
||||
- `live` user
|
||||
- mDNS with `live.local`
|
||||
- Wi-Fi bootstrap
|
||||
- hardware probe and graceful degradation
|
||||
|
||||
2. Control Plane
|
||||
- FastAPI backend
|
||||
- Next.js panel
|
||||
- managed config roots
|
||||
- service registry and status polling
|
||||
|
||||
3. Hub Modules
|
||||
- ShellCrash
|
||||
- WebTTY
|
||||
- Cockpit
|
||||
- File Browser
|
||||
- Homepage
|
||||
- Netdata
|
||||
- Android Web Panel
|
||||
|
||||
4. Business Modules
|
||||
- Douyin / YouTube relay app
|
||||
- SRS
|
||||
- HDMI playback bridge
|
||||
- Android / ADB integration
|
||||
- Chromium persistent profile
|
||||
- Browser-based device control via web-scrcpy
|
||||
|
||||
5. Future Modules
|
||||
- Caddy
|
||||
- WireGuard
|
||||
- FRP
|
||||
- Matrix
|
||||
- Uptime Kuma
|
||||
- n8n
|
||||
- AI and media workloads
|
||||
|
||||
## Design Rules
|
||||
|
||||
- `install-hub.sh` must never hard-depend on business services such as SRS.
|
||||
- `install-business.sh` must work on a clean Linux system without requiring the hub profile first.
|
||||
- If the hub profile already exists, the business profile must reuse it instead of replacing it.
|
||||
- Each service stays in its own systemd unit or compose file so it can be removed without breaking unrelated modules.
|
||||
- The control plane edits only managed roots and never exposes arbitrary filesystem write access.
|
||||
- ARM and X86 share one control plane, then diverge only through the generated hardware profile.
|
||||
|
||||
## Current Implementation
|
||||
|
||||
- `scripts/linux/lib/common.sh` contains the shared install functions used by every profile.
|
||||
- `scripts/linux/install_hub.sh` installs the reusable Linux super hub.
|
||||
- `scripts/linux/install_business.sh` installs the Douyin or YouTube business module.
|
||||
- `scripts/linux/install_stack.sh` remains as a compatibility entrypoint for `hub`, `business`, and `all`.
|
||||
- `src/control_plane.py` exposes managed roots, hardware profile loading, and service actions.
|
||||
- `scripts/hardware_probe.py` generates safe runtime defaults for ARM and X86.
|
||||
- `services/` keeps dockerized modules isolated instead of merging them into one monolith.
|
||||
|
||||
## Recommended Next Modules
|
||||
|
||||
- Caddy for unified reverse proxy and TLS
|
||||
- wg-easy for WireGuard mesh management
|
||||
- FRP panel for tunnel management
|
||||
- Uptime Kuma for alerting
|
||||
- n8n for workflow automation
|
||||
- Matrix plus Element for messaging and operations collaboration
|
||||
Reference in New Issue
Block a user