Local PS4 live streaming

L

The PS4 has a wonderful live stream feature built in. It supports Twitch and Ustream and for most people thats plenty, but what if you wanted to use another service? What if you wanted to archive all of your gameplay without uploading it to Twitch?

In this post I’ll be showing you how to stream from your PS4 to a local (or remote) RTMP server.

This guide assumes you have some expirence with nix like environments.

The method I use is destructive and will break Twitch streaming for anyone else on the network.

Requirements

  • dd-wrt enabled router (or any router with iptables)
  • nix server environment
  • nginx with the nginx-rtmp-module installed
  • ffmpeg installed (to convert the video container after stream ends)

IPTables

To capture the outgoing RTMP stream, I’m using NAT redirection on the Twitch IP range for port 1935.

iptables -t nat -A PREROUTING -d 199.9.0.0/16 -p tcp --dport 1935 -j DNAT --to-destination <local_ip>:1935  
iptables -t nat -A POSTROUTING -j MASQUERADE  

You can ssh into your router and and paste these lines directly into the prompt, any future requests will be redirected. When you reboot your router, these rules will be removed.

RTMP Server

To recive the stream locally, you need an RTMP server that can handle the stream, I’m using the nginx-rtmp-moduleHere is a guide on getting that setup.

Here is the config for the rtmp module and the bash script I use to convert from FLV to MP4.

rtmp {  
    server {
        listen 1935;
        application app {
            live on;
            recorder storage {
                record all;
                record_path /home/user/gameplay;
                record_unique on;
                exec_record_done /home/user/gameplay/.encode.sh $path $basename;
            }
        }
    }
}
#!/bin/bash
/usr/local/bin/ffmpeg -i $1 -vcodec copy -acodec copy -threads 1 /home/user/gameplay/`date '+%b_%d_%Y_%H_%M'`.mp4
rm $1  

If your RTMP server is outside of the local network, you could use the push directive to continue pushing the stream to twitch, something like this:

push rtmp://live-ord.twitch.tv/app/$name;  

At this point the server would be acting as a proxy.


Once you have the RTMP server running, you should be able to broadcast from the Twitch app on your PS4 and it be intercepted by your local server.

Videos are stored in .flv format and once the stream ends they will be converted to .mp4. The videos format is 1280×720 h264 with AAC audio.

Here is a video showcasing the quality, it isn’t the best, but it’s a pretty great way to archive all your gameplay locally.

Add Comment

Benjamin Phelps

Get in touch

You can find me in various places with various levels of success. Your best bet is just to send me an email (send it to ben at this domain).