PS5用户直播只能用采集卡或者直接推送到twich或者youtube,无意中看到B站有同学用PS5直接推送到B站,但是需要一些技术门槛,按照那个同学的思路整理了自己直播到B站的方式
思路
PS5推流到nginx-rtmp,再从nginx-rtmp推流到B站,但是这样的话弹幕看到,所以搞了个IRF转发的代码段。
PS5跟twitch服务器发送相互数据如下:
1.PS5发送PASS
2.irc回复特定内容
3.PS5发送JOIN
4.irc回复特定内容(据实际观察,3、4步重复两次)
前四步已经建立了信任连接,之后就是irc单向往PS5发送消息
那么我们自己建一个irc服务器,跟PS5交互就行
步骤
使用抽取B站直播间弹幕的用的是https://github.com/xfgryujk/blivedm,也可以看我的github,里面有以下代码文件
1.simple.py中直播间号码改成自己的
1 2 3
| TEST_ROOM_IDS = [ 22509403, ]
|
2.simple.py中添加像irf发送弹幕代码
1 2 3 4 5 6
| def send(bmsg): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('10.255.1.101', 6667)) s.send(bmsg.encode('utf-8')) s.close()
|
3.simple.py中async def _on_danmuku下面添加代码
1
| send(":" + message.uname +"!" + message.uname + "@" + message.uname + ".tmi.twitch.tv PRIVMSG " + "#willwillwang :"+ message.msg + "\r\n")
|
4.Irc服务器程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| import socket import os from threading import Thread import threading
clients = set() clients_lock = threading.Lock()
def listener(client, address): print ("Accepted connection from: ", address) with clients_lock: clients.add(client) try: while True: data = client.recv(1024) if not data: break else: print (repr(data)) if b'PASS' in data: msg = """:tmi.twitch.tv 001 willwillwang :Welcome, GLHF! :tmi.twitch.tv 001 willwillwang :Welcome, GLHF! :tmi.twitch.tv 002 willwillwang :Your host is tmi.twitch.tv :tmi.twitch.tv 003 willwillwang :This server is rather new :tmi.twitch.tv 004 willwillwang :- :tmi.twitch.tv 375 willwillwang :- :tmi.twitch.tv 372 willwillwang :You are in a maze of twisty passages, all alike. :tmi.twitch.tv 376 willwillwang :> """ data = msg.encode('ascii') if b'JOIN' in data: msg = """:willwillwang!willwillwang@willwillwang.tmi.twitch.tv JOIN #willwillwang :willwillwang.tmi.twitch.tv 353 willwillwang = #willwillwang :willwillwang """ data = msg.encode('ascii') with clients_lock: for c in clients: c.sendall(data) print(data.decode('utf-8')) finally: with clients_lock: clients.remove(client) client.close()
host = '0.0.0.0' port = 6667
s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((host,port)) s.listen(3) th = []
while True: print ("Server is listening for connections...") client, address = s.accept() th.append(Thread(target=listener, args = (client,address)).start())
s.close()
|
注意
把上面willwillwang的部分更改为自己twitch账号