Live Stream and Recording

Use this guide to understand how to create & play a Live stream and to record the live stream using Videograph APIs.
1 Generate API Access token key pair Videograph uses token key pair that consists of Token ID and a secret key to authenticate API calls. You can generate a new access token in settings of your Videograph dashboard. API Access Tokens are specific to an environment. Make sure you select the right environment tin which you want to upload the video files. The access token should have Video Read and Write permissions.
2 Send POST request to Create Live Stream Videograph handles live streams in two different ways. As described below: Below is the POST API request you need to make for a successful Live Stream creation either with recording ‘true’ or ‘false’. Live stream with ‘recording’ parameter ‘true’ will push a record of the live stream. Here, the live stream is recorded as it being broadcasted which will allow you to create video clips from the available DVR of the live stream. Videograph stores the live stream recording for 12 hours from the start time of live stream after which it will expire. If you want the entire live stream to be available as an asset just create a video clip with EPCOH values of Live stream’s Start time and End time. Create Live stream with Recording ‘true’ : Note: Only the live stream recording is expired after 12 hours. Any video clips generated from the recording will be stored as an on-demand asset. You can access such video clips from ‘Videos’ menu in Videograph’s dashboard. All live streams with recording ’true’ can be accessed from ‘Live Recording’ menu in Videograph dashboard. Here, the live stream is directly published and is not recorded, which means you cannot create video clips from the live stream. The reason for implementing two different approaches for Live stream handling is to reduce the cost associated with processing and storing the live stream recordings. This way you can use the recording option only when it is required and therefore incur appropriate charges. Create Live stream with Recording ‘false’ : All live streams with recording ’false’ can be accessed from ‘Live Stream’ menu in Videograph dashboard.
curl --request POST \
     --url https://api.videograph.ai/video/services/api/v1/livestreams \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
     "title": "Live stream",
     "region": "us-east-1",
     "record": false
}
'
const sdk = require('api')('@videograph/v1.0#5hvd3ilcrhxps0');

sdk.postVideoServicesApiV1Livestreams({title: 'Live stream', region: 'us-east-1', record: false})
  .then(({ data }) => console.log(data))
  .catch(err => console.error(err));
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.videograph.ai/video/services/api/v1/livestreams', [
  'body' => '{"title":"Live stream","region":"us-east-1","record":false}',
  'headers' => [
    'accept' => 'application/json',
    'content-type' => 'application/json',
  ],
]);

echo $response->getBody();
import requests

url = "https://api.videograph.ai/video/services/api/v1/livestreams"

payload = {
    "title": "Live stream",
    "region": "us-east-1",
    "record": False
}
headers = {
    "accept": "application/json",
    "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"title\":\"Live stream\",\"region\":\"us-east-1\",\"record\":false}");
Request request = new Request.Builder()
  .url("https://api.videograph.ai/video/services/api/v1/livestreams")
  .post(body)
  .addHeader("accept", "application/json")
  .addHeader("content-type", "application/json")
  .build();

Response response = client.newCall(request).execute();
3 Start broadcasting live stream and record Videograph supports Live Stream using RTMP protocol, which is supported most broadcasting software and hardware as well as mobile apps. Videograph will provide a RTMP URL and streaming key after you create a live stream as described in the above step.
RTMP Server URLDescription
rtmp://rc-ingest.in.videograph.ai/recRTMP URL to push live streaming with recording parameter 'true' . Live stream will be recorded and available for 12 hours from the start time of live stream.
rtmp://ingest.in.videograph.ai/liveRTMP URL to push live streaming with recording parameter 'false' . Live streams will not be recorded.
You will need a client app or video software that can push RMTP stream. The RTMP server URL and stream key needs to configured in the video software as in shown below ex:OBS : 1. Start the live stream from your video software or client app. After RTMP configuration, you need to initiate the Live stream from two places to start streaming: 2. Start the live stream from Videograph dashboard. As shown below the default state of Live stream is ‘Idle’ unless you start the live stream from Videograph dashboard. After which the status will become ‘Active’ and the live player will start playing the stream. Note: If you have started the Live stream from Videograph dashboard but haven’t started it in your broadcast software then you will see a blank feed in the live player even though the live stream status is ‘active’. Make sure you have started the live stream in your broadcast software before you start the live stream from Videograph dashboard.
4 Play the live stream using Playback back URL Use the Playback HLS URL to play the live stream in your application. The playback back URL will be generated as soon as you a create live stream and you can retrieve the playback url by sending a GET request with unique ‘Stream_ID’ . Below is sample code of API response for GET request with Playback URL.
{
  "code": 200,
  "data": {
    "createdOn": 1673595417480,
    "metadata": [],
    "playbackUrl": "PLAYBACKURL",
    "rtmpUrl": "RTMP URL",
    "status": "Idle",
    "streamKey": "STREAMKEY",
    "streamUUID": "271dc169-da00-4f4e-bdc8-01c13f827eb9",
    "title": "live stream"
  },
  "message": "Livestream details with id: 271dc169-da00-4f4e-bdc8-01c13f827eb9",
  "status": "Success"
}