Skip to content

Instantly share code, notes, and snippets.

@pbostrom
Last active February 12, 2019 20:15
Show Gist options
  • Save pbostrom/ae616c4c456960fd0a935ec4d29c1ac8 to your computer and use it in GitHub Desktop.
Save pbostrom/ae616c4c456960fd0a935ec4d29c1ac8 to your computer and use it in GitHub Desktop.
Livepeer
Livepeer node

The only things needed to run a Livepeer broadcasting node is the livepeer binary and an Ethereum keystore with passphrase. Copy the keystore to ~/.lpData/keystore and start the node with:

$ livepeer -ethPassword "passphrase" -ethUrl ws://<mainnet RPC server>:8546 -rtmpAddr 0.0.0.0:1935 -httpAddr 0.0.0.0:8935

This will create an RTMP endpoint on port 1935, which will accept connections from live video streams. Additionally, an HLS endpoint on port 8935 is used for streaming transcoded video to connecting players. You will need to deposit funds into your Livepeer account to pay transcoding fees. Use the Livepeer explorer and MetaMask to make a deposit using the same Ethereum account as above: https://explorer.livepeer.org/accounts/<account address>/broadcasting. Once you have some funds you will need to configure the broadcasting node using the livepeer_cli command to set your maximum broadcasting fees and your desired transcoding resolutions. At this point you are ready to push a live video stream to your RTMP endpoint.

Livepeer player

Theoretically you could use any HLS streaming player to play your video, but you will need to obtain the name of your stream from either the output of the broadcasting node or by querying Ethereum logs. The Livepeer player has all of this functionality integrated so it's probably the simplest option. It's fairly simple to host the Livepeer player, just clone the livepeerjs repo and configure the player module:

$ cd livepeerjs/packages/player
$ vi .env.production
# edit the env file with values for
# REACT_APP_CONTROLLER_ADDRESS - obtain this value from the output of livepeer_cli config screen
# REACT_APP_STREAM_ROOT_URL - the external address of your HLS streaming endpoint, i.e. http://1.1.1.1:8935/stream
# REACT_APP_HTTP_PROVIDER - this is the HTTP interface of Ethereum mainnet RPC server
$ yarn build
$ yarn serve
CDN

To support scaling to many viewers it's best to use a CDN to deliver the live stream. AWS's CloudFront supports HLS delivery. You just need to configure a distribution that points to the external address of your HLS streaming endpoint. Important: make sure you update and rebuild the Livepeer player to point REACT_APP_STREAM_ROOT_URL at the CDN, i.e. https://d3444zm5bjgj0j.cloudfront.net/stream.

Issues

There is an issue in the implementation of the Livepeer player when it queries the Ethereum logs for jobs being broadcast by your Livepeer node. By default, the jobs query will look through the last 1000000 blocks. This is overkill, and any current livestream should be reasonably found in the last several thousand blocks. Using the original value will effectively DDOS your mainnet RPC node, because every viewer that initializes the player is going to make an eth_getLogs over 1000000 blocks.

Another issue with the player is that it does not appear to handle multiplexing multiple transcoded resolutions of the streaming video, it seems to only select the highest resolution stream. This apparently causes a problem on mobile, as the mobile browsers are unable to decode the video stream, failing with the error MediaError code 3 – "MEDIA_ERR_DECODE".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment