{"id":21941150,"url":"https://github.com/timerring/bilive","last_synced_at":"2025-03-17T03:19:03.061Z","repository":{"id":250243517,"uuid":"831745006","full_name":"timerring/bilive","owner":"timerring","description":"自动监听、B站直播录制和弹幕、自动转换xml弹幕（含付费留言、礼物等）为ass并压制进视频，自动投稿至B站，无需GPU，兼容超低配置服务器。","archived":false,"fork":false,"pushed_at":"2024-11-08T06:59:45.000Z","size":12477,"stargazers_count":5,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-08T07:37:08.104Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timerring.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-21T14:02:21.000Z","updated_at":"2024-11-08T06:59:44.000Z","dependencies_parsed_at":"2024-11-08T07:37:09.644Z","dependency_job_id":null,"html_url":"https://github.com/timerring/bilive","commit_stats":null,"previous_names":["timerring/blive","timerring/bilive"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timerring%2Fbilive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timerring%2Fbilive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timerring%2Fbilive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timerring%2Fbilive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timerring","download_url":"https://codeload.github.com/timerring/bilive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243965747,"owners_count":20375920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T03:01:05.995Z","updated_at":"2025-03-17T03:19:03.055Z","avatar_url":"https://github.com/timerring.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"assets/headerDark.svg\" /\u003e\n    \u003cimg src=\"assets/headerLight.svg\" alt=\"BILIVE\" /\u003e\n  \u003c/picture\u003e\n\n*7 x 24 小时无人监守录制、渲染弹幕、识别字幕、自动切片、自动上传、兼容超低配机器，启动项目，人人都是录播员。*\n\n[:page_facing_up: Documentation](https://timerring.github.io/bilive/) |\n[:gear: Installation](#quick-start) |\n[:thinking: Reporting Issues](https://github.com/timerring/bilive/issues/new/choose)\n\n支持模型\n\n  \u003cimg src=\"assets/openai.svg\" alt=\"OpenAI whisper\" width=\"60\" height=\"60\" /\u003e\n  \u003cimg src=\"assets/zhipu-color.svg\" alt=\"Zhipu GLM-4V-PLUS\" width=\"60\" height=\"60\" /\u003e\n  \u003cimg src=\"assets/gemini-brand-color.svg\" alt=\"Google Gemini 1.5 Pro\" width=\"60\" height=\"60\" /\u003e\n\n\u003c/div\u003e\n\n##  1. Introduction\n\n\u003e 如果您觉得项目不错，欢迎 :star: 也欢迎 PR 合作，如果有任何疑问，欢迎提 issue 交流。\n\n自动监听并录制B站直播和弹幕（含付费留言、礼物等），根据分辨率转换弹幕、语音识别字幕并渲染进视频，根据弹幕密度切分精彩片段并通过视频理解大模型生成有趣的标题，自动投稿视频和切片至B站，兼容无GPU版本，兼容超低配置服务器与主机。\n\n## 2. Major features\n\n- **速度快**：采用 `pipeline` 流水线处理视频，理想情况下录播与直播相差半小时以内，没下播就能上线录播，**目前已知 b 站录播最快版本**！\n- **多房间**：同时录制多个直播间内容视频以及弹幕文件（包含普通弹幕，付费弹幕以及礼物上舰等信息）。\n- **占用小**：自动删除本地已上传的视频，极致节省空间。\n- **模版化**：无需复杂配置，开箱即用，( :tada: NEW)通过 b 站搜索建议接口自动抓取相关热门标签。\n- **检测片段并合并**：对于网络问题或者直播连线导致的视频流分段，能够自动检测合并成为完整视频。\n- **自动渲染弹幕**：自动转换xml为ass弹幕文件并且渲染到视频中形成**有弹幕版视频**并自动上传。\n- **硬件要求极低**：无需GPU，只需最基础的单核CPU搭配最低的运存即可完成录制，弹幕渲染，上传等等全部过程，无最低配置要求，10年前的电脑或服务器依然可以使用！\n- **( :tada: NEW)自动渲染字幕**(如需使用本功能，则需保证有 Nvidia 显卡)：采用 OpenAI 的开源模型 [`whisper`](https://github.com/openai/whisper)，自动识别视频内语音并转换为字幕渲染至视频中。\n- **( :tada: NEW)自动切片上传**：根据弹幕密度计算寻找高能片段并切片，结合多模态视频理解大模型 [`GLM-4V-PLUS`](https://bigmodel.cn/dev/api/normal-model/glm-4) 自动生成有意思的切片标题及内容，并且自动上传。\n\n项目架构流程如下：\n\n```mermaid\ngraph TD\n        User((用户))--record--\u003estartRecord(启动录制)\n        startRecord(启动录制)--保存视频和字幕文件--\u003evideoFolder[(Video 文件夹)]\n\n        User((用户))--scan--\u003estartScan(启动扫描 Video 文件夹)\n        videoFolder[(Video 文件夹)]\u003c--间隔两分钟扫描一次--\u003estartScan(启动扫描 Video 文件夹)\n        startScan \u003c--视频文件--\u003e whisper[whisperASR模型]\n        whisper[whisperASR模型] --生成字幕--\u003eparameter[查询视频分辨率]\n        subgraph 启动新进程\n        parameter[查询分辨率] --\u003eifDanmaku{判断}\n        ifDanmaku --\u003e|有弹幕| DanmakuFactory[DanmakuFactory]\n        ifDanmaku --\u003e|无弹幕| ffmpeg1[ffmpeg]\n        DanmakuFactory[DanmakuFactory] --根据分辨率转换弹幕--\u003e ffmpeg1[ffmpeg]\n        ffmpeg1[ffmpeg] --渲染弹幕及字幕 --\u003e Video[视频文件]\n        Video[视频文件] --计算弹幕密度并切片--\u003e GLM[多模态视频理解模型]\n        GLM[多模态视频理解模型] --生成切片信息--\u003e slice[视频切片]\n        end\n        \n        slice[视频切片] --\u003e uploadQueue[(上传队列)]\n        Video[视频文件] --\u003e uploadQueue[(上传队列)]\n\n        User((用户))--upload--\u003estartUpload(启动视频上传进程)\n        startUpload(启动视频上传进程) \u003c--扫描队列并上传视频--\u003e uploadQueue[(上传队列)]\n```\n\n\n## 3. 测试硬件\n+ OS: Ubuntu 22.04.4 LTS\n\n  \u003e尽量使用 22.04+ 的版本，更早版本的 ubuntu 自带 gcc 版本无法更新至 DanmakuFactory 以及 biliup-rs 所需版本，若使用较早版本，请参考 [version `GLIBC_2.34‘ not found简单有效解决方法](https://blog.csdn.net/huazhang_001/article/details/128828999)。\n+ CPU：2核 Intel(R) Xeon(R) Platinum 85\n+ GPU：无\n+ 内存：2G\n+ 硬盘：40G\n+ 带宽: 3Mbps\n+ Python 版本: 3.10\n  \u003e 个人经验：若想尽可能快地更新视频，主要取决于上传速度而非弹幕渲染速度，因此建议网络带宽越大越好。\n\n## 4. Quick start\n\n更详细的教程请参考文档 [bilive](https://timerring.github.io/bilive/)\n\n\u003e [!NOTE]\n\u003e 如果你是 windows 用户，请使用 WSL 运行本项目。\n\n### Mode\n首先介绍本项目三种不同的处理模式：\n1. `pipeline` 模式(默认): 目前最快的模式，需要 GPU 支持，最好在 `blrec` 设置片段为半小时以内，asr 识别和渲染并行执行，分 p 上传视频片段。\n![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2024-12-11-17-33-15.png)\n2. `append` 模式: 基本同上，但 asr 识别与渲染过程串行执行，比 pipeline 慢预计 25% 左右，对 GPU 显存要求较低，兼顾硬件性能与处理上传效率。\n![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2024-12-11-19-07-12.png)\n3. `merge` 模式: 等待所有录制完成，再进行识别渲染合并过程，上传均为完整版录播（非分 P 投稿），等待时间较长，效率较慢，适合需要上传完整录播的场景。\n![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2024-12-11-19-08-58.png)\n\n\u003e [!IMPORTANT]\n\u003e 凡是用到 GPU 均需保证 GPU 显存大于运行程序所需 VRAM，具体计算 VRAM 方法可以参考[该部分](https://timerring.github.io/bilive/models.html#计算-vram-需求)。\n\n### Installation(有 GPU 版本)\n\n\u003e 是否有 GPU 以 `nvidia-smi` 显示 nvidia GPU 驱动以及 `nvcc -V` 显示 `CUDA` 版本号为准。如果未配置显卡驱动或未安装 `CUDA`，即使有 GPU 也无法使用，而会使用 CPU 推理（不推荐，可根据自身硬件条件判断是否尝试 CPU 推理）。\n\n\u003e [!TIP]\n\u003e 如果你是 windows 用户，请使用 WSL 运行本项目。\n\n#### 1. 安装依赖(推荐先 `conda` 创建虚拟环境)\n\n```\ncd bilive\npip install -r requirements.txt\n```\n\n此外请根据各自的系统类型安装对应的 [`ffmpeg`](https://www.ffmpeg.org/download.html)，例如 [ubuntu 安装 ffmpeg](https://gcore.com/learning/how-to-install-ffmpeg-on-ubuntu/)。\n\n[常见问题收集](https://timerring.github.io/bilive/install-questions.html)\n\n#### 2. 设置环境变量用于保存项目根目录\n\n```\n./setPath.sh \u0026\u0026 source ~/.bashrc\n```\n\n#### 3. 配置 whisper 模型及 GLM-4V-PLUS 模型\n\n##### 3.1 whisper 模型\n项目默认采用 [`small`](https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.pt) 模型，请点击下载所需文件，并放置在 `src/subtitle/models` 文件夹中。\n\n\u003e [!TIP]\n\u003e 使用该参数模型至少需要保证有显存大于 2.7GB 的 GPU，否则请使用其他参数量的模型。\n\u003e + 更多模型请参考 [whisper 参数模型](https://timerring.github.io/bilive/models.html) 部分。\n\u003e + 更换模型方法请参考 [更换模型方法](https://timerring.github.io/bilive/models.html#更换模型方法) 部分。\n\n##### 3.2 GLM-4V-PLUS 模型\n\n\u003e 此功能默认关闭，如果需要打开请将 `src/config.py` 文件中的 `AUTO_SLICE` 参数设置为 `True`\n\n在配置文件 `src/config.py` 中，`SLICE_DURATION` 以秒为单位设置切片时长（不建议超过 1 分钟），在项目的自动切片功能需要使用到智谱的 [`GLM-4V-PLUS`](https://bigmodel.cn/dev/api/normal-model/glm-4) 模型，请自行[注册账号](https://www.bigmodel.cn/invite?icode=shBtZUfNE6FfdMH1R6NybGczbXFgPRGIalpycrEwJ28%3D)并申请 API Key，填写到 `src/config.py` 文件中对应的 `Your_API_KEY` 中。\n\n#### 4. biliup \u0026 bilitool 登录\n\n首先按照 [biliup-rs](https://github.com/biliup/biliup-rs) 登录b站，登录脚本在 `src/utils/biliup` ，登录产生的`cookies.json`保留在该文件夹下即可。\n\n然后同样通过 `bilitool login` 扫码登录（biliup 的 list 对应 api 已经失效，因此我写了 [bilitool](https://github.com/timerring/bilitool) 工具作为替换）。\n\n[常见问题收集](https://timerring.github.io/bilive/biliup.html)\n\n#### 5. 启动自动录制\n\n```bash\n./record.sh\n```\n\n[常见问题收集](https://timerring.github.io/bilive/record.html)\n\n#### 6. 启动自动上传\n\n请先确保你已经完成`步骤 3`，正确下载并放置了模型文件。\n\n##### 6.1 启动扫描渲染进程\n\n输入以下指令即可检测已录制的视频并且自动合并分段，自动进行弹幕转换，字幕识别与渲染的过程：\n\n```bash\n./scan.sh\n```\n\n[常见问题收集](https://timerring.github.io/bilive/scan.html)\n\n##### 6.2 启动自动上传进程\n\n```bash\n./upload.sh\n```\n\n[常见问题收集](https://timerring.github.io/bilive/upload.html)\n\n\n#### 7. 查看执行日志\n\n相应的执行日志请在 `logs` 文件夹中查看，如果有问题欢迎在 [`issue`](https://github.com/timerring/bilive/issues/new/choose) 中提出。\n```\nlogs # 日志文件夹\n├── blrec # blrec 录制日志\n│   └── ...\n├── scan # scan 处理日志\n│   └── ...\n├── upload # upload 上传日志\n│   └── ...\n└── runtime # 每次执行的日志\n    └── ...\n```\n\n### Installation(无 GPU 版本)\n无 GPU 版本过程基本同上，可以跳过步骤 3 配置 whisper 的部分，需要注意在执行步骤 5 **之前**完成以下设置将确保完全用 CPU 渲染视频弹幕。\n\n1. 请将 `src/config.py` 文件中的 `GPU_EXIST` 参数设置为 `False`。（若置为 `True` 但又没有 GPU 或者 Nvidia 驱动找不到，则会使用 CPU 推理，非常消耗 CPU 计算资源，不推荐，可自行根据硬件条件进行尝试。）\n2. 将 `MODEL_TYPE` 调整为 `merge` 或者 `append`。\n\n\u003e [!TIP]\n\u003e 上传默认参数如下，[]中内容全部自动替换。也可在 src/upload/extract_video_info.py 中自定义相关配置：\n\u003e + 默认标题是\"【弹幕+字幕】[XXX]直播回放-[日期]-[直播间标题]\"。\n\u003e + 默认描述是\"【弹幕+字幕】[XXX]直播，直播间地址：[https://live.bilibili.com/XXX] 内容仅供娱乐，直播中主播的言论、观点和行为均由主播本人负责，不代表录播员的观点或立场。\"\n\u003e + 默认标签是根据主播名字自动在 b 站搜索推荐中抓取的[热搜词]，详见[bilibili-API-collect](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/search/suggest.md)。\n\n### Docker 运行\n\n也可以直接拉取 docker 镜像运行，默认 latest。守护进程是 upload，而 record 以及 scan 需要在配置后手动启动，相关配置以及启动流程从 3.2 开始即可，此版本 docker 镜像无 GPU 配置。\n\n\u003e [!IMPORTANT]\n\u003e 如果不需要使用可视化页面可以忽略以下提醒：\n\u003e - 不推荐在有公网 ip 的服务器上直接暴露 22333 端口访问管理页面，如果使用请自行限制端口入站 ip 规则或者采用 nginx 等反向代理配置密钥限制他人访问。\n\u003e - 管理页面主要针对 record 模块，只有手动运行 record 后(步骤5)才能访问到管理页面。\n\n```bash\nsudo docker run \\\n    -itd \\\n    --name bilive_docker \\\n    -p 22333:2233 \\\n    timerring/bilive:0.2.10\n```\n\n## 特别感谢\n\n- [biliup/biliup-rs](https://github.com/biliup/biliup-rs)\n- [hihkm/DanmakuFactory](https://github.com/hihkm/DanmakuFactory)\n- [acgnhiki/blrec](https://github.com/acgnhiki/blrec)\n- [OpenAI/whisper](https://github.com/OpenAI/whisper)","funding_links":[],"categories":["其他_机器视觉","直播相关工具","Python"],"sub_categories":["资源传输下载","直播脚本"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimerring%2Fbilive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimerring%2Fbilive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimerring%2Fbilive/lists"}