Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Audio transcoding

Son Güncelleme:Oct 01, 2026

Ses kod dönüştürme, ses dosyalarını istediğiniz biçimlere dönüştürmenizi sağlar. Bu konuda ses kod dönüştürme için kullanılan parametreler açıklanır ve örnekler sunulur.

Kullanım senaryoları

  • Çeşitli oynatma cihazlarıyla uyumluluğu sağlamak amacıyla müzik dosyası biçimlerini dönüştürün.

  • MP3 gibi yüksek oranda sıkıştırılmış kayıplı biçimlere dönüştürerek büyük boyutlu kayıpsız ses dosyaları için depolama alanını optimize edin.

  • Düşük bant genişliğine sahip bağlantılarda kesintisiz oynatma sağlamak üzere sesi farklı bit hızlarına dönüştürerek çevrimiçi akış hizmetlerinin çeşitli ağ koşullarına uyum sağlamasına olanak tanıyın.

  • Proje gereksinimlerine veya dağıtım standartlarına uygun hale getirmek amacıyla video prodüksiyonu ve post-prodüksiyon işlemleri için ses varlıklarını hazırlayın.

Kullanım notları

  • Ses kod dönüştürme yalnızca eşzamansız işlemeyi destekler ve x-oss-async-process yöntemiyle çağrılır.

  • Ses kod dönüştürmeyi kullanmadan önce bir Intelligent Media Management (IMM) projesini bir OSS paket ile ilişkilendirmeniz gerekir. Daha fazla bilgi için bkz. Hızlı başlangıç ve AttachOSSBucket.

  • Anonim erişim reddedilir.

  • Özelliği kullanmak için gerekli izinlere sahip olmanız gerekir. Daha fazla bilgi için bkz. izinler.

  • Varsayılan örnekleme hızı veya ses kanalı sayısı hedef kapsayıcı biçimiyle uyumsuzsa kod dönüştürme başarısız olabilir.

  • Ses kod dönüştürme için örnekleme bit derinliğini yalnızca flac biçimi için ayarlayabilirsiniz. Video kod dönüştürme için bit derinliğini OSS x-oss-process eyleminin pixfmt parametresini kullanarak ayarlayabilirsiniz. Daha fazla bilgi için bkz. Video kod dönüştürme.

Parametreler

Eylem: audio/convert

Aşağıdaki tabloda parametreler açıklanmaktadır.

Parametre

Tür

Zorunlu

Açıklama

ss

int

Hayır

Kod dönüştürmenin milisaniye cinsinden başlangıç zamanı. Geçerli değerler:

  • 0 (varsayılan): Kod dönüştürme ses dosyasının başından başlar.

  • 0'dan büyük bir değer: Kod dönüştürme ss. milisaniyeden başlar.

t

int

Hayır

Milisaniye cinsinden kod dönüştürme süresi. Geçerli değerler:

  • 0 (varsayılan): Kod dönüştürme ses dosyasının sonuna kadar devam eder.

  • 0'dan büyük bir değer: Kod dönüştürme t milisaniye boyunca devam eder.

f

string

Evet

Çıkış kapsayıcı biçimi. Geçerli değerler:

  • mp3

  • aac

  • flac

  • oga

  • ac3

  • opus

  • amr

ar

int

Hayır

Çıkış ses örnekleme hızı. Varsayılan olarak kaynak sesin örnekleme hızı kullanılır. Geçerli değerler:

  • 8000

  • 11025

  • 12000

  • 16000

  • 22050

  • 24000

  • 32000

  • 44100

  • 48000

  • 64000

  • 88200

  • 96000

Not

Desteklenen örnekleme hızları biçime göre değişir. MP3, 48 kHz'e kadar örnekleme hızlarını destekler. Opus 8 kHz, 12 kHz, 16 kHz, 24 kHz ve 48 kHz'yi destekler. AC3 32 kHz, 44,1 kHz ve 48 kHz'yi destekler. AMR yalnızca 8 kHz ve 16 kHz'yi destekler.

ac

int

Hayır

Çıkış ses kanalı sayısı. Varsayılan olarak kaynak sesteki kanal sayısı kullanılır. Değer aralığı: 1 ila 8.

Not

Desteklenen ses kanalı sayısı biçime göre değişir. MP3 yalnızca mono ve stereo desteği sunar. AC3 6 kanala (5.1) kadar destekler. AMR yalnızca mono desteği sunar.

aq

int

Hayır

Ses kalitesi. Bu parametre ab parametresi ile birlikte kullanılamaz. Değer aralığı: 0 ila 100.

ab

int

Hayır

Bit/saniye (bps) cinsinden ses bit hızı. Bu parametre aq parametresi ile birlikte kullanılamaz. Değer aralığı: 1.000 ila 10.000.000.

abopt

string

Hayır

Ses bit hızı seçeneği. Geçerli değerler:

  • 0 (varsayılan): Hedef ses bit hızı her zaman kullanılır.

  • 1: Kaynak ses bit hızı ab ile belirtilen hedef bit hızından düşükse kaynak ses bit hızı kullanılır.

  • 2: Kaynak ses bit hızı ab ile belirtilen hedef bit hızından düşükse kod dönüştürme işi başarısız olur.

adepth

int

Hayır

Çıkış sesinin örnekleme bit derinliği. Geçerli değerler: 16 ve 24.

Not

Bu parametre yalnızca f değeri flac olarak ayarlandığında geçerlidir.

Not

sys/saveas ve notify parametreleri de ses kod dönüştürme için kullanılır. Daha fazla bilgi için bkz. sys/saveas ve Bildirimler.

REST API kullanma

MP3'ü AAC'ye dönüştürme

İş yapılandırması

  • Kapsayıcı biçimi: mp3'ten aac'ye

  • Kaynak dosya: example.mp3

  • Kod dönüştürme süresi: 10.000. milisaniyeden başlayarak 60.000 milisaniye.

  • Ses ayarları: Orijinal örnekleme hızını ve ses kanalı sayısını koruyun ve ses bit hızını 96 Kbps olarak ayarlayın.

  • Tamamlanma bildirimi: MNS kullanarak bir mesaj gönderin.

Örnek istek

// Transcode the audio file named example.mp3.
POST /example.mp3?x-oss-async-process HTTP/1.1
Host: video-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
 
x-oss-async-process=audio/convert,ss_10000,t_60000,f_aac,ab_96000|sys/saveas,b_b3V0YnVja2V0,o_b3V0b2JqcHJlZml4LnthdXRvZXh0fQo/notify,topic_QXVkaW9Db252ZXJ0

WAV'ı Opus'a dönüştürme

İş yapılandırması

  • Kapsayıcı biçimi: wav'den opus'a

  • Kod dönüştürme süresi: Tüm ses dosyası.

  • Ses ayarları: 48 kHz örnekleme hızı, iki kanal ve 96 Kbps ses bit hızı.

  • Çıkış yolu: oss://outbucket/outobject.opus

  • Tamamlanma bildirimi: MNS kullanarak bir mesaj gönderin.

Örnek istek

// Transcode the audio file named example.wav.
POST /example.wav?x-oss-async-process HTTP/1.1
Host: video-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
 
x-oss-async-process=audio/convert,f_opus,ab_96000,ar_48000,ac_2|sys/saveas,b_b3V0YnVja2V0, o_b3V0b2JqLnthdXRvZXh0fQo/notify,topic_QXVkaW9Db252ZXJ0

SDK'ları kullanma

Eşzamansız ses kod dönüştürme gerçekleştirmek için Java, Python ve Go SDK'larını kullanabilirsiniz.

Java

SDK for Java 3.17.4 veya sonraki bir sürüm gerektirir.

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.AsyncProcessObjectRequest;
import com.aliyun.oss.model.AsyncProcessObjectResult;
import com.aliyuncs.exceptions.ClientException;

import java.util.Base64;

public class Demo {
    public static void main(String[] args) throws ClientException {
        // yourEndpoint: The endpoint of the region where your bucket is located.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // The region ID for the endpoint, for example, cn-hangzhou.
        String region = "cn-hangzhou";
        // Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the bucket name.
        String bucketName = "examplebucket";
        // Specify the transcoded audio file.
        String targetKey = "dest.aac";
        // Specify the source audio file.
        String sourceKey = "src.mp3";

        // Create an OSSClient instance.
        // When the OSSClient instance is no longer used, call the shutdown method to release resources.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(region)
                .build();

        try {
            // Build the audio processing style string and audio transcoding parameters.
            String style = String.format("audio/convert,ss_10000,t_60000,f_aac,ab_96000");
            // Build the asynchronous processing instruction.
            String bucketEncoded = Base64.getUrlEncoder().withoutPadding().encodeToString(bucketName.getBytes());
            String targetEncoded = Base64.getUrlEncoder().withoutPadding().encodeToString(targetKey.getBytes());
            String process = String.format("%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0", style, bucketEncoded, targetEncoded);
            // Create an AsyncProcessObjectRequest object.
            AsyncProcessObjectRequest request = new AsyncProcessObjectRequest(bucketName, sourceKey, process);
            // Execute the asynchronous processing task.
            AsyncProcessObjectResult response = ossClient.asyncProcessObject(request);
            System.out.println("EventId: " + response.getEventId());
            System.out.println("RequestId: " + response.getRequestId());
            System.out.println("TaskId: " + response.getTaskId());

        } finally {
            // Shut down the OSSClient.
            ossClient.shutdown();
        }
    }
}

Python

SDK for Python 2.18.4 veya sonraki bir sürüm gerektirir.

# -*- coding: utf-8 -*-
import base64
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

def main():
    # Obtain access credentials from environment variables. Before you run this sample code, make sure that the environment variables are configured.
    auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
    # The endpoint of the region where the bucket is located. For example, for China (Hangzhou), use https://oss-cn-hangzhou.aliyuncs.com.
    endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'

    # Specify the bucket name, for example, examplebucket.
    bucket = oss2.Bucket(auth, endpoint, 'examplebucket')

    # Specify the name of the source audio file.
    source_key = 'src.mp3'

    # Specify the name of the transcoded audio file.
    target_key = 'dest.aac'

    # Build the audio processing style string and audio transcoding parameters.
    audio_style = 'audio/convert,ss_10000,t_60000,f_aac,ab_96000'

    # Build the processing instruction, including the save path and the Base64-encoded bucket name and target object name.
    bucket_name_encoded = base64.urlsafe_b64encode('examplebucket'.encode()).decode().rstrip('=')
    target_key_encoded = base64.urlsafe_b64encode(target_key.encode()).decode().rstrip('=')
    process = f"{audio_style}|sys/saveas,b_{bucket_name_encoded},o_{target_key_encoded}/notify,topic_QXVkaW9Db252ZXJ0"

    try:
        # Execute the asynchronous processing task.
        result = bucket.async_process_object(source_key, process)
        print(f"EventId: {result.event_id}")
        print(f"RequestId: {result.request_id}")
        print(f"TaskId: {result.task_id}")
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()

Go

SDK for Go 3.0.2 veya sonraki bir sürüm gerektirir.

package main

import (
	"encoding/base64"
	"fmt"
	"log"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Obtain temporary access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET, and OSS_SESSION_TOKEN environment variables are configured.
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Create an OSSClient instance.
	// yourEndpoint: The endpoint of the region where your bucket is located. For example, for China (Hangzhou), use https://oss-cn-hangzhou.aliyuncs.com. Set this parameter based on the actual region.
	// yourRegion: The region ID, for example, cn-hangzhou.
	client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Specify the bucket name, for example, examplebucket.
	bucketName := "examplebucket"

	bucket, err := client.Bucket(bucketName)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Specify the name of the source audio file.
	sourceKey := "src.mp3"
	// Specify the name of the transcoded audio file.
	targetKey := "dest.aac"

	// Build the audio processing style string and audio transcoding parameters.
	audioStyle := "audio/convert,ss_10000,t_60000,f_aac,ab_96000"

	// Build the processing instruction, including the save path and the Base64-encoded bucket name and target object name.
	bucketNameEncoded := base64.URLEncoding.EncodeToString([]byte(bucketName))
	targetKeyEncoded := base64.URLEncoding.EncodeToString([]byte(targetKey))
	process := fmt.Sprintf("%s|sys/saveas,b_%v,o_%v/notify,topic_QXVkaW9Db252ZXJ0", audioStyle, bucketNameEncoded, targetKeyEncoded)

	// Execute the asynchronous processing task.
	result, err := bucket.AsyncProcessObject(sourceKey, process)
	if err != nil {
		log.Fatalf("Failed to async process object: %s", err)
	}

	fmt.Printf("EventId: %s\n", result.EventId)
	fmt.Printf("RequestId: %s\n", result.RequestId)
	fmt.Printf("TaskId: %s\n", result.TaskId)
}