Ses bilgisi ayıklama özelliğini kullanarak ses örnekleme hızı, ses kanalı sayısı ve kapak resmi kullanılıp kullanılmadığı gibi medya meta verilerini bir ses dosyasından ayıklayabilirsiniz.
Ön koşullar
OSS paketiniz, Intelligent Media Management (IMM) projenizle ilişkilendirilmiş olmalıdır. OSS konsolunda veya OSS API kullanarak bir OSS paketini IMM projenizle ilişkilendirebilirsiniz.
OSS konsolunda bir IMM projesini bir OSS paketiyle nasıl ilişkilendireceğiniz hakkında daha fazla bilgi için Başlangıç kılavuzu konusundaki Adım 1: Bir OSS paketini bir IMM projesiyle ilişkilendirin bölümüne bakın.
Bir API işlemi çağırarak bir IMM projesini bir paketle nasıl ilişkilendireceğiniz hakkında daha fazla bilgi için AttachOSSBucket konusuna bakın.
Kullanım notları
Ses bilgisi ayıklama yalnızca eşzamanlı işleme (x-oss-process) destekler.
Anonim erişim desteklenmez.
IMM üzerinde gerekli İzinler sahip olmanız gerekir.
Parametreler
Eylem: audio/info
Ses bilgileri JSON biçiminde döndürülür.
Yanıt parametreleri hakkında daha fazla bilgi için DetectMediaMeta konusuna bakın.
RESTful API kullanın
FLAC dosyasının video bilgilerini sorgulayın
Örnek istek
// Extract audio information from the example FLAC file.
GET /exmaple.flac?x-oss-process=audio/info 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
Örnek yanıt
HTTP/1.1 200 OK
Server: AliyunOSS
Date: Wed, 25 May 2022 12:43:57 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 161
Connection: keep-alive
x-oss-request-id: 628E2481184E20F26C000009
x-oss-transfer-acc-type: acc-none
x-oss-data-location: oss-cn-hangzhou-a
ETag: "D0F162350DA037F4DC2A142B2E116BD0"
Last-Modified: Wed,
25 May 2022 12:20:34 GMT
x-oss-object-type: Normal
x-oss-hash-crc64ecma: 2040549661341440100
x-oss-storage-class: Standard
x-oss-server-time: 12437
{
"RequestId":"E63E1EFB-6D65-59DE-A11D-B0B761FDB301",
"Album":"Album",
"AlbumArtist":"Singer",
"Bitrate":973219,
"Duration":303.76,
"FormatLongName":"raw FLAC",
"FormatName":"flac",
"StreamCount":3,
"Title":"Song name"
"AudioStreams":
[
{
"ChannelLayout":"stereo",
"Channels":2,
"CodecLongName":"FLAC (Free Lossless Audio Codec)",
"CodecName":"flac","CodecTag":"0x0000",
"CodecTagString":"[0][0][0][0]",
"Duration":303.76,
"SampleFormat":"s16",
"SampleRate":"44100",
"TimeBase":"1/44100"
}
],
"VideoStreams":
[
{
"AverageFrameRate":"0/0",
"BitDepth":8,
"CodecLongName":"Motion JPEG",
"CodecName":"mjpeg",
"CodecTag":"0x0000",
"CodecTagString":"[0][0][0][0]",
"ColorRange":"pc",
"ColorSpace":"bt470bg",
"Duration":303.76,
"FrameRate":"90000/1",
"Height":800,
"Index":1,
"Level":-99,
"PixelFormat":"yuvj444p",
"Profile":"Progressive",
"Refs":1,
"TimeBase":"1/90000",
"Width":800
},
{
"AverageFrameRate":"0/0",
"BitDepth":8,
"CodecLongName":"Motion JPEG",
"CodecName":"mjpeg",
"CodecTag":"0x0000",
"CodecTagString":"[0][0][0][0]",
"ColorRange":"pc",
"ColorSpace":"bt470bg",
"Duration":303.76,
"FrameRate":"90000/1",
"Height":800,
"Index":2,
"Level":-99,
"PixelFormat":"yuvj444p",
"Profile":"Progressive",
"Refs":1,
"TimeBase":"1/90000",
"Width":800
}
]
}
OSS SDK'lerini kullanın
Aşağıdaki örnek kod, yaygın programlama dilleri için OSS SDK'lerini kullanarak ses bilgilerini nasıl ayıklayacağınıza ilişkin örnekler sunar. Diğer programlama dilleri için SDK'ler kullanarak ses bilgilerini ayıklamak istiyorsanız aşağıdaki örnek koda göre parametreleri değiştirin.
Java
Java için OSS SDK 3.17.4 veya sonraki bir sürümü gereklidir.
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.OSSObject;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyuncs.exceptions.ClientException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public class Demo {
public static void main(String[] args) throws ClientException, ClientException {
// Specify the endpoint of the region in which the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region ID of the bucket in which the bucket is stored. Example: cn-hangzhou.
String region = "cn-hangzhou";
// Obtain a credential from the environment variables. Before you run the 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 name of the bucket.
String bucketName = "examplebucket";
// If the audio file is stored in the root directory the bucket, specify the name of the audio file. If the audio file is not stored in the root directory of the bucket, you must specify the full path of the audio file. Example: exampledir/example.mp3.
String key = "example.mp3";
// Create an OSSClient instance.
// Call the shutdown method to release resources when the OSSClient is no longer in use.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Create an audio information extraction instruction.
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
getObjectRequest.setProcess("audio/info");
// Use the process parameter of the getObject method to pass the processing instruction.
OSSObject ossObject = ossClient.getObject(getObjectRequest);
// Read and display the audio information.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = ossObject.getObjectContent().read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
String audioInfo = baos.toString("UTF-8");
System.out.println("Audio Info:");
System.out.println(audioInfo);
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
} finally {
// Stop the OSSClient instance.
ossClient.shutdown();
}
}
}
PHP
PHP için OSS SDK 2.7.0 veya sonraki bir sürümü gereklidir.
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
try {
// Obtain a credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
$provider = new EnvironmentVariableCredentialsProvider();
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
$endpoint = 'https://oss-cn-hangzhou.aliyuncs.com';
// Specify the name of the bucket. Example: examplebucket.
$bucket = 'examplebucket';
// If the audio file is stored in the root directory the bucket, specify the name of the audio file. If the audio file is not stored in the root directory of the bucket, you must specify the full path of the audio file. Example: exampledir/example.mp3.
$key = 'example.mp3';
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
// Specify the ID of the Alibaba Cloud region in which the bucket is located.
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
// Create an audio information extraction instruction.
$options[$ossClient::OSS_PROCESS] = "audio/info";
$result = $ossClient->getObject($bucket,$key,$options);
var_dump($result);
} catch (OssException $e) {
printf($e->getMessage() . "\n");
return;
}
Python
Python için OSS SDK 2.18.4 veya sonraki bir sürümü gereklidir.
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain a credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the ID of the Alibaba Cloud region in which the bucket is located.
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
# If the audio file is stored in the root directory the bucket, specify the name of the audio file. If the audio file is not stored in the root directory of the bucket, you must specify the full path of the audio file. Example: exampledir/example.mp3.
key = 'example.mp3'
# Create an audio information extraction instruction.
process = 'audio/info'
try:
# Use the get_object method and pass the processing instruction by using the process parameter.
result = bucket.get_object(key, process=process)
# Read and display the audio information.
audio_info = result.read().decode('utf-8')
print("Audio Info:")
print(audio_info)
except oss2.exceptions.OssError as e:
print("Error:", e)
Go
Go için OSS SDK 3.0.2 veya sonraki bir sürümü gereklidir.
package main
import (
"fmt"
"io"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain a temporary credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Create an OSSClient instance.
// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify your actual endpoint.
// Specify the ID of the Alibaba Cloud region in which the bucket is located. 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 name of the bucket. Example: examplebucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// If the audio file is stored in the root directory the bucket, specify the name of the audio file. If the audio file is not stored in the root directory of the bucket, you must specify the full path of the audio file. Example: exampledir/example.mp3.
// Create an audio information extraction instruction by using the oss.Process method.
body, err := bucket.GetObject("example.mp3", oss.Process("audio/info"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
defer body.Close()
data, err := io.ReadAll(body)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Println("data:", string(data))
}