Audio transcoding

Updated at:

This topic describes how to transcode audio using the media transcoding API of Intelligent Media Management (IMM).

Feature introduction

Audio transcoding converts an audio file from one format to another. This process improves file compatibility and can reduce the file size without a significant loss in audio quality.

image

Scenarios

  • Audio format compatibility: Different devices and players support different audio formats. You can use transcoding to ensure that audio files are playable on the target device.

  • Audio streaming: In live streaming or streaming media services, you can transcode audio to optimize transmission efficiency for different network conditions and user devices.

  • Audio compression: To save storage space or bandwidth, you can transcode audio files into more efficient or compressed formats, such as transcoding a WAV file to an MP3 or AAC format.

  • Parameter adjustment: You can adjust parameters such as the sample rate and the number of sound channels of the audio.

Supported audio and video formats

Category

Format

Audio

All mainstream formats, such as AAC, MP3, WAV, FLAC, WMA, AC3, and OPUS.

Video

All mainstream formats, such as MP4, MPEG-TS, MKV, MOV, AVI, FLV, M3U8, WebM, WMV, RM, and VOB.

How to use

Prerequisites

  • Create an AccessKey. For more information, see Create an AccessKey.

  • Activate Object Storage Service (OSS) and create a bucket. For more information, see Create a bucket.

  • Activate Intelligent Media Management (IMM). For more information, see Activate IMM.

  • Create a project in the IMM console. For more information, see Create a project.

    Note
    • You can also call an API operation to create a project. For more information, see Create a project.

    • You can call the ListProjects operation to list all projects that are created in a specified region.

Step 1: Upload a file

You can use the OSS console to upload the media file to a bucket in the same region as your IMM project.

image

Step 2: Use IMM for audio transcoding

You can call the CreateMediaConvertTask operation to create an audio transcoding task.

Parameter examples

The following examples show how to use the IMM project test-project to transcode audio.

For more information about the features and usage of ApsaraVideo Media Processing, see Media transcoding.

Note

You can process audio files using the media transcoding API operation in the OpenAPI Portal. For reference, see the SDK code.

Transcode audio to the AAC format

Transcoding information

  • Input file path: oss://test-bucket/video-demo/test.mp3

  • Encoding format: mp3 -> aac

  • Audio configuration: bitrate of 96 Kbps, two sound channels, sample rate of 44.1 kHz

  • Output audio path: oss://test-bucket/video-demo/test.aac

  • Transcoding completion notification: An MNS (Message Service) message is sent to the MNS topic "test-mns-topic".

For an SDK example, see OpenAPI Portal. The example parameters are automatically filled. You can modify the parameters as needed before you run the test.

The following request parameters are used

{
  "ProjectName": "test-project",
  "Notification": {
    "MNS": {
      "TopicName": "test-mns-topic"
    }
  },
  "Sources": [
    {
      "Subtitles": [],
      "URI": "oss://test-bucket/video-demo/test.mp3"
    }
  ],
  "Targets": [
    {
      "Audio": {
        "TranscodeAudio": {
          "Bitrate": 96000,
          "Channel": 2,
          "Codec": "aac",
          "SampleRate": 44100
        }
      },
      "Container": "aac",
      "URI": "oss://test-bucket/video-demo/test.{autoext}"
    }
  ]
}

Transcode audio to the MP3 format

Transcoding information

  • Input file: oss://test-bucket/video-demo/test.aac

  • Format: AAC to MP3

  • Audio configuration: A bitrate of 128 Kbps, two sound channels, and a sample rate of 44.1 kHz

  • Output file: oss://test-bucket/video-demo/test.mp3

  • Transcoding completion notification: An MNS message is sent to the MNS topic "test-mns-topic".

For an SDK example, see the OpenAPI Portal. The example parameters are automatically populated. You can modify them as needed before testing.

The following are the request parameters.

{
  "ProjectName": "test-project",
  "Notification": {
    "MNS": {
      "TopicName": "test-mns-topic"
    }
  },
  "Sources": [
    {
      "URI": "oss://test-bucket/video-demo/test.aac"
    }
  ],
  "Targets": [
    {
      "Audio": {
        "TranscodeAudio": {
          "Bitrate": 128000,
          "Channel": 2,
          "Codec": "mp3",
          "SampleRate": 44100
        }
      },
      "Container": "mp3",
      "URI": "oss://test-bucket/video-demo/test.{autoext}"
    }
  ]
}

Extract audio from a video

You can extract a single audio track from a video and save it as a separate audio file without changing the sample rate or the number of sound channels.

Transcoding information

  • Input file path: oss://test-bucket/video-demo/test.mp4

  • Audio configuration: A single audio stream is extracted from the video and converted to the AAC encoding format.

  • Output audio path: oss://test-bucket/video-demo/test-audio-%d.aac

  • Transcoding completion notification: An MNS message is sent to the MNS topic "test-mns-topic".

For an SDK example, see OpenAPI Portal. The example parameters are automatically filled. You can modify the parameters as needed before you run the test.

The following request parameters are used

{
  "ProjectName": "test-project",
  "Notification": {
    "MNS": {
      "TopicName": "test-mns-topic"
    }
  },
  "Sources": [
    {
      "URI": "oss://test-bucket/video-demo/test.mp4"
    }
  ],
  "Targets": [
    {
      "Audio": {
        "TranscodeAudio": {
          "Codec": "aac"
        }
      },
      "Container": "aac",
      "URI": "oss://test-bucket/video-demo/test-audio-{streamindex}.{autoext}"
    }
  ]
}

If the file contains multiple audio tracks that you want to extract, you can save each track as a separate audio file without changing the sample rate or the number of sound channels.

Transcoding information:

  • Input file path: oss://test-bucket/video-demo/test.mp4

  • Audio configuration: All audio streams are extracted from the video, converted to the AAC encoding format, and the bitrate is set to 256 Kbps.

  • Output audio path: oss://test-bucket/video-demo/test-audio-%d.aac

  • Transcoding completion notification: An MNS message is sent to the MNS topic "test-mns-topic".

For an SDK example, see OpenAPI Portal. The example parameters are automatically filled. You can modify the parameters as needed before you run the test.

The following request parameters are used:

{
  "ProjectName": "test-project",
  "Notification": {
    "MNS": {
      "TopicName": "test-mns-topic"
    }
  },
  "Sources": [
    {
      "URI": "oss://test-bucket/video-demo/test.mp4"
    }
  ],
  "Targets": [
    {
      "Audio": {
        "Stream": [
          101
        ],
        "TranscodeAudio": {
          "Bitrate": 256000,
          "Codec": "aac"
        }
      },
      "Container": "aac",
      "URI": "oss://test-bucket/video-demo/test-audio-{streamindex}.{autoext}"
    }
  ]
}