Live stream over RTMP

RTMP, a streaming protocol supported by a majority of encoders, is supported by the VideoCoin Network. This guide describes creating a stream, sending data to the ingest, and observing the HLS output.

List available streaming profiles

Below is the endpoint to retrieve all existing output profiles. Determine which profile will best suit your desired output stream and note the id property:

$ curl -X GET https://console.videocoin.network/api/v1/profiles
{
"items": [
{
"id": "190b9d72-208d-4fa2-90b7-5b203c0025d2",
"name": "SD",
"description": "SD",
"is_enabled": true
},
{
"id": "45d5ef05-efef-4606-6fa3-48f42d3f0b96",
"name": "FullHD",
"description": "FullHD",
"is_enabled": true
},
{
"id": "e53e377f-2621-4ef1-8004-7d782e9608eb",
"name": "HD",
"description": "HD",
"is_enabled": true
}
]
}

Create the stream object

Create the stream and include the required name, input_type, output_type and profile_id values. profile_id is the value of the desired profile in the previous step. Note that this request requires authorization in the form of a Bearer token. See "API Authorization" for more:

$ curl -X POST -H 'Authorization: Bearer <TOKEN>' -H 'Content-Type: application/json' -d '{"name": "live", "input_type": "INPUT_TYPE_RTMP", "output_type": "OUTPUT_TYPE_HLS", "profile_id": "190b9d72-208d-4fa2-90b7-5b203c0025d2"}' https://console.videocoin.network/api/v1/streams
{
"id": "3f18785d-b757-4f18-77e2-36680043fff6",
"name": "live",
"output_url": "https://streams.videocoin.network/3f18785d-b757-4f18-77e2-36680043fff6/index.m3u8",
"stream_contract_id": "1959998627787229139",
"stream_contract_address": "",
"status": "STREAM_STATUS_NEW",
"input_status": "INPUT_STATUS_NONE",
"created_at": "2019-11-06T22:54:06.866402573Z",
"updated_at": "2019-11-06T22:54:06.866452401Z",
"ready_at": null,
"completed_at": null,
"rtmp_url": "rtmp://rtmp.console.videocoin.network:1935/live/3f18785d-b757-4f18-77e2-36680043fff6",
"input_type": "INPUT_TYPE_RTMP",
"output_type": "OUTPUT_TYPE_HLS"
}

Start preparation of the stream

Using the id value of the previous operation, begin running the stream to prepare its input and output destinations:

$ curl -X POST -H 'Authorization: Bearer <TOKEN>' https://console.videocoin.network/api/v1/streams/3f18785d-b757-4f18-77e2-36680043fff6/run

Sending video over RTMP to the stream's ingest

The stream is not yet ready to receive video until its status property is equal to STREAM_STATUS_PREPARED. For more about the various values of a stream's status property, see the "List of stream statuses (status)" section in the "Streams" page:

$ curl -X GET -H 'Authorization: Bearer <TOKEN>' https://console.videocoin.network/api/v1/streams/3f18785d-b757-4f18-77e2-36680043fff6
{
"id": "3f18785d-b757-4f18-77e2-36680043fff6",
"name": "live",
"output_url": "https://streams.videocoin.network/3f18785d-b757-4f18-77e2-36680043fff6/index.m3u8",
"stream_contract_id": "1959998627787229139",
"stream_contract_address": "0x548CEb2CD19Df313e2aA65c9301CBb9d264dBB8F",
"status": "STREAM_STATUS_PREPARED",
"input_status": "INPUT_STATUS_NONE",
"created_at": "2019-11-06T22:54:07Z",
"updated_at": "2019-11-06T22:54:15Z",
"ready_at": null,
"completed_at": null,
"rtmp_url": "rtmp://rtmp.console.videocoin.network:1935/live/3f18785d-b757-4f18-77e2-36680043fff6",
"input_type": "INPUT_TYPE_RTMP",
"output_type": "OUTPUT_TYPE_HLS"
}

The stream is now ready to receive video. Using the rtmp_url property of your stream, begin sending data to the stream with your encoder. Below uses ffmpeg as the encoder to accomplish this:

$ ffmpeg -re -f lavfi -i testsrc=rate=30 -c:v libx264 -b:v 1600k -preset ultrafast -b 900k -c:a libfdk_aac -b:a 128k -s 640x480 -x264opts keyint=60 -g 30 -pix_fmt yuv420p -f flv rtmp://rtmp.console.videocoin.network:1935/live/3f18785d-b757-4f18-77e2-36680043fff6

Using HLS output of stream

The HLS output is not ready for use until the stream's status property is equal to STREAM_STATUS_READY:

$ curl -X GET -H 'Authorization: Bearer <TOKEN>' https://console.videocoin.network/api/v1/streams/3f18785d-b757-4f18-77e2-36680043fff6
{
"id": "3f18785d-b757-4f18-77e2-36680043fff6",
"name": "live",
"output_url": "https://streams.videocoin.network/3f18785d-b757-4f18-77e2-36680043fff6/index.m3u8",
"stream_contract_id": "1959998627787229139",
"stream_contract_address": "0x548CEb2CD19Df313e2aA65c9301CBb9d264dBB8F",
"status": "STREAM_STATUS_READY",
"input_status": "INPUT_STATUS_ACTIVE",
"created_at": "2019-11-06T22:54:07Z",
"updated_at": "2019-11-06T22:54:15Z",
"ready_at": "2019-11-06T22:58:15Z",
"completed_at": null,
"rtmp_url": "rtmp://rtmp.console.videocoin.network:1935/live/3f18785d-b757-4f18-77e2-36680043fff6",
"input_type": "INPUT_TYPE_RTMP",
"output_type": "OUTPUT_TYPE_HLS"
}

Once the stream is in STREAM_STATUS_READY state, use the output_url property with any HLS-compatible video player to view your stream's output:

$ ffplay https://streams.videocoin.network/3f18785d-b757-4f18-77e2-36680043fff6/index.m3u8

Ending your stream

The stream will complete automatically if the encoder it is receiving data from has stopped. The stream can also be stopped manually as shown below:

$ curl -X POST -H 'Authorization: Bearer <TOKEN>' https://console.videocoin.network/api/v1/streams/3f18785d-b757-4f18-77e2-36680043fff6/stop