Get Stream Stats
How to get stream online status, duration, bitrate, codec and more
Overview
The stream statistic can help you monitor if there's any anomaly during the streaming session and troubleshoot the problems that occurred. LiveAPI provides the GET /v2/live_streams/{id}/stats
endpoint to help you easily grab the stream's stats in real-time.
How to get stream stats
You can call the GET /v2/live_streams/{id}/stats
endpoint to get the stats of your stream in real-time.
Sample request:
curl --location --request GET 'https://api.castr.com/v2/live_streams/620e0d57427ff4ddd764515f/stats' \
--header 'Content-Type: application/json;charset=UTF-8' \
--header 'Authorization: {your_authentication}'
Sample response:
For further info, you can refer to GET /v2/live_streams/{id}/stats
.
{
"bitrate": 2118,
"published_from": "42.116.183.239",
"last_dts": 1646710659445.3,
"online_clients":1,
"running": true,
"start_running_at": 1646710572201,
"lifetime": 86973.333251953,
"input_bitrate": 2118,
"id": "6226cf2c-3262-4413-b4e1-e41635feb981",
"out_bandwidth": 6546,
"published_via": "rtmp",
"push_stats": {
"rtmp://a.rtmp.youtube.com/live2/debs-4ux2-r565-1sv4-68zh": {
"sent_bytes": 23343452,
"status": "running"
}
},
"source_id": "6226cf2b-db4e-4f23-8056-dbbc0b598149",
"output_bitrate": 2118,
"bytes_out": 49337319,
"bytes_in": 24716859,
"retry_count": 0,
"media_info": {
"tracks": [
{
"track_id": "a1",
"codec": "aac",
"content": "audio",
"channels": 2,
"sample_rate": 48000,
"bitrate": 162
},
{
"bframes": 0,
"sar_height": 1,
"pixel_height": 720,
"fps": 30,
"track_id": "v1",
"bitrate": 1956,
"profile": "Baseline",
"height": 720,
"width": 1280,
"sar_width": 1,
"content": "video",
"gop_size": 23,
"codec": "h264",
"pixel_width": 1280,
"level": "3.1",
"pix_fmt": "yuv420p",
"last_gop": 25
}
]
},
"alive": true,
"opened_at": 1646710572201,
"ts_delay": 869,
"url": "publish://",
"last_access_at": 1646710572201
}
No stats returned when stream offline
You should only call the endpoint when your stream's status is online, otherwise, it'll return an error.
Sample response when getting the stats of an offline stream:
{
"statusCode": 404,
"error": "Not Found",
"message": "Stream not found in upstreams."
}
Updated 6 months ago