# Using Live Transcode with APIs

You can create and manage Live Transcode channels from your own application through the Fleet API. For example, you can open a channel before an event starts and delete it when the event ends.

TIP

Live Transcode API functions are enabled per service. To use them, contact support@inox.co.th with the Service ID you want enabled. Support only enables these functions for the service. You generate the API Key yourself.

# Enable the API for your backend application

  1. Sign in to ByteArk Fleet (https://fleet.byteark.com) (opens new window), select the service, and go to the Settings tab.
  2. In the API Key section, click Generate API Key.
  3. Use the Service ID and API Key in your API requests.

The API Key belongs to the service it was generated in. It only works with that Service ID, so each service needs its own key and its own Live Transcode enablement.

# Calling the API from a backend application

Send HTTP requests to the following URL pattern:

curl -XPOST https://fleet.byteark.com/api/:serviceId/:apiKey/:apiFunctionName -d [parameters]
1

Replace :serviceId and :apiKey with the values from the previous step, and choose an :apiFunctionName from the list below.

  • serviceId : Service ID of your ByteArk Fleet service.
  • apiKey : API Key generated for that service.
  • apiFunctionName : Function to call.
  • parameters : Parameters for the function, as key-value pairs.

A successful request returns status 200 with a JSON object that matches the function you called.

# API function names

  • createchannel: Create a new Live Transcode channel
  • listchannels: List opened Live Transcode channels
  • deletechannel: Delete an unused Live Transcode channel
  • dropchannelpublisher: Drop the inbound signal to the Live Transcode server
  • dropchanneltranscoder: Reset and restart the Live Transcoder

# API responses and parameters

# 1. Create a new Live Stream (createchannel)

curl -XPOST https://fleet.byteark.com/api/:serviceId/:apiKey/createchannel -d 'transcode[1080p]=1&transcode[720p]=1&transcode[480p]=1&streamname=teststream'
1

Create a new Live Stream channel. Choose the resolutions you need with these parameters.

  • Stream name (streamname)
  • The resolutions you need: transcode[1080p], transcode[720p], transcode[576p], transcode[480p], transcode[360p] and transcode[240p]. Set a parameter to 1 to enable that resolution. Enabled resolutions use an automatic bitrate.
  • Or a bitrate preset (preset) instead of transcode. See Bitrate presets below.

After you call this API, the service returns the status of the transcoder and an RTMP endpoint to publish to. Enter the returned streamendpoint and streamkey into your RTMP streaming software to start sending your stream to ByteArk. To watch the live stream, use the streamurl, which ends with index.m3u8.

{ "transcodelimit" :5,
"transcodeusage" :3,
"streamid" :450,
"streamname" :"testapi2",
"streamkey" :"t5bx-fwr7-mywm",
"streamsource" :"",
"streammode" :"PUSH",
"streamendpoint" :"rtmp:\/\/publish.fleet.byteark.com\/fleet",
"transcoder": {
   "1080p": { "enabled" :true, "bitrate" :"auto" },
   "720p": { "enabled" :true,  "bitrate" :"auto" },
   "576p": { "enabled" :false, "bitrate" :"auto" },
   "480p": { "enabled" :true,  "bitrate" :"auto" },
   "360p": { "enabled" :false, "bitrate" :"auto" },
   "240p": { "enabled" :false, "bitrate" :"auto" }
   },
"streamurl" :"https:\/\/teststream-gmwjpl.cdn.byteark.com\/fleetstream\/testapi2\/index.m3u8" }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# Bitrate presets

Instead of choosing resolutions one by one, you can pass preset to create the channel with a fixed set of resolutions, each at a constant bitrate.

curl -XPOST https://fleet.byteark.com/api/:serviceId/:apiKey/createchannel -d 'preset=live-event&streamname=teststream'
1

Available presets (bitrate in kbps):

Preset 1080p 720p 480p 360p 240p
live-event 7800 3500 1575 780 280

The live-event preset does not include 576p.

  • preset and transcode cannot be used together. Sending both returns status 400.
  • An unknown preset name returns status 400, and the error message lists the available presets.
  • In the response, transcoder shows the preset bitrate for each resolution instead of "auto", for example "1080p": { "enabled": true, "bitrate": 7800 }.

# 2. List opened Live Streams (listchannels)

curl -XPOST https://fleet.byteark.com/api/:serviceId/:apiKey/listchannels
1

List the opened live stream channels, with the transcode status and details of each channel.

  • transcodelimit : Maximum number of transcodes in your service.
  • transcodeusage : Number of transcodes in use.

Details are grouped by channel. Each channel contains the following data.

  • streamid : ID of the stream in Fleet Streaming
  • streamname : Stream name (set when the channel was created)
  • streamkey : Key of RTMP endpoint.
  • streammode : Streaming mode. "PUSH" means you publish the signal to the assigned RTMP endpoint. "PULL" means Fleet Streaming pulls RTMP from an endpoint you assigned.
  • streamendpoint : RTMP server endpoint.
  • streamurl : Live Stream URL for watching the stream.
  • transcoder: List of enabled resolution(s). Example: 1080p: {"enabled": true}

# 3. Delete Live Stream (deletechannel)

curl -XPOST https://fleet.byteark.com/api/:serviceId/:apiKey/deletechannel -d "streamname=[streamname]"
1

This API deletes your Live Stream channel once you are done with it. Call it with the stream name. After the request, the channel is deleted, its publish signal and transcode are dropped, and you can no longer use that stream.

# 4. Drop Live Stream Publisher (dropchannelpublisher)

curl -XPOST https://fleet.byteark.com/api/:serviceId/:apiKey/dropchannelpublisher -d "streamname=[streamname]"
1

Drop the signal being published to the RTMP server of the given stream name. The RTMP server then waits to receive a signal again.

Normally, use this function to reset the status when you detect a streaming error, such as a signal error or a status error.

A response with status=1 means the signal was dropped. If your publishing software is still running and still sending a signal to the RTMP server, the stream resumes. The result appears within 5-15 seconds.

# 5. Drop Live Transcoder (dropchanneltranscoder)

curl -XPOST https://fleet.byteark.com/api/:serviceId/:apiKey/dropchanneltranscoder -d "streamname=[streamname]"
1

This function disconnects the Live Transcoder so that it restarts. Call it with the streamname of the channel whose transcoder you want to restart. Admins normally use it to reset the transcoder when the input signal is invalid or incorrect.

A response with status=2 means the transcoder was restarted. If your publishing software is still running and still sending a signal to the RTMP server, the stream resumes. The result appears within 5-15 seconds.

# Limitation

The number of Live Transcodes that can be active at the same time within an account is limited (transcodelimit). To increase the limit, contact us at sales@byteark.com