Audio Transcoding โ
This document is based on the official Tencent Cloud documentation Audio/Video Transcoding Integration and covers only the audio features.
Converts the input audio to a different encoding format, bitrate, and sample rate. It runs as an offline task and supports standard audio transcoding, TSC (Top Speed Codec) audio transcoding, and adaptive bitrate audio.
Supported Types โ
| Type | Description |
|---|---|
| Standard audio transcoding | Lowers the bitrate and changes the encoding standard, sample rate, and channels to suit the device and network environment |
| TSC audio transcoding | An upgrade over standard audio transcoding. Applies adaptive optimization based on the audio type to deliver a clearer listening experience at lower bandwidth |
| Adaptive bitrate audio | Converts the input audio into multiple bitrate streams that are selected based on the playback environment |
API Information โ
| Item | Value |
|---|---|
| Service | MPS |
| API Action | ProcessMedia |
| Endpoint | mps.tencentcloudapi.com |
| API version | 2019-06-12 |
| Processing method | Asynchronous (query the result after a TaskId is issued) |
For authentication, all API use the TC3-HMAC-SHA256 (SecretId/SecretKey) signature. For how to generate the signature, see the TokenHub document in Quick Start.
Request Parameters โ
| Parameter | Type | Required | Example | Description |
|---|---|---|---|---|
| InputInfo | Object | Required | {"Type":"URL","UrlInputInfo":{"Url":"https://example.com/audio.mp3"}} | Input media. Type is URL or COS |
| OutputStorage | Object | Required | {"Type":"COS","CosOutputStorage":{"Bucket":"mybucket-125xxx","Region":"ap-guangzhou"}} | Output storage. Specifies the COS Bucket and Region |
| OutputDir | String | Optional | /output/audio/ | Output directory. Must start with / and end with / |
| MediaProcessTask.TranscodeTaskSet.N.Definition | Integer | Required | 100800 | Transcoding template ID. Use an audio-specific template or a custom template |
| MediaProcessTask.TranscodeTaskSet.N.OverrideParameter.Container | String | Optional | m4a | Output container. For audio-only output, specify an audio container such as m4a |
| MediaProcessTask.TranscodeTaskSet.N.OverrideParameter.AudioTemplate.Codec | String | Optional | aac | Output audio codec |
| MediaProcessTask.TranscodeTaskSet.N.OverrideParameter.AudioTemplate.Bitrate | Integer | Optional | 64 | Output audio bitrate (kbps) |
| MediaProcessTask.TranscodeTaskSet.N.OverrideParameter.AudioTemplate.SampleRate | Integer | Optional | 44100 | Output sample rate (Hz) |
| MediaProcessTask.TranscodeTaskSet.N.OverrideParameter.AudioTemplate.AudioChannel | Integer | Optional | 2 | Number of output channels |
| TaskNotifyConfig.NotifyUrl | String | Optional | https://example.com/callback | Task completion callback URL. NotifyType is URL |
Silence Packet Padding โ
When audio frames are discontinuous or there is no silence at the end, silence packets can be padded. This is controlled by StdExtInfo's audio_info.enable_mute_audio value.
| Value | Behavior |
|---|---|
0 | Disabled (default value) |
1 | Pads silence packets when audio frames are discontinuous |
2 | In addition to behavior 1, also pads silence at the end |
"StdExtInfo" : "{\"audio_info\":{\"enable_mute_audio\":1}}"Call Example โ
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.mps.v20190612 import mps_client, models
cred = credential.Credential("<SecretId>", "<SecretKey>")
http_profile = HttpProfile
http_profile.endpoint = "mps.tencentcloudapi.com"
client = mps_client.MpsClient(cred, "ap-guangzhou", ClientProfile(httpProfile=http_profile))
params = {
"InputInfo": {
"Type": "URL",
"UrlInputInfo": {"Url": "https://example.com/audio.mp3"}
},
"OutputStorage": {
"Type": "COS",
"CosOutputStorage": {"Bucket": "mybucket-125xxx", "Region": "ap-guangzhou"}
},
"OutputDir": "/output/audio/",
"MediaProcessTask": {
"TranscodeTaskSet": [{
"Definition": 100800,
"OverrideParameter": {
"Container": "m4a",
"AudioTemplate": {
"Codec": "aac",
"Bitrate": 64,
"SampleRate": 44100,
"AudioChannel": 2
}
}
}]
}
}
req = models.ProcessMediaRequest
req.from_json_string(json.dumps(params))
resp = client.ProcessMedia(req)
print(resp.to_json_string)Response Example โ
{
"TaskId": "24000022-WorkflowTask-b20a8exxxxxxx1tt110253",
"RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
}Usage Notes โ
Audio transcoding is billed based on the output file duration. Rates differ by processing type, including standard transcoding, TSC transcoding, and audio-only transcoding.
You can query the result by entering the TaskId in DescribeTaskDetail API, or receive it through the completion callback.