Skip to content

Instructions for building and operating your own platform for livestreaming. Uses Livepeer's open-source video infrastructure software.

License

Notifications You must be signed in to change notification settings

RUDE-labs/simple-streaming-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 

Repository files navigation

simple-streaming-server

Contents

Introduction

This page gives an introduction to simple-streaming-server.

The main objective is to help you install simple-streaming-server on a computer.

It will also help you to operate simple-streaming-server.

This repo is published under MIT License.

What is it, and what does it do??

simple-streaming-server is software to run on a computer or a server. It uses entirely open-source and freely available software, and makes extensive use of Livepeer's open-source video infrastructure software.

A simple-streaming-server can receive and serve streaming content. It can also be configured to transcode streaming content to improve accessibility.

The streaming content must be Video + Audio, and must be published into the simple-streaming-server in a linear stream.

This stream of content can be live (from camera and microphone) or recorded (from a disk).

image

It can receive streaming content published in RTMP format, from tools like OBS Studio, ManyCam, FFmpeg, or many other tools.

It can serve streaming content over http with a .m3u8 extension, for playback in tools like VLC Media Player, media-enabled Mobile browsers (Brave, Firefox or Chrome), embedded in an html page using a stream player such as hls.js, or inside a mobile application using something like ExoPlayer.

Minimum Setup

Here are instructions to setup a simple-streaming-server on a local computer. They will work on Mac or Linux (Ubuntu).

  1. Download the latest release of pre-compiled software from Livepeer's Release Page on Github, under where it says Assets:
  • On a Mac, download the livepeer-darwin-amd64.tar.gz file to the Downloads folder

  • On Linux (Ubuntu), download the livepeer-linux-amd64.tar.gz file

  1. Unzip the file:
  • On Mac, simply open the file, and it will extract to the folder containing the file (Downloads).

  • On Linux (Ubuntu), open the livepeer-darwin-amd64.tar.gz file then click "Extract", and extract it to "Home".

  1. Open Terminal, and navigate to the folder containing the livepeer binary:
  • On Mac, run cd Downloads/livepeer-darwin-amd64

  • On Linux (Ubuntu), run cd livepeer-linux-amd64

  1. Run ./livepeer -broadcaster

  2. Wait until the text Video Ingest Endpoint - rtmp://127.0.0.1:1935 is displayed.

simple-streaming-server is now running.

image

Next Steps

Now that simple-streaming-server is running, here are some further things you can do:

Publish and Consume Content

This section explains how to publish and consume content to and from simple-streaming-server.

This can be done via a command line interface using FFmpeg, or from a graphical user interface using OBS Studio and VLC Media Player.

Command Line Interface

This section explains how to publish and consume content to and from simple-streaming-server using a command line interface (CLI).

Install FFmpeg

Install FFmpeg on Linux (Ubuntu) using sudo apt install ffmpeg

Install FFmpeg on a Mac using instructions on FFmpeg's website.

Publish a test source

FFmpeg can be used to generate and publish a test source of content to simple-streaming-server:

  1. Make sure simple-streaming-server is running on localhost 127.0.0.1.

  2. Run the following command:

ffmpeg -re -f lavfi -i \
       testsrc=size=500x500:rate=30,format=yuv420p \
       -f lavfi -i sine -c:v libx264 -b:v 1000k \
       -x264-params keyint=60 -c:a aac -f flv \
       rtmp://127.0.0.1:1935/test_source
  • test_source is the "stream key" for this publication.
  • size=500x500 defines the dimensions of the test video source in pixels
  • rate=30 defines the frame rate of the test video in frames per second
  • 1000k defines the bitrate for the stream
  • keyint=60 defines the keyframe interval in frames
  1. See that simple-streaming-server is receiving a stream called test_source.

image

Publish a recorded video

FFmpeg can be used to publish recorded content to simple-streaming-server:

  1. Make sure simple-streaming-server is running on localhost 127.0.0.1.

  2. Run the following command:

ffmpeg \
        -re \
        -i video.mov \
        -codec copy \
        -f flv rtmp://127.0.0.1:1935/recorded_content
  • recorded_content is the "stream key" for this publication.
  1. See that simple-streaming-server is receiving a stream called recorded_content.

image

Consume content using ffplay

ffplay is part of FFmpeg, and can be used to request and playback content from simple-streaming-server.

  1. Make sure content is being published into simple-streaming-server.

  2. Run ffplay http://127.0.0.1:8935/stream/test_source.m3u8

  • test_source is the "stream key" used when publishing content to simple-streaming-server.
  1. See the content from the test_source stream being played back:

image

Inspect content metadata

curl is command line tool and library for transferring data with URLs, and can be used to inspect metadata of content published by simple-streaming-server.

  1. Make sure content is being published into simple-streaming-server.

  2. Run curl http://127.0.0.1:8935/stream/test_source.m3u8

  • test_source is the "stream key" used when publishing content to simple-streaming-server.
  1. View metadata about the stream(s) of content available for consumption, with .m3u8 extension(s):

image

  1. Run curl http://127.0.0.1:8935/stream/test_source/source.m3u8

  2. View metadata about the segment(s) of content available for consumption, with .ts extension(s):

image

Graphical User Interface

This section explains how to publish content to and consume content from simple-streaming-server using graphical user interfaces (GUIs).

Publish content using OBS Studio

OBS Studio can be used to configure and publish streaming content to simple-streaming-server:

  1. Download and install OBS Studio

  2. Launch OBS Studio, and decline to use the auto-configuration wizard.

image

  1. Go to Settings > Output

  2. Set "Output Mode" to "Advanced".

  3. Set the Streaming Keyframe interval to 2 seconds.

image

  1. Go to Settings > Stream

  2. Set "Service" to Custom

  3. Set "Server" to rtmp://127.0.0.1 and "Stream Key" to obs-studio

image

  1. Click OK to close "Settings".

  2. Under "Sources", click the + and select "Text" source.

  3. Add some text

image

  1. Make sure simple-streaming-server is running.

  2. Click "Start Streaming" (and also "Start Recording" if you also want to record the stream).

  3. See that simple-streaming-server is receiving a stream called obs-studio.

image

Learn about what other sources of content can be configured.

Consume content using VLC Media Player

VLC Media Player can be used to request and playback content from simple-streaming-server.

  1. Make sure content is being published into simple-streaming-server.

  2. Download and install VLC Media Player

  3. Launch VLC Media Player

  4. Select Media > Open Network Stream... (Ctrl-N)

  5. Enter http://127.0.0.1:8935/stream/obs-studio.m3u8 as the network URL

image

  1. Click "Play", and see the content from the obs-studio stream:

image

Configuring Content in OBS Studio

OBS Studio can be used to add video and audio content sources to be published to simple-streaming-server.

image

  • Configuring Video:
    • The big black box in the middle of the screen is the "canvas" for visual content.
    • One or more "Scenes" can be configured, which can be switched between when publishing
    • Zero or more "Sources" can be added to each "Scene", to
    • Examples of "Sources" are: static text, images, recorded videos, live videos (e.g. from a camera), screenshares, window shares.

Configuring Audio

  • Audio being published can be monitored in the "Mixer", both visually and audibly
  • Audio sources can be configured in Settings > Audio, and will appear in the "Mixer"
  • Examples of sources are sound cards, microphones and audio played by the computer.

Here is an example of a variety of different content sources configured in OBS Studio:

Screenshot from 2020-03-14 23-43-55

Hosted Setup

A simple-streaming-server can be deployed on a hosted server. For this It is assumed that this hosted server is running Linux (Ubuntu).

simple-streaming-server Access Options

It is necessary to configure simple-streaming-server appropriately, in order to allow required remote access to the server.

Local publish and consume only (no remote access)

When starting simple-streaming-server, run the following command:

./livepeer \ 
        -broadcaster \
        -rtmpAddr 127.0.0.1:1935 \
        -httpAddr 127.0.0.1:8935

Note: this command is technically equivalent to running the same command without -rtmpAddr or -httpAddr flags, as these are the default options. They are explicitly included here for illustrative purposes only.

simple-streaming-server will only allow content to be published and consumed on the hosted server itself:

publish consume
local yes yes
remote no no

Local publish, Remote consume

When starting simple-streaming-server, run the following command:

./livepeer \ 
        -broadcaster \
        -rtmpAddr 127.0.0.1:1935 \
        -httpAddr 0.0.0.0:8935

This will only allow content to be published from the hosted server itself but will allow content to be consumed locally or remotely, by any host with network access to the hosted server.

publish consume
local yes yes
remote no yes

Remote publish and consume (full remote access)

When starting simple-streaming-server, run the following command:

./livepeer \ 
        -broadcaster \
        -rtmpAddr 0.0.0.0:1935 \
        -httpAddr 0.0.0.0:8935

This will allow content to be published and / or consumed remotely, by any host with network access to the hosted server.

publish consume
local yes yes
remote yes yes

Note: when publishing or consuming content from a remote host, the server's IP address must be used instead of 127.0.0.1 Note: you may need to open ports 1935 and 8935 in your server's firewall configuration in order to allow internet access.

Architecture Summary

This section provides a high level summary of the logical and functional architecture of a simple-streaming-server.

image

Content can be published to simple-streaming-server via RTMP to port 1935.

Content can be consumed by requesting a URL with .m3u8 extension, via http from port 8935. simple-streaming-server will respond by serving a sequence of content segment files with .hs extensions over http, for playback.

The code for this software is available on Livepeer's go-livepeer repository.

Transcoding

simple-streaming-server can be configured to transcode the source content into different frame sizes and frame rates.

Transcoding allows content to be consumed by devices with less-performant network connections (bytes per second).

Local Transcoding

image

Transcoding can be performed on the same computer / server running the simple-streaming-server.

  1. Open a Terminal, and run the following command from the folder containing livepeer binary:
./livepeer \
        -broadcaster \
        -orchAddr 127.0.0.1:8936 \
        -transcodingOptions P144p30fps16x9,P240p30fps16x9 \
        -v 99
  • -orchAddr specifies the location of the Orchestrator / Transcoder service on the network
  • -transcodingOptions specifies frame sizes and frame rates to be transcoded into.
  • -v 99 is the highest level of logging output.
  1. Open another Terminal, and run the following command from the folder containing livepeer binary:
./livepeer \
        -orchestrator \
        -transcoder \
        -serviceAddr 127.0.0.1:8936 \
        -cliAddr 127.0.0.1:7936 \
        -v 99
  • -orchestrator and -transcoder tell the software to run in Orchestrator and Transcoder modes
  • -serviceAddr specifies the IP address and port that this service should run on the network
  • -v 99 is the highest level of logging output.

simple-streaming-server is now running with Local Transcoding enabled.

  1. Inspect the content metadata to see the additional streams available for consumption:

image

Note: many players of streaming content will dynamically switch between available streams in order to optimise the quality of playback given the available bandwidth.

Local Distributed Transcoding

Screenshot from 2020-04-30 16-58-19

Transcoding activities can also be distributed across an Orchestrator, and one or more Transcoders.

  1. Open a Terminal, and run the following command from the folder containing livepeer binary:
./livepeer \
        -broadcaster \
        -orchAddr 127.0.0.1:8936 \
        -transcodingOptions P144p30fps16x9,P240p30fps16x9 \
        -v 99
  1. Open another Terminal, and run the following command from the folder containing livepeer binary:
./livepeer \
        -orchestrator \
        -orchSecret pineapple \
        -serviceAddr 127.0.0.1:8936 \
        -cliAddr 127.0.0.1:7936 \
        -v 99
  • -orchSecret is a way for this Orchestrator to allow Transcoders to authenticate
  1. Open another Terminal, and run the following command from the folder containing livepeer binary:
./livepeer \
        -transcoder \
        -orchSecret pineapple \
        -orchAddr 127.0.0.1:8936 \
        -v 99

simple-streaming-server is now running with (Local) Distributed Transcoding enabled.

Remote Transcoding

Transcoding can also be performed on a different computer / server from the simple-streaming-server.

For this you will need two hosts (computers / servers):

  • For the simple-streaming-server
    • This host will need to be able to connect to port 8936 on the host of the remote transcoder.
  • For the remote transcoder
  1. Open a Terminal on the remote transcoder host, and run the following command:
./livepeer \
        -broadcaster \
        -orchAddr 192.168.2.113:8936 \
        -transcodingOptions P144p30fps16x9,P240p30fps16x9 \
        -v 99
  • 192.168.2.113 is the IP address of the remote transcoder host
  1. Open a Terminal on the simple-streaming-server host, and run the following command:
./livepeer \
        -orchestrator \
        -transcoder \
        -serviceAddr 192.168.2.113:8936 \
        -cliAddr 127.0.0.1:7936 \
        -v 99
  • 192.168.2.113 is the IP address of the remote transcoder host

simple-streaming-server is now running with Remote Transcoding enabled.

Outsourced Transcoding (requires payment in Ethereum)

Transcoding services can be purchased directly from individual Orchestrators operating in Livepeer's public Transcoding Marketplace.

Services are provide on a pay-as-you-go basis using Ethereum, without any minimum contractual obligation.

  1. Install geth, which is client software to run Ethereum, released by Ethereum Foundation.
  • This client software can be used to sync Ethereum blockchain, and to broadcast transactions to be included in the blockchain.
  1. Open a Terminal and run the following command to run geth client
geth -rpc -rpcapi eth,net,web3 --syncmode "light"
  1. Wait until geth has imported all new block headers, and has started downloading 1 block at a time:

image

  1. Open another Terminal and run the following command:
./livepeer \
        -broadcaster \
        -network mainnet \
        -transcodingOptions P144p30fps16x9,P240p30fps16x9 \
        -ethUrl http://127.0.0.1:8545 \
        -pixelsPerUnit 1 \
        -maxPricePerUnit 1 \
        -v 99
  • mainnet signifies Ethereum's main network
  • -ethUrl is the network location of the geth service.
  • -pixelsPerUnit and -maxPricePerUnit are for setting the maximum price to be paid for Transcoding
  1. Enter a Passphrase twice:

image

Note: no characters will appear in the window when typing the passphrase.

The Passphrase will be used to encrypt the Private Key generated by this process. The Private Key will be used to sign transactions for publishing on Ethereum.

  1. Enter the Passphrase again to start the simple-streaming-server.

  2. Wait until the text CLI server listening on 127.0.0.1:7935 is displayed in the console:

image

  1. Open a Terminal, and run the following command from the folder containing livepeer_cli binary:
./livepeer_cli
  1. Send some ETH from your wallet to the ETH Account listed under NODE STATS.

  2. In livepeer_cli, run option 12. Invoke "deposit broadcasting funds" (ETH)

image

This command will deposit some ETH into a smart contract in Livepeer's protocol, which can be spent on Transcoding services.

  1. Enter the amount of ETH you would like to deposit into the contract.

  2. Enter the amount of ETH you would like to keep in reserve in the contract, and press return.

simple-streaming-server is now running with Outsourced Transcoding on Livepeer, with payment on Ethereum.

You can now stream content into simple-streaming-server, and observe that your content is being transcoded into different formats.

Further details on setting the maximum price to be paid for Transcoding can be found in Livepeer's Broadcaster documentation.

To find out more about Livepeer, go to this 10-minute primer.

Start on system boot

This section explains how to configure simple-streaming-server to start when the underlying system starts.

The instructions use systemd on Linux (Ubuntu), and require root / sudo access.

simple-streaming-server.service

  1. Ensure the simple-streaming-server has been downloaded and installed on the underlying system

  2. Run the following commands to fetch a simple-streaming-server.service file from /etc/systemd/system folder

cd /etc/systemd/system
sudo wget https://raw.githubusercontent.com/videoDAC/simple-streaming-server/master/systemd/simple-streaming-server.service
  1. Run the following commands to enable and start simple-streaming-server.service:
sudo systemctl enable simple-streaming-server.service
sudo systemctl start simple-streaming-server.service

simple-streaming-server is now running.

  1. Run the following command to tail the logs:
sudo journalctl -f --unit=simple-streaming-server.service

Note: by default, the simple-streaming-server will only accept inbound rtmp content and serve outbound http content from and to localhost (127.0.0.1). To open ports to remote hosts, change the corresponding configuration to 0.0.0.0 and run sudo systemctl daemon-reload, then sudo systemctl restart simple-streaming-server.service.

publish-test-source.service

  1. Ensure the FFmpeg has been downloaded and installed on the underlying system

  2. Run the following commands to fetch a publish-test-source.service file from /etc/systemd/system folder

cd /etc/systemd/system
sudo wget https://raw.githubusercontent.com/videoDAC/simple-streaming-server/master/systemd/publish-test-source.service
  1. Run the following commands to enable and start simple-streaming-server.service:
sudo systemctl enable publish-test-source.service
sudo systemctl start publish-test-source.service

a test source is now being published into simple-streaming-server

  1. Run the following command to tail the logs:
sudo journalctl -f --unit=publish-test-source.service
  1. Run curl http://0.0.0.0:8935/stream/hello_consumer.m3u8 to see
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=4000000,RESOLUTION=1000x1000
hello_consumer/source.m3u8

local-transcoding.service

  1. Ensure the simple-streaming-server has been downloaded and installed on the underlying system

  2. Run the following commands to fetch a simple-streaming-server.service file from /etc/systemd/system folder

cd /etc/systemd/system
sudo wget https://raw.githubusercontent.com/videoDAC/simple-streaming-server/master/systemd/local-transcoding.service
  1. Run the following commands to enable and start local-transcoding.service:
sudo systemctl enable local-transcoding.service
sudo systemctl start local-transcoding.service

simple-streaming-server is now running with local transcoding service.

  1. Run the following command to tail the logs:
sudo journalctl -f --unit=local-transcoding.service
  1. Ensure publish-test-source.service is running, then run curl http://0.0.0.0:8935/stream/hello_consumer.m3u8 to see
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=4000000,RESOLUTION=1000x1000
hello_consumer/source.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=400000,RESOLUTION=256x144
hello_consumer/P144p30fps16x9.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=600000,RESOLUTION=426x240
hello_consumer/P240p30fps16x9.m3u8

geth-light.service

  1. Ensure the geth binary is in /home/ubuntu/ethereum

  2. Run the following commands to fetch a geth-light.service file, from /etc/systemd/system folder

cd /etc/systemd/system
sudo wget https://raw.githubusercontent.com/videoDAC/simple-streaming-server/master/systemd/geth-light.service
  1. Run the following commands to enable and start geth-light.service:
sudo systemctl enable geth-light.service
sudo systemctl start geth-light.service

geth-light is now running, allowing simple-streaming-server to connect to Ethereum.

  1. Run the following command to tail the logs:
sudo journalctl -f --unit=geth-light.service

Roadmap

This section describes additional features to be defined as part of this guide.

HTTPS Content Serving

This section will describe how to configure simple-streaming-server to serve content as https instead of http.

This is necessary for content to be served to webpages which themselves are served via https.

  • Install nginx
  • Configure nginx
  • Generate and install a cert
  • Test the installation

Web Player

This section will describe how to deploy a web-based streaming content player.

It will describe the code to be embedded into a webpage.

It will also describe how to deploy a webpage hosted on IPFS, with name resolution using ENS. An example of such a page is http://criticaltv.videodac.eth.link

Server-side Paywall

This section will describe how to install and configure Orchid's open-source software to prevent simple-streaming-server from serving content unless the consumer is paying for the content in OXT.

image

GPU Transcoding

This section will describe how to configure the -transcoder process to use a GPU for Transcoding.

Content Distribution Network

This section will describe how to configure a commercial Content Distribution Network (CDN), such as Amazon CloudFront, Cloudflare or Akamai. This is required in order to be able to serve content to large numbers of viewers simultaneously.

IP Address Whitelisting

This section will explain how to configure simple-streaming-server to only allow publishing and consuming from specific whitelisted IP addresses.

Raspberry Pi

This section will seek to add instructions for running simple-streaming-server on a Raspberry Pi.

About

Instructions for building and operating your own platform for livestreaming. Uses Livepeer's open-source video infrastructure software.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published