You can integrate your product to use the Video Streaming for unlimited video streaming and hosting services. In this guide, we’ll take you through the API and webhook operations involved in integrating with the Video Streaming.
Typically, your app presents users with an interface through which they can create and manage a stream. Each user action represents a request to an endpoint in the Video Streaming API and a webhook. The following diagram shows the typical high-level sequence of the operations grouped into stages:
You’ll need to have:
Use the post_streams_id method to create a stream object in the Video Streaming.
Sample request payload:
{
"stream": {
"name": "test_stream",
"pull": false,
"uri": null,
"active": false,
"transcoding_region": "ix1",
"auto_record": false,
"webrtc": false,
"dvr_enabled": false,
"cdn_id": 53949,
"projection": "regular"
}
}
Sample response payload:
{
"id": 320423,
"active": false
...
}
Use the post_broadcasts method to create a broadcast object.
Sample request payload:
{
"broadcast": {
"name": "test_broadcast",
"status": "pending",
"share_url": "",
"custom_iframe_url": "",
"show_dvr_after_finish": false,
"pending_message": "Please wait ...",
"ad_id": null,
"stream_ids": [320423]
...
}
}
Sample response payload:
{
"id": 192470,
"status": "pending",
"stream_ids": [320423],
...
}
Having received a successful response from your app, the user can now publish the stream. Use the patch_streams_id method to activate the stream.
Sample request payload:
{
"stream": {
"active": true
}
}
Sample response payload:
{
"id": 320423,
"active": true
...
}
The Video Streaming sends a webhook that contains "live": true to your subscribed endpoint.
Sample webhook payload:
{
"type": "stream",
"message": {
"stream": {
"id": 320423,
"live": true,
"recording": false
}
}
}
The user tests the broadcast at this stage.
Use the patch_broadcasts_id method to update the broadcast status to Live.
Sample request payload:
{
"broadcast": {
"status": "live"
}
}
Sample response payload:
{
"id": 192470,
"status": "live"
...
}
The Video Streaming sends a webhook that contains "status": live to your subscribed endpoint.
Sample webhook payload:
{
"type": "broadcast",
"message": {
"broadcast": {
"id": 192470,
"status": "live"
}
}
}
The user starts streaming at this stage. The broadcast is visible to the audience.
Use the put_streams_id_start_recording method to begin recording.
If the returned HTTP status code is 204, the request is successful.
The Video Streaming sends a webhook that contains "recording": true to your subscribed endpoint.
Sample webhook payload:
{
"type": "stream",
"message": {
"stream": {
"id": 320423,
"live": true,
"recording": true
}
}
}
The user stops streaming at this stage.
Use the put_streams_id_stop_recording method to stop recording
The response to this request contains information about the recorded video.
Sample response payload:
{
"id": 803111,
"name": "Stream Record: test_stream, 2022-06-03 13:25:16 +0000",
"recording_started_at": "2022-06-03T13:24:29.000Z",
"created_at": "2022-06-03T13:25:16.000Z",
...
}
The Video Streaming sends a webhook that contains "recording": false to your subscribed endpoint.
Sample webhook payload:
{
"type": "stream",
"message": {
"stream": {
"id": 320423,
"live": true,
"recording": false
}
}
}
The Video Streaming sends a webhook that contains "status": "pending" to your subscribed endpoint.
Sample webhook payload:
{
"type": "video",
"message": {
"video": {
"id": 803111,
"slug": "MTdaAbW7IzBsjgvy",
"name": "Stream Record: test_stream, 2022-06-03 13:25:16 +0000",
"duration": 48410,
"status": "pending",
...
}
}
}
Use the patch_broadcasts_id method to update the broadcast status to Finished.
Sample request payload:
{
"broadcast": {
"status": "finished"
}
}
Sample response payload:
{
"id": 192470,
"status": "finished"
...
}
The Video Streaming sends a webhook that contains "status": "finished" to your subscribed endpoint.
Sample webhook payload:
{
"type": "broadcast",
"message": {
"broadcast": {
"id": 192470,
"status": "finished"
}
}
}
Use the patch_streams_id method to deactivate the stream.
Sample request payload:
{
"stream": {
"active": false
}
}
Sample response payload:
{
"id": 320423,
"live": true,
"transcoded_qualities": ["360n", "480n", "720n"],
"transcoding_speed": 1.0,
"active": false,
"rtmp_play_url": [ "rtmp://pull-ix1.gvideo.co:1939/in/320423?4a5d279b6371c7bcc5ce47afb0f74637",
"rtmp://pull-ix1.gvideo.co:1939/out/58725_320423_360n?4a5d279b6371c7bcc5ce47afb0f74637?vhost=out",
"rtmp://pull-ix1.gvideo.co:1939/out/58725_320423_480n?4a5d279b6371c7bcc5ce47afb0f74637?vhost=out",
"rtmp://pull-ix1.gvideo.co:1939/out/58725_320423_720n?4a5d279b6371c7bcc5ce47afb0f74637?vhost=out"
],
"transcoding_enabled": true,
...
}
The Video Streaming sends a webhook that contains "live": false to your subscribed endpoint.
Sample webhook payload:
{
"type": "stream",
"message": {
"stream": {
"id": 320423,
"live": false,
"recording": false
}
}
}
Use the delete_broadcasts_id method to delete the broadcast.
If the returned HTTP status code is 204, the request is successful.
This indicates that one quality version of the video currently being processed is ready for the viewers to watch.
The Video Streaming sends a webhook that contains "status": "viewable" to your subscribed endpoint.
Sample webhook payload:
{
"type": "video",
"message": {
"video": {
"id"": 803111,
"slug": "MTdaAbW7IzBsjgvy",
"name": "Stream Record: test_stream, 2022-06-03 13:25:16 +0000",
"duration": 48410,
"status": "viewable",
"converted_videos": [
{
"name": "vod720n",
"status": "complete"
},
{
"name": "vod480n",
"status": "processing"
},
{
"name": "vod360n",
"status": "processing"
},
{
"name": "vod240n",
"status": "processing"
}
]
}
}
}
This indicates that all quality versions of the video are ready for viewers to watch.
The Video Streaming sends a webhook that contains "status": "ready" to your subscribed endpoint.
Sample webhook payload:
{
"type": "video",
"message": {
"video": {
"id": 803111,
"slug": "MTdaAbW7IzBsjgvy",
"name": "Stream Record: test_stream, 2022-06-03 13:25:16 +0000",
"duration": 48410,
"status": "ready",
"converted_videos": [
{
"name": "vod720n",
"status": "complete"
},
{
"name": "vod480n",
"status": "complete"
},
{
"name": "vod360n",
"status": "complete"
},
{
"name": "vod240n",
"status": "complete"
}
]
}
}
}
Use the get_api_videos_id method to retrieve detailed information about the video.
Sample response payload:
{
"id": 803111,
"name": "Stream Record: test_stream, 2022-06-03 13:25:16 +0000",
"client_id": 58725,
"duration": 48410,
"stream_id": 320423,
"recording_started_at": "2022-06-03T13:24:29.000Z",
"created_at": "2022-06-03T13:25:16.000Z",
"sprite": "https://s-ed1.cloud.gcore.lu/videoplatform/sprites/58725/803111_803111.mp4_sprite.jpg",
...
}
The user can reuse the same stream for each broadcast. In this case, you don’t need to create a new one. Just update the stream using the patch_streams_id method with the appropriate transcoding region.
Sample request payload:
{
"stream": {
"transcoding_region": dt1
}
}
Sample response payload:
{
"id": 320423,
"live": false,
"backup_live": false,
"transcoded_qualities": ["360n", "480n", "720n"],
"transcoding_speed": 1.0,
"push_url": "rtmp://vp-push-dt1.gvideo.co/in/320423?6460e735eda6b61bd4c99e02abf0c8df",
"backup_push_url": "rtmp://vp-push-ix1.gvideo.co/in/320423b?6460e735eda6b61bd4c99e02abf0c8df",
"push_url_srt": "srt://vp-push-dt1-srt.gvideo.co:5001?streamid=320423#6460e735eda6b61bd4c99e02abf0c8df",
"backup_push_url_srt": "srt://vp-push-ix2-srt.gvideo.co:5001?streamid=320423b#6460e735eda6b61bd4c99e02abf0c8df",
...
}
Sample webhook payload:
{
"type": "stream",
"message": {
"stream": {
"id": 320423,
"live": false,
"recording": false
}
}
}
Sample request payload:
{
"broadcast": {
"status": "paused"
}
}
Sample response payload:
{
"id": 192470,
"status": "paused",
...
}
The Video Streaming can’t currently reconnect without interrupting the recording if the stream gets temporary disruption. But we plan to implement this in the future.
You can delete streams that have been inactive for some time and are associated with a deleted user account. To do this, use the delete_api_videos_id method.
If the returned HTTP status code is 204, the request is successful.
Check out our Video Streaming API documentation for more methods that might come in handy for other use cases.
Was this article helpful?
Explore the Streaming Platform by Gcore