基于BililiveRecorder 的集群录播客户端

Overview

高度自动化的录播服务端!

banner

一、项目介绍

1、介绍

这是NGlive的录播服务器集群的客户端部分实现代码,它可以自动化的进行录制-压制-上传-通知,同时流程高度可自定义,并且可以任意受中心服务器的调度,有一定的错误修复能力。可以保证长期稳定的运行。

2、基本功能

这个客户端集 录制、转码压制、上传为一体,同时集成了正向反向API、WS等功能 如下图所示: 这里应该有图、但是还没有做

3、环境

本项目基于Python3.9.0开发,在其他版本的运行状态未知请在安装依赖前阅读下面的说明 可以有效减少出问题的概率。

4、依赖

Package Version
baidupcs-py 0.6.25
requests 2.26.0
fastapi 0.63.0
pydantic 1.7.3
pathlib 1.0.1
SQLAlchemy 1.3.22
loguru 0.5.3
websockets 8.1
  • 安装 baidupcs-py 时,请前往 这里 仔细阅读安装注意事项

5、项目结构

本项目结构如下:

├─ BililiveRecorder  录播姬
|  __GraphQL.py      封装了部分graphql方法
│  README.md         自述文件
│  LICENSE           LICENSE
│  db.py             数据库的定义和基本操作   
|  eventManager.py   事件驱动核心 
|  eventRun.py       NGlive任务管理
|  initial.py        配置文件
|  linstener.py      监听-响应模块
|  log.py            日志配置
|  orm.py            验证-整理数据
|  resquest_test.py  验证-整理数据
|  systemInfo.py     系统监控
|  taskslist.py      任务队列
|  trcode.py         转码模块
|  up.py             上传模块
|  upload.py         上传功能的实现
|  wsclient.py       ws模块
|  api.py            程序入口

6、交流

外联群QQ:781665797

二、使用

安装并配置ffmpeg

您如果用到了转码模块 需要安装并配置 ffmpeg 您需要在环境变量中配置他或者自行修改代码。

配置录播姬

略 请参考 BililiveRecorder的配置文档 录播姬需要配置webhook

配置NGlive

下载本项目后,用任意IDE打开 config.ini

你会看到这些配置选项

[BASIC]
; 录播姬的位置 本项目带有一个含有GraphQL API 的版本
; 如果您使用不含有 GraphQL API 的版本,会导致部分功能不可用
; 不用带引号 绝对路径和相对路径都能用
RecorderPath = ./BililiveRecorder/BililiveRecorder.Cli.exe
; 录播姬的 GraphQL API 端口
api_port = 8200
; 录播姬的工作目录 里面要包含配置 如果您不会配置,请查看录播姬的文档
works_path = F:\\录播
; 转码输出的路径
out_path = ./out
; 录播姬需要配置 webhook 地址为 http://127.0.0.1:8100/webhook/
; NGlive 正向服务器地址
NGhost = 127.0.0.1
; NGlive 服务器端口
NGport = 8100
; WS地址 如果有 请修改为您自己的
wspath = ws://lb.ngworks.cn/nglive/nglive_xa/ws?token=3b1e903e-1a8c-8fa8-296e-dbd9bfcc2e38

[TRANSCODE]

; 码率控制模式或编码方式 必须全部大写!!
; COPY 直接复制 flv文件转换封装为 MP4

; CRF  恒定速率因子模式 进行码率控制
; CQ  恒定量化器模式 进行码率控制
; B   固定目标码率模式 进行码率控制

; ABR  平均比特率的编码方式。
; VBR  动态(可变)比特率的方式进行编码。
model = CQ

; 编码器
; 目前尽只可以使用 X264 必须全部大写!!
encoder = X264

; 当使用 CRF 模式时 需要配置 固定码率系数 crf
; crf 参数应当根据实际选择 0 是最清晰 但是体积是最大的 51 是最大压缩 画质损失最大
; crf 参数区间应为[0~51] 主观上讲 [18~28]是一个合理的区间 本配置文件默认  24
crf = 24

; 当使用 CQ 模式时 需要配置 恒定量化因子 cqp
; cqp 参数应当根据实际选择 0 是最清晰 但是体积是最大的 51 是最大压缩 画质损失最大
; cqp 参数区间应为[0~51] 主观上讲 [18~28]是一个合理的区间 本配置文件默认  24
cq = 24

; 当使用ABR模式或 B模式时 需要配置 目标比特率 单位(Kbps)
; 目标比特率请根据您的实际需求选择
Bitrate = 5000

; 用于设置码率控制缓冲器的大小,设置的好处是,让整体的码率更趋近于希望的值,减少波动
bufsize = 2000

; preset 参数主要调节编码速度和质量的平衡 必须全部小写!!
; 有ultrafast、superfast、veryfast、faster、fast、medium、slow、slower、veryslow、placebo这10个选项,从快到慢
preset = veryfast

[COOKIES]
; 百度云的cookies  还在写

[FACTORY]
; 流程控制  还在写

根据自己的实际情况配置。

直接使用

您仅需要按照上述方法配置后下载本项目,双击运行api.py文件。

终端中运行

您可以在项目目录下打开终端: 输入以下命令:

python api.py

如果您是windows操作系统 我们非常不建议您这样做,因为在使用过程中,如果您选择了终端中的任何字符,都会让终端进入快速编辑模式,这样会让程序暂停,从而发生意料之外的事情。

三、如何工作

1、概览

NGlive并不集成录制功能: NGlive的录制功能依赖于BililiveRecorder,他们中间通过http api 进行数据交换。

NGlive不是一个单机的录播系统: NGlive是一个分布式的录播集群,它应当由 录制客户端(NGlive)均衡服务器(RecorderMaster)web服务构成。但是他们之间相互独立,正如本项目,没有中心服务器的依赖,您也可以让其很好的运行。

NGlive是一个流程高度可以编辑的系统: 您可以随意的编排录播消费的方法,不用按部就班的操作,如果配合图形化的ui,您可以向搭积木一样安排您的流程。

他们之间的信息交换如图:

时序图

我们为有公网IP资源的机器提供了正向HTTP正向ws使其可以被其他成员访问,为其提供了更加完美的开放能力。

同时没有公网IP资源的机器也至少可以通过反向http反向ws与均衡服务器进行交互,而WS服务为其与其他成员进行直接交互提供了可能。

NGlive客户端采用了事件驱动的开发思路 每个模块之间互不干扰,仅通过监听器进行交互。

NGlive尝试使用了 生产者-消费者 模型 每个模块之间的联系通过任务队列进行数据传递。

NGlive有一定的自我恢复能力tasksDocter发现某个线程意外退出时,他会将该线程重启,以保证程序整体的正常运行。

2、web API 与数据结构

2.1、错误码

错误码 说明
4031 错误的房间号
4032 房间号重复添加
4033 这个房间位于黑名单
4042 房间号不存在

2.2、Http API

2.2.1 获取当前添加的所有房间

GET http://127.0.0.1:8100/allroom

获得当前服务器添加的所有房间与其配置。

2.2.2 获取指定房间信息

GET http://127.0.0.1:8100/getroom

请求参数

参数 类型 说明
roomid interesting 房间号码

获得指定房间号码的信息和配置。

2.3.3 添加房间

GET http://127.0.0.1:8100/addroom

请求参数

参数 类型 说明
roomid interesting 房间号码

添加一个房间,并立即开始录制。

2.4.4 删除房间

GET http://127.0.0.1:8100/removeroom

请求参数

参数 类型 说明
roomid interesting 房间号码

停止该房间的录制,并立即将其删除。

2.3、WS

2.3.1、ws事件

事件名称 含义
SessionStarted 开播/手动开始录制
FileOpening 文件打开
FileClosed 文件关闭
SessionEnded 关播/手动关闭录制
TranscodeStarted 开始转码
IsTranscode 正在转码
TranscodeEnded 转码结束
TranscodeError 转码出错
UpStarted 开始上传
IsUp 正在上传
UpEnded 结束上传
UpError 上传出错
heartbeat 服务器心跳数据

四、贡献 - 特别感谢 - license

1、贡献

如果您发现了更好的使用方法,不妨分享出来!你可以使用pr功能提交请求,我会审阅。或者在使用中出现了什么问题,都可以提交issue,或者加入我们的外联群(QQ:781665797)交流。

2、特别感谢

3、license

GNU AGPLv3 许可证

Owner
NGWORKS
NGWORKS
Lightweight, zero-dependency proxy and storage RTSP server

python-rtsp-server Python-rtsp-server is a lightweight, zero-dependency proxy and storage server for several IP-cameras and multiple clients. Features

Vlad 39 Nov 23, 2022
This plugin generates json files used by deovr allowing you to play 2d and 3d video's using the player

deovr-plugin This plugin generates json files used by deovr allowing you to play 2d and 3d video's using the player. Deovr looks for an index file /de

10 Sep 29, 2022
A Simple Telegram Bot By @Tellybots to add Subtitle Files in Video

Video-subtitle-merger A Simple Telegram Bot By @Tellybots to add Subtitle Files in Video Features Force Sub Button Added Soon Support Media Type Such

6 Dec 31, 2021
camKapture is an open source application that allows users to access their webcam device and take pictures or create videos.

camKapture is an open source application that allows users to access their webcam device and take pictures or create videos.

manoj 1 Jun 21, 2022
Converts Betaflight blackbox gyro to MP4 GoPro Meta data so it can be used with ReelSteady GO

Here are a bunch of scripts that I created some time ago as a proof of concept that Betaflight blackbox gyro data can be converted to GoPro Metadata F

108 Oct 05, 2022
Home Assistant custom component for viewing IP cameras RTSP stream in real time using WebRTC technology

WebRTC Camera Home Assistant custom component for viewing IP cameras RTSP stream in real time using WebRTC technology. Based on: Pion - pure Go implem

Alex X 739 Dec 30, 2022
Zaid Vc Player Bot For Telegram

Zaid Vc Player Bot For Telegram

1 Dec 04, 2021
Webcam Indicator is an application to recieve and send messages from your own Webcam Server.

Welcome to Webcam Indicator 👋 Webcam Indicator is an application to recieve and send messages from your own Webcam Server. 🏠 Homepage Prerequisites

Lorenzo Carbonell 2 Apr 04, 2022
Python Script for Streaming YouTube Videos in VLC Media Player.

Short Description Use this Simple Script to stream YouTube Video to VLC

Sijey 6 May 27, 2021
goal: render videos on eu4's timeline function

Rendering Videos on the EU4 Time Line This repository contains code to create an eu4-savefile that plays back a video in question.

29 Dec 24, 2022
This application makes a webrtc video call with jitsi meet signaling

gstreamer-jitsi-meet This application makes a webrtc video call with jitsi meet signaling. Other end can be any jitsi meet app or web app. It doesn't

Linh 7 Apr 26, 2022
Source files for the data lake demo video using the AWS TICKIT database

Data Lake Demo Source code for video demonstration detailed in the post, Building a Simple Data Lake on AWS . Build a simple data lake on AWS using a

Gary A. Stafford 97 Dec 23, 2022
Video stream recording dockerized server using python/ffmpeg.

Stream Recording Server Video stream recording dockerized server using python/ffmpeg. Usage Configuration Prepare .env file, check .env.example for th

GR 2 Jan 14, 2022
720p FPGA Media Player (RISC-V + Motion JPEG + SD + HDMI on an Artix 7)

FPGA Media Player This project is a FPGA based media player which is capable of playing Motion JPEG encoded video over HDMI or VGA on commonly availab

179 Dec 02, 2022
Boltstream Live Video Streaming Website + Backend

Boltstream Self-hosted Live Video Streaming Website + Backend Reference

Ben Wilber 1.7k Dec 28, 2022
Program for converting video to GIF

video-to-gif Program for converting video to GIF Install the lib: pip install moviepy Usage: Specify the path to the video file. clip = VideoFileClip(

Artem Mokin 0 Dec 13, 2021
Automatically logs into VTOP and can perform certain tasks

VTOP_Login Automatically logs into VTOP and can perform certain tasks To run the

Jatin 1 Jan 30, 2022
plumi video sharing

December 2017 update We are moving tickets from the Plumi tracker (trac.plumi.org) here, for historical reasons. Plumi video sharing system Plumi is a

Plumi 111 Dec 15, 2022
pyYotubemanager is full web automated bot capable of General tasks like:- Uploading a Video , Downloading , adding Title , Description , Listing types , adding Thumbnail

PyYoutubemanager Explore the docs » View Demo · Report Bug · Request Feature About The Project PyYotubemanager is full web automated bot capable of Ge

4 Jun 29, 2022
A python program which converts images and video into excel spreadsheets.

image2excel A program which converts images and video into Excel spreadsheets. Usage examples can be found in examples Videos can take a long time to

Oscar Peace 2 Aug 09, 2021