nginx

Twitch streaming using two machines WITHOUT a capture card!

Twitch streaming using two machines WITHOUT a capture card!

The goal of this process is to take load off your CPU on your gaming machine and improve your stream quality.

Machine 1, The gaming PC.

Machine 2, A Linux (Ubuntu in this guide) box.

The gaming PC will be configured to capture and encode at a high bit-rate (20,000k) then transfer the footage to the Linux box that will re-encode it at 3500k and stream it to Twitch.

Linux set-up

Install Ubuntu Server 14.04.1 LTS ( http://www.ubuntu.com/download/server )

Download and compile Nginx with the RTMP module.

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev git libav-tools
git clone https://github.com/arut/nginx-rtmp-module.git
wget http://nginx.org/download/nginx-1.7.4.tar.gz
cd nginx-1.7.4
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make
sudo make install

Set Nginx to start on boot by creating an upstart file…

sudo nano /etc/init/nginx.conf

Paste the following in to this new file… (Thanks Georg0yo, I had to amend the start on line thou)

# nginx
description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]
env DAEMON=/usr/local/nginx/sbin/nginx
env PID=/var/run/nginx.pid
expect fork
respawn
respawn limit 10 5
#oom never
pre-start script
    $DAEMON -t
    if [ $? -ne 0 ]
        then exit $?
    fi
end script
exec $DAEMON

Configure Nginx

sudo nano /usr/local/nginx/conf/nginx.conf

Add this to the BOTTOM of the file…

rtmp {
    server {
        listen 1935; 
        chunk_size 4096;
        application transcode {
            live on;
            record off;
            exec avconv -i rtmp://localhost:1935/transcode/test -c:v libx264 -profile:v main -preset faster -cbr_quality 10 -re -crf 23 -r 30 -g 60 -b:v 3500k -maxrate 3500k -minrate 3500k -bufsize 7000k -acodec copy -vf crop=1920:1080:0:0 -af "volume=10dB" -f flv rtmp://localhost:1935/live/test;
        }
        application live {
            live on;
            record off;
            push rtmp://live-lhr.twitch.tv/app/YOUR_TWITCH_STREAM_KEY;
        }
    }
}

Start Nginx

sudo initctl start nginx

Gaming PC set-up

Install XSplit broadcaster or OBS. I use XSplit since it allows me to hardware encode using my Avermedia capture card but both will support Nvidia encoding and OBS supports Intel quick sync.

Set-up a custom RTMP stream using the following details…

Stream URL : rtmp://YOUR_SERVERS_IP_ADDRESS:1935/transcode
Stream Key : test
Change the stream bit rate to 20,000k and the encoder to anything but x264 (Nvidia Encoder, Intel Quick sync or Avermedia)

Now when you broadcast from your gaming PC it will send the high bit-rate stream to the server, encode it using x264 then stream it to Twitch.

Breakdown of the “avconv” settings…

-i rtmp://localhost:1935/transcode/test

The input stream

-c:v libx264

Use the x264 encoder

-profile:v main

Use the “main” profile

-preset faster

Use the “faster” preset, other options are veryfast, fast, medium, slow…

-cbr_quality 10
-re
-crf 23

These 3 options are advised elsewhere, research and change if needed

-r 30

The frame rate to capture at

-g 60

Key interval setting, for twitch keep this at frame rate * 2

-b:v 3500k
-maxrate 3500k
-minrate 3500k

Bit-rate to encode video at.

-bufsize 7000k

Buffer size should be bit-rate * 2

-acodec copy

Copy the audio codec format used on the input stream for the output stream

-vf crop=1920:1080:0:0

I have to set this since the Avermedia card outputs at 1920×1088

-af "volume=10dB"

Boost the audio by 10dB’s, feel free to disable

-f flv rtmp://localhost:1935/live/test;

The output stream. I could of just streamed right to Twitch from avconv but I did it this way so I could record the encoded stream to disk. (See the RTMP Nginx module document for record options).

You should now hopefully be streaming with less overhead vs x264 on your gaming PC.

Sources and credits…

https://obsproject.com/forum/threads/guide-two-pc-configuration-without-capturecard.6757/

Since ffmpeg is no longer supported in the latest versions of Ubuntu I made this to show how it can be done with avconv.