wiki:org/meetings/2015SummerDevMeeting/LiveStreamingOnion

Introduction

Overview

We are going to realize a live video stream through .onion

  • publishing through .onion (RTMP, avconv)
  • viewing through .onion (HLS, VLC)

Technical specs

The live stream will be encoded with 320x180 pixels, 12fps, 1 audio channel, 32kbit audio bitrate, constant rate factor = 30. This results in a video stream bitrate of ~150kbit/s. It will be encapsulated into MPEG TS and served per HTTP as HLS (HTTP Live Streaming) -Format.

Streaming with nginx-rtmp

Since nginx-rtmp has all we need, let's do it.

Setting up nginx-rtmp

First, compile nginx with nginx-rtmp plugin on Your tor hidden service machine and install. Getting started with nginx rtmp

Then, add a rtmp-section (from document root) and modify Your /usr/local/nginx/conf/nginx.conf as this:

rtmp {
      server {
                listen 127.0.0.1:1935 so_keepalive=on;
                ping 30s;
                ping_timeout 10s;
                meta on;
                # interleave on;
                max_streams 1024;
                chunk_size 4096;
                # notify_method get;
                wait_key on;
                wait_video on;
                drop_idle_publisher 5s;
                publish_notify on;
                play_restart on;

                application hls {
                        live on;
                        hls on;
                        hls_path /var/www/html;
                        hls_fragment 5s;
                }
        }
}

You should modify http section of nginx.conf as follow. "sendfile=off" is important for refreshing http video. Add Your own parameters or the default ones.

http {
        sendfile off;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
}

Now setup Your http live streaming - hidden service in /etc/nginx/sites-enabled/default

server {
        listen 127.0.0.1:80;
        location / {
                root /var/www/html;
                types {
                        application/vnd.apple.mpegurl m3u8;
                        video/mp2t ts;
                }
                add_header Cache-Control no-cache;
        }
}

That's pretty much it. Restart Your nginx and

netstat -tupel | grep 1935

to see if it accepts incoming connections on localhost:1935.

Setting up torrc

Enable Your hidden service in torrc through

HiddenServiceDir /var/lib/tor/hiddenservice
HiddenServicePort 80 127.0.0.1:80
HiddenServicePort 1935 127.0.0.1:1935

Restart tor. Now, the nginx-rtmp should listen for incoming rtmp connections from .onion

Playing around

The backend is configured and You can now publish and play live streams to and from Your hidden service.

Publishing Livestreams

Let's say, Your .onion domain is secrettv09n08949.onion and You want to publish a local rtp stream to remote Tor hidden service.

On Your local machine (not the HS machine) issue the command

torsocks avconv -y -i rtp://239.255.0.50:5004 -vcodec libx264 -acodec aac -r 12 -ac 1 -ab 32k -s 320x180 -strict experimental -profile:v baseline -level 30 -crf 30 -f flv rtmp://secrettv09n08949.onion/hls/mytv

Receiving the stream with VLC

Now that the stream is being published, go to VLC and modify the SOCKS settings (in Preferences) to match Your torsocks and issue the command

vlc -vvv http://secrettv09n08949.onion/mytv.m3u8

That's it, folks

Last modified 2 years ago Last modified on Oct 6, 2015, 5:22:55 PM