SDK Quickstart
This article explains how to use the Agora Go SDK to start cloud transcoding. The Go SDK helps developers integrate Agora's RESTful API more easily. It offers the following features:
- Simplified communication: The SDK encapsulates RESTful API requests and responses to simplify communication.
- Ensured availability: If DNS resolution fails, network errors occur, or requests time out, the SDK automatically switches to the optimal domain to ensure REST service availability.
- Easy-to-use API: The SDK provides a simple and intuitive API that makes it easy to perform common tasks such as creating and destroying cloud transcoding sessions.
- Additional benefits: Built with Go, the SDK offers efficiency, concurrency, and scalability.
Understand the tech
When you use the Go SDK for Cloud Transcoding:
- Call
Acquire()
to get a builder token for your transcoding task - Call
Create()
with your configuration to start transcoding specified streams - The service processes and publishes the transcoded streams to your target channels
- Viewers can subscribe to either original or transcoded streams
The following sections show you how to implement this workflow.
Prerequisites
Before you start, ensure that you have:
- Go 1.18 or higher
- Followed the Enable Cloud Transcoding guide to:
- Set up your Agora account and activate the Cloud Transcoding service
- Obtain your App ID from Agora Console
- Obtain your Customer ID and Customer Secret for REST API authentication
- Generate RTC tokens for your channels (valid for up to 24 hours)
- A way to test transcoding input streams:
- Implement the Video Calling Quickstart, or
- Use the Agora Web Demo to simulate audio and video streams
Set up your project
Follow these steps to create and configure a new project:
-
Create an empty project folder named
test-transcoder
. -
Navigate to the
test-transcoder
directory and initialize a Go module: -
Create a
main.go
file in the project directory for implementing your cloud transcoding task. -
Install the Go SDK:
-
Add the required imports to
main.go
:
Implement cloud transcoding
This section introduces the minimal workflow for cloud transcoding. For demonstration purposes, this example only transcodes the host's audio.
Define variables
In the main.go
, add the following code to define and configure the key parameters.
-
In this example, the stream from the host of the
show
channel is used as the input stream for the transcoder. To simplify parameter configuration, the transcoder's output stream is also published to the same channel. The input and output streams share the same token. -
For Cloud Transcoding, multiple input streams must come from the same channel, while the output can be one or more streams and may be assigned to any channel.
Create and initialize the client
In main.go
, add the following code to create and initialize the client.
Get cloud transcoding resources
Before creating a cloud transcoding task, call the Acquire
method to obtain a builder token tokenName
. A token can only be used for a single cloud transcoding task.
Start cloud transcoding
Call Create
to create a Cloud Transcoding task and start transcoding. In this example, the audio and video streams of two hosts in the same channel are mixed and combined.
Stop cloud transcoding
When the transcoding task is complete, call the Delete
method to end cloud transcoding:
Complete example code
The complete sample code for this example is presented here for your reference and use.
Complete sample code
Test your implementation
Follow these steps to test Cloud Transcoding:
-
In the project folder, run the Go project:
-
Check the console output for successful execution:
- Look for "acquire success" followed by a tokenName
- Look for "create success" followed by a taskId
- After 10 seconds, look for "delete success"
-
To test the transcoded audio output:
- Open the Agora Web Demo
- Join the same channel you configured
- You hear audio transcoded by your Go application
If you see error messages, check that your App ID, tokens, and credentials are correct.
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.
- Refer to the API documentation for complete parameter details.
- If you encounter any problems, refer to Troubleshooting.
Sample project
For more Cloud Transcoding examples, see the Sample project on GitHub.