Giter Club home page Giter Club logo

bilibililivetools's Introduction

BilibiliLiveTools

Bilibili(B站)无人值守直播工具。自动登录,自动获取直播推流地址,自动推流(使用ffmpeg),可以用于电脑、树莓派等设备无人值守直播。

前提条件

  • 在Bilibili中通过实名认证,并开通了直播间。点击连接开通直播间(很简单的,实名认证通过后直接就可以开通了)
  • 推流默认使用FFmpeg,树莓派官方系统默认安装了的,我就不再赘述,其它系统请自行安装(Windows版本已经打包ffmpeg,就不用自己装了)。

项目说明

  1. BilibiliAutoLiver.Plugin.Base
    视频帧处理插件(目前还不支持)。
  2. BilibiliAutoLiver
    一键开启直播工具。使用方式请查询说明。
  3. Bilibili.AspNetCore.Apis
    哔哩哔哩API封装,封装了完整的登录,Cookie管理相关的API,有其他项目需要可以直接使用。
  4. BilibiliLiverTests
    单元测试神马的。

Tips: 除了开播工具BilibiliAutoLiver以外,其余工具没有编译二进制发行版本。如有需要,可以提交Issue或者自行下载编译。

Demo

扫描二维码登录:

自动化推流直播:

教程

开始推流

  1. 获取程序
    树莓派 64位操作系统:

    wget https://github.com/withsalt/BilibiliLiveTools/releases/latest/download/BilibiliAutoLiver_Linux_ARM64.zip --no-check-certificate

    Windows:
    点击链接下载:https://github.com/withsalt/BilibiliLiveTools/releases/latest/download/BilibiliAutoLiver_Windows_x64.zip

  2. 解压并授权

    unzip BilibiliAutoLiver_Linux_ARM64.zip && chmod -R 755 BilibiliAutoLiver_Linux_ARM64 && chmod +x BilibiliAutoLiver_Linux_ARM64/BilibiliAutoLiver
  3. 运行
    在Linux上面运行:

    ./BilibiliAutoLiver --urls="http://*:18686"  

    这行命令的意思是运行程序,并监听18686端口。

  4. 使用哔哩哔哩APP扫码登录
    程序开始运行后,找到命令行中输出的地址信息,如下图所示:
    在任意浏览器中打开上述任意一个地址,将会出现二维码界面
    使用哔哩哔哩APP进行扫码登录。扫码登录成功后,只要账号不主动退出,就不用再进行扫码登录啦。

  5. 编辑直播设置
    默认情况下,是没有推流配置的。只有配置推流信息之后,才能进行推流。
    扫码登录之后,进入直播设置->推流设置,按照说明填写推流命令(目前仅支持高级模式)。建议填写之前先测试推流命令能否正确执行。
    高级模式推流命令中的“{URL}”,是一个配置符号,将在程序中被替换为获取到的Bilibili推流地址,所以一定要在最终命令中,把测试文件或者地址修改为 “{URL}”(URL大写) ,否则无法保存。
    这里提供常见的两条推流命令:

    a. 树莓派,Linux操作系统:
    推流名称为/dev/video0的摄像头的画面。

    ffmpeg -thread_queue_size 1024 -f v4l2 -s 1280*720 -input_format mjpeg -i \"/dev/video0\" -stream_loop -1 -i \"Content/demo_music.m4a\" -vcodec h264_omx -pix_fmt yuv420p -r 30 -s 1280*720 -g 60 -b:v 10M -bufsize 10M -acodec aac -ac 2 -ar 44100 -ab 128k -f flv {URL}

    b. Winodws操作系统
    推流名称为HD Pro Webcam C920的摄像头的画面。

    ffmpeg -f dshow -video_size 1280x720 -i video=\"HD Pro Webcam C920\" -vcodec libx264 -pix_fmt yuv420p -r 30 -s 1280*720 -g 60 -b:v 5000k -an -preset:v ultrafast -tune:v zerolatency -f flv {URL}

    命令参数具体含义我就不解释了,建议直接问ChatGPT,或者直接让ChatGPT帮忙写推流命令。

  6. 安装FFmpeg(可选)
    为什么是可选?因为已经默认内置了ffmpeg,不用自行安装。但是对于一些其他的linux发行版。可能没有内置ffmpeg,所以需要用户自行安装ffmpeg。
    Linux(基于debian的发行版):

    # 安装,就这一行命令
    sudo apt install ffmpeg
    # 测试是否安装,有输出表示安装完成
    ffmpeg -version
  7. 停止推流
    进入直播设置->推流设置,点击停止直播。

  8. 配置开机自启等
    Linux上面配置系统服务,可以查看:https://www.quarkbook.com/?p=733

常见问题

  1. FFmpeg报错
    肯定是你的ffmpeg指令有问题。这个工具严格意义上来说就是一个ffmpeg调用工具,ffmpeg的使用,全靠你自己。

  2. 通过Cookie登录失败
    长期未登录(至少半年),修改过密码(修改密码后全平台下线),账号失效了?

  3. FFmpeg测试失败,An error occurred trying to start process... 未安装ffmpeg。

题外话

项目中所用的API都是各处扒拉来的野生API,非官方提供的API。因为B站随时在更新API,所以工具有随时挂掉的风险。当发现工具非配置原因导致不可用时,请提交issue。所以在未来遇到无法解决问题且无人接收情况下,此项目将会被废弃。
还有种情况是,我本人也不用了。也就不更新了.....

Todo

1、添加日志功能,能清晰的看到是为何开启推流失败
2、不再直接使用ffmpeg推流命令进行推流,将改为内置的推流方式。将有更高的可玩性,比如提供一个图像处理管道,通过机器视觉对图像进行二次处理。
3、弹幕获取功能(有这个计划,但是我感觉没啥用,不一定会搞)

Stargazers over time

Stargazers over time

bilibililivetools's People

Contributors

withsalt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bilibililivetools's Issues

登陆失败

需要手机或者邮箱的验证码
命令行中给出的登录url,使用浏览器打开后显示需要验证码。不知道这个问题能不能解决

关于如何读取多个视频

appsettings.json中的"FFmpegCmd"怎么使用非ffmpeg的命令,比如我需要利用Linux的命令while true do来循环读取文件夹中的多个视频,但是报错

依然提示输入字符串不是合法 integer

树莓派环境:
Raspberry Pi 4B
系统: Raspbian Linux raspberrypi 4.19.57-v7l+ #1244 SMP Thu Jul 4 18:48:07 BST 2019 armv7l GNU/Linux
版本: No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster

参考操作连接: quarkbook.com/?p=733

错误消息:

Unhandled exception. System.Exception: Convert result model failed. Input string '160.8' is not a valid integer. Path 'data.userCoinIfo.coins', line 1, position 870.
at Bilibili.Api.LiveApi.GetRoomInfo(User user) in E:\CSharp\Projects\BilibiliLiveTools\src\Bilibili\Api\LiveApi.cs:line 135
at BilibiliLiveTools.Program.Main(String[] args) in E:\CSharp\Projects\BilibiliLiveTools\src\BilibiliLiveTools\Program.cs:line 63
at BilibiliLiveTools.Program.

(String[] args)
Aborted

无法正确处理用户信息

SYSTEM INFO

Linux raspberrypi 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42 BST 2020 armv7l GNU/Linux 32bit
version 21bfdeee3a6ea823e2113b983390acd1eec8edfb
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian

ERROR:

Unhandled exception. System.Exception: Convert result model failed. Could not convert string to integer: 2020-06-29. Path 'data.vip_endtime', line 1, position 1015.
   at Bilibili.Api.LiveApi.GetRoomInfo(User user) in E:\CSharp\Projects\Developing\BilibiliLiveTools\src\Bilibili\Api\LiveApi.cs:line 135
   at BilibiliLiveTools.Program.Main(String[] args) in E:\CSharp\Projects\Developing\BilibiliLiveTools\src\BilibiliLiveTools\Program.cs:line 62
   at BilibiliLiveTools.Program.<Main>(String[] args)

一个小小的请求?

大佬,是这样的。我们机厅每天有直播一款名为《舞萌DX》的街机音游,现在用上了您的项目之后就实现了无人值守开播。
不过现在有一个问题:
因为我们机厅的直播是通过obs直播的,并不直接调用工具内的ffmpeg参与推流。
那么工具在获取到推流地址后obs会立刻进行推流,但是工具内的ffmpeg会因为无事可干而导致控制台循环输出错误信息尝试重新推流。
当尝试次数过多时,api会提示获取次数频繁,我们担心这样持续久了会影响到直播账号的风控健康度。
请问有无可以解决此问题的方法?感谢~

登录失败呢

错误信息:{
"code": -449,
"message": "服务繁忙, 请稍后再试",
"ts": 1587874569
}

ffmpeg push rtmp failed

[rtmp @ 0x55ad29d510] Cannot read RTMP handshake response
rtmp://live-push.bilivideo.com/live-bvc/?streamname=xxx

硬币数量不为整数时会报错

Unhandled exception. System.Exception: Convert result model failed. Input string '1315.4' is not a valid integer. Path 'data.userCoinIfo.coins', line 1, position 907.
   at Bilibili.Api.LiveApi.GetRoomInfo(User user) in E:\CSharp\Projects\BilibiliLiveTools\src\Bilibili\Api\LiveApi.cs:line 135
   at BilibiliLiveTools.Program.Main(String[] args) in E:\CSharp\Projects\BilibiliLiveTools\src\BilibiliLiveTools\Program.cs:line 63
   at BilibiliLiveTools.Program.<Main>(String[] args)
fish: “sudo ./BilibiliLiveTools” terminated by signal SIGABRT (Abort)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.