Skip to content

Instantly share code, notes, and snippets.

@nitrag
Last active July 24, 2022 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitrag/cd8e441c0c65b99400073151e250c408 to your computer and use it in GitHub Desktop.
Save nitrag/cd8e441c0c65b99400073151e250c408 to your computer and use it in GitHub Desktop.
Redirect Twitch broadcast to OSP (Xbox)
With the Twitch app on Xbox/PS4 running in the background it will broadcast your game and audio to Twitch. This is all well and great if you don't mind privacy. If you do value your privacy you can stream to a private server like OSP (Open Streaming Platform).
One of these:
a. Fancy router in which you can set a custom DST-NAT rules
b. NanoPi R2S (https://www.friendlyelec.com/index.php?route=product/product&product_id=282)
Rough outline of steps:
1. Register a Twitch account
2. Download Twitch on your console, authenticate
3. Test a broadcast to your Twitch account
--- We know that Streaming to Twitch works, now let's redirect this to OSP
4. Setup your OSP server, create an account, create a channel.
5. Modify OSP-RTMP with this diff: https://gitlab.com/osp-group/flask-nginx-rtmp-manager/-/merge_requests/271/diffs
6. Run OSP upgrade and choose OSP-RTMP.
7. Insert the R2S between your Xbox and Router. Router into WAN port, and XBOX in to LAN port. I used the NanoPi R2S with OpenWRT. In OpenWRT go to Firewall -> Adanced -> Custom. Add these lines:
``` bash
OSP_SERVER="1.1.1.1"
iptables -t nat -A PREROUTING -p tcp --dport 1935 -j DNAT --to-destination $OSP_SERVER
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
```
This will redirect any RTMP traffic on port 1935 to the OSP Server of your choosing. Reboot. You should verify the results by running `iptables -t nat -L -n -v`.
8. Get your streaming key. The twitch app uses it's own OAuth mechanism to authenticate the app with your account. It won't tell you what streaming key is used. So after enabling the firewall rule in OpenWRT hit the Start Broadcast in Twitch app. It will die after a few seconds. Now do this while running TCP Dump on your OSP Server `tcpdump port 1935 -w twitch.pcap`. Run that command, Start broadcasting, CTRL-C to stop capture a few seconds after the Twitch stream dies. Transfer that pcap file to your local computer. Open it. Find the packet that says `publish()`, right click and Follow-TCP Stream. In the packet payload you should see something like `publish - https://live.twitch......./app/<your stream key here>?...`.
9. Replace your auto-generated streaming key for your OSP channel. Currently, this is a raw DB edit since changing your key is not currently possible from the web. Mysql into your server and set the key in the `Channels` table.
10. Open Twitch app, hit Broadcast. It should now be hitting your OSP server instead (if setup correctly)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment