基于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
A Telegram bot to convert videos into x265/x264 format via ffmpeg.

Video Encoder Bot A Telegram bot to convert videos into x265/x264 format via ffmpeg. Configuration Add values in environment variables or add them in

Adnan Ahmad 82 Jan 03, 2023
A tool to fuck a video/audio quality using FFmpeg

Media quality fucker A tool to fuck a video/audio quality using FFmpeg How to use Download the source Download Python Extract FFmpeg Put what you want

Maizena 8 Jan 25, 2022
Cvplayer - A simple video player written in python using ffpyplayer and OpenCV

Video Player cvplayer is a minimal wrapper around the ffpyplayer.MediaPlayer cla

ADI 7 Dec 19, 2022
Program to play videos with props in Apex Legends

R5Fresh A video player for the Apex Legends mod R5Reloaded

9 Nov 13, 2022
Tiny python video cutter

tiny_python_video_cutter Source code based on a discussion in StackOverflow Setup project in Pycharm: Configure virtual env in Pycharm. You are done w

Truong 2 May 28, 2022
MPV remote controller is a program for remote controlling mpv player with device in your local network through web browser.

MPV remote controller is a program for remote controlling mpv player with device in your local network through web browser.

5 May 26, 2022
Image and video quality assessment

CenseoQoE: 视觉感知画质评价框架 项目介绍 图像/视频在编解码、传输和显示等过程中难免引入不同类型/程度的失真导致图像质量下降。图像/视频质量评价(IVQA)的研究目标是希望模仿人类视觉感知系统, 通过算法评估图片/视频在终端用户的眼中画质主观体验的好坏,目前在视频编解码、画质增强、画质监。

Tencent 133 Dec 20, 2022
Rune - a video miniplayer made with Python.

Rune - a video miniplayer made with Python.

1 Dec 13, 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
MoviePy is a Python library for video editing, can read and write all the most common audio and video formats

MoviePy is a Python library for video editing: cutting, concatenations, title insertions, video compositing (a.k.a. non-linear editing), video processing, and creation of custom effects. See the gall

10k Jan 08, 2023
pyffstream - A CLI frontend for streaming over SRT and RTMP specializing in sending off files

pyffstream - A CLI frontend for streaming over SRT and RTMP specializing in sending off files

Gregory Beauregard 3 Mar 04, 2022
GStreamer Inspector GUI

gst-explorer GStreamer GUI Interface Tool GUI interface for inspecting GStreamer Plugins, Elements and Type Finders. Expects Python3 Qt, PyQt5 and GSt

Jetsonhacks 31 Nov 29, 2022
Search a video semantically with AI.

Which Frame? Search a video semantically with AI. For example, try a natural language search query like "a person with sunglasses". You can also searc

David Chuan-En Lin 1 Nov 06, 2021
Python script for extracting audio from video files and creating Mel spectrograms

video2spectrogram About This package is meant to automate the process of extracting audio files from videos and saving the plots computed from these a

Alexandros Stergiou 1 Oct 28, 2021
基于BililiveRecorder 的集群录播客户端

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

NGWORKS 7 Jul 10, 2022
A GUI based datamoshing apllication for everyone! Apply this glitch to your videos and gifs. Supports all video formats!

A GUI based datamoshing apllication for everyone! Apply this glitch to your videos and gifs. Supports all video formats!

Akascape 131 Dec 31, 2022
Examples of usage of GStreamer hlssink3 plugin.

Examples of usage of GStreamer hlssink3 plugin.

Rafael Carício 2 Aug 03, 2022
Automatic video generator for local news

Automatic video generator for local news

Gabriel Monteiro 2 Jan 11, 2022
Splat a video into a mosaic by sampling a frame at regular intervals

Splat a video into a mosaic by sampling a frame at regular intervals. Useful for seeing the changes over time of an entire video or movie.

Ryan Fox 4 Oct 16, 2022
Spotify playlist video generator

This program creates a video version of your Spotify playlist by using the Spotify API and YouTube-dl.

0 Mar 03, 2022