Todos los productos
Search
Centro de documentos

Object Storage Service:Procesamiento asíncrono con OSS SDK for PHP 2.0

Última actualización: Sep 22, 2026

El procesamiento asíncrono permite que un programa siga ejecutando otras tareas sin esperar a que finalice la tarea actual. Use el parámetro x-oss-async-process para procesar datos de forma asíncrona en Object Storage Service (OSS).

Nota de uso

  • En el código de ejemplo de este tema se usa el identificador de la región China (Hangzhou) (cn-hangzhou) y el endpoint público. Si necesita acceder a OSS desde otros servicios de Alibaba Cloud ubicados en la misma región, use el endpoint interno. Para conocer la correspondencia entre las regiones y los endpoints de OSS, consulte Regions and endpoints.

Código de ejemplo

A continuación se muestra un código de ejemplo que convierte un documento a un formato específico:

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the required arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// Specify the style used to process the video and convert it to the specified format.
$style = "video/convert,f_avi,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1";

// Construct an asynchronous processing instruction that contains the Base64-encoded bucket and object names.
$process = sprintf(
    "%s|sys/saveas,b_%s,o_%s",
    $style,
    rtrim(base64_encode($bucket), '='), // The Base64-encoded bucket name. Remove the equal sign (=) at the end. 
    rtrim(base64_encode($key), '=')     // The Base64-encoded object name. Remove the equal sign (=) at the end.
);

// Create a request object for asynchronous processing.
$request = new Oss\Models\AsyncProcessObjectRequest(
    bucket: $bucket, // The name of the bucket.
    key: $key         // The name of the object.
);

// Specify the processing instruction.
$request->process = $process;

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request); 

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Escenarios comunes

Transcodificación de video

La transcodificación de video modifica el formato de codificación de un archivo. Este proceso reduce el tamaño del archivo al ajustar parámetros como la resolución y la tasa de bits, además de convertir el formato del contenedor.

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the required arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// Specify the name of the transcoded video.
$targetObject = "dest.avi";

// Specify a processing style to specify the format, video codec, resolution, bit rate, frame rate, audio codec, and audio bit rate.
$style = "video/convert,f_avi,vcodec_h265,s_1920x1080,vb_2000000,fps_30,acodec_aac,ab_100000,sn_1";

// Construct an asynchronous processing instruction that contains the processing style and the Base64-encoded bucket and object names.
$process = sprintf(
    "%s|sys/saveas,b_%s,o_%s",
    $style,
    rtrim(base64_encode($bucketName), '='), // The Base64-encoded bucket name. Remove the equal sign (=) at the end.
    rtrim(base64_encode($targetObject), '=') // The Base64-encoded object name. Remove the equal sign (=) at the end.
);

// Create a request object for asynchronous processing.
$request = new Oss\Models\AsyncProcessObjectRequest(
    bucket: $bucketName, // The name of the bucket.
    key: $objectName,    // The name of the object.
    asyncProcess: $process // The asynchronous processing instruction.
);

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request);

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Conversión de video a imagen animada

Esta conversión transforma un video en imágenes animadas con formato GIF o WebP.

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the required arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line parameters
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// Specify the name of the animated GIF image.
$targetKey = "destexample.gif";

// Configure parameters for converting the video to a GIF image, including parameters used to specify the width, height, and frame interval.
$animationStyle = "video/animation,f_gif,w_100,h_100,inter_1000";

// Construct an asynchronous processing instruction that contains the storage path and the Base64-encoded bucket and object names.
$bucketNameEncoded = base64_encode($bucketName); // The Base64-encoded bucket name.
$targetKeyEncoded = base64_encode($targetKey);   // The Base64-encoded object name.
$process = sprintf(
    "%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0",
    $animationStyle,
    $bucketNameEncoded,
    $targetKeyEncoded
);

// Create a request object for asynchronous processing.
$request = new Oss\Models\AsyncProcessObjectRequest(
    bucket: $bucketName,      // The name of the bucket.
    key: $objectName,         // The name of the object.
    asyncProcess: $process    // The asynchronous processing instruction.
);

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request);

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Conversión de video a sprite

Este proceso extrae fotogramas de un video y genera sprites con base en reglas específicas.

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the required arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// Specify the name of the output sprite.
$targetKey = "example.jpg";

// Configure parameters for converting the video to a sprite, including parameters used to specify the format, width, height, and frame interval.
$animationStyle = "video/sprite,f_jpg,sw_100,sh_100,inter_10000,tw_10,th_10,pad_0,margin_0";

// Construct an asynchronous processing instruction that contains the storage path and the Base64-encoded bucket and object names.
$bucketNameEncoded = base64_encode($bucketName); // The Base64-encoded bucket name.
$targetKeyEncoded = base64_encode($targetKey);   // The Base64-encoded object name.
$process = sprintf(
    "%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0",
    $animationStyle,
    $bucketNameEncoded,
    $targetKeyEncoded
);

// Create a request object for asynchronous processing.
$request = new Oss\Models\AsyncProcessObjectRequest(
    bucket: $bucketName,      // The name of the bucket.
    key: $objectName,         // The name of the object.
    asyncProcess: $process    // The asynchronous processing instruction.
);

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request);

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Captura de fotogramas de video

La captura de fotogramas extrae imágenes de un video según reglas definidas y las convierte a un formato específico.

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the required arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// Specify the name of the captured frame.
$targetKey = "dest.png";

// Configure parameters for capturing video frames, including parameters used to specify the format, width, height, crop method, frame interval.
$animationStyle = "video/snapshots,f_jpg,w_100,h_100,scaletype_crop,inter_10000";

// Construct an asynchronous processing instruction that contains the storage path and the Base64-encoded bucket and object names.
$bucketNameEncoded = base64_encode($bucketName); // The Base64-encoded bucket name.
$targetKeyEncoded = base64_encode($targetKey);   // The Base64-encoded object name.
$process = sprintf(
    "%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0",
    $animationStyle,
    $bucketNameEncoded,
    $targetKeyEncoded
);

// Create a request object for asynchronous processing.
$request = new Oss\Models\AsyncProcessObjectRequest(
    bucket: $bucketName,      // The name of the bucket.
    key: $objectName,         // The name of the object.
    asyncProcess: $process    // The asynchronous processing instruction.
);

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request);

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Fusión de videos

La fusión de videos combina varios archivos de video en uno solo con un formato determinado.

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the required arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// Specify the name of the merged video.
$targetObject = "dest.mp4";

// Specify the name of the video to be merged.
$video1 = "concat1.mp4";
$video2 = "concat2.mp4";

// Create a style string and configure parameters for video merging.
$style = sprintf(
    "video/concat,ss_0,f_mp4,vcodec_h264,fps_25,vb_1000000,acodec_aac,ab_96000,ar_48000,ac_2,align_1/pre,o_%s/sur,o_%s,t_0",
    rtrim(base64_encode($video1), '='), // The Base64-encoded name of the first video. Remove the equal sign (=) at the end.
    rtrim(base64_encode($video2), '=')  // The Base64-encoded name of the second video. Remove the equal sign (=) at the end.
);

// Constrcut an asynchronous processing instruction.
$process = sprintf(
    "%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0",
    $style,
    rtrim(base64_encode($bucketName), '='),   // The Base64-encoded bucket name. Remove the equal sign (=) at the end.
    rtrim(base64_encode($targetObject), '=')  // The Base64-encoded object name. Remove the equal sign (=) at the end.
);

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request);

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Transcodificación de audio

La transcodificación de audio convierte archivos de sonido a un formato específico.

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the require arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// Specify the name of the transcoded audio file.
$targetKey = "dest.aac";

// Create a style string and configure parameters for audio transcoding.
$animationStyle = "audio/convert,ss_10000,t_60000,f_aac,ab_96000";

// Construct an asynchronous processing instruction that contains the storage path and the Base64-encoded bucket and object names.
$bucketNameEncoded = base64_encode($bucketName); // The Base64-encoded bucket name.
$targetKeyEncoded = base64_encode($targetKey);   // The Base64-encoded object name.
$process = sprintf(
    "%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0",
    $animationStyle,
    $bucketNameEncoded,
    $targetKeyEncoded
);

// Create a request object for asynchronous processing.
$request = new Oss\Models\AsyncProcessObjectRequest(
    bucket: $bucketName,      // The name of the bucket.
    key: $objectName,         // The name of the object.
    asyncProcess: $process    // The asynchronous processing instruction.
);

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request);

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Fusión de audio

La fusión de audio une varios archivos de sonido en un único archivo con un formato determinado.

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the required arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Define the global variables.
$region = ''; // The region where the bucket is located.
$bucketName = ''; // The name of the bucket.

// Parse command line arguments.
$options = getopt('', ['region:', 'bucket:']);

// Check whether the region is specified.
if (empty($options['region'])) {
    echo "Error: invalid parameters, region required\n";
    exit(1);
}

// Check whether the bucket name is specified.
if (empty($options['bucket'])) {
    echo "Error: invalid parameters, bucket name required\n";
    exit(1);
}

// Obtain the values of the command line arguments.
$region = $options['region'];
$bucketName = $options['bucket'];

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// The names of the audio files to be merged.
$audio1 = "src1.mp3";
$audio2 = "src2.mp3";

// Specify the name of the merged audio file.
$targetAudio = "dest.aac";

// Create a style string and configure parameters for audio merging.
$audio1Encoded = base64_encode($audio1); // The Base64-encoded name of the first audio file.
$audio2Encoded = base64_encode($audio2); // The Base64-encoded name of the second audio file.
$style = sprintf(
    "audio/concat,f_aac,ac_1,ar_44100,ab_96000,align_2/pre,o_%s/pre,o_%s,t_0",
    $audio1Encoded,
    $audio2Encoded
);

// Construct an asynchronous processing instruction that contains the storage path and the Base64-encoded bucket and object names.
$bucketEncoded = base64_encode($bucketName); // The Base64-encoded bucket name.
$targetEncoded = base64_encode($targetAudio); // The Base64-encoded object name.
$process = sprintf(
    "%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0",
    $style,
    $bucketEncoded,
    $targetEncoded
);

// Create a request object for asynchronous processing
$request = new Oss\Models\AsyncProcessObjectRequest(
    bucket: $bucketName,      // The name of the bucket.
    asyncProcess: $process    // The asynchronous processing instruction.
);

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request);

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Decodificación de marca de agua invisible

El siguiente código de ejemplo decodifica una marca de agua invisible a partir de una imagen:

<?php

// Import the autoload file to load dependencies.
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Specify the descriptions of command line arguments.
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // (Required) The region where the bucket is located.
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // (Optional) The endpoint that other services can use to access OSS.
    "bucket" => ['help' => 'The name of the bucket', 'required' => True], // (Required) The name of the bucket.
    "key" => ['help' => 'The name of the object', 'required' => True], // (Required) The name of the object.
];

// Generate a long options list to parse the command line arguments.
$longopts = \array_map(function ($key) {
    return "$key:"; // Add a colon (:) to the end of each argument to specify that a value is required.
}, array_keys($optsdesc));

// Parse command line arguments.
$options = getopt("", $longopts);

// Check whether the required arguments are configured.
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help"; // Prompt that the required arguments are not configured.
        exit(1);
    }
}

// Obtain the values of the command line arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
$key = $options["key"];       // The name of the object.

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Specify the endpoint if provided.
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;

// Define the global variables.
$region = ''; // The region where the bucket is located.
$bucketName = ''; // The name of the bucket.

// Parse the command line arguments.
$options = getopt('', ['region:', 'bucket:']);

// Check whether the region is specified.
if (empty($options['region'])) {
    echo "Error: invalid parameters, region required\n";
    exit(1);
}

// Check whether the bucket name is specified.
if (empty($options['bucket'])) {
    echo "Error: invalid parameters, bucket name required\n";
    exit(1);
}

// Obtain the values of the command line arguments.
$region = $options['region'];
$bucketName = $options['bucket'];

// Use environment variables to load the AccessKey ID and AccessKey secret.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Use the default configurations of the SDK.
$cfg = Oss\Config::loadDefault();

// Specify the credential provider.
$cfg->setCredentialsProvider($credentialsProvider);

// Specify the region.
$cfg->setRegion($region);

// Create an OSSClient instance.
$client = new Oss\Client($cfg);

// Specify the name of the watermarked image.
$sourceKey = $objectName; // Specify the name of the image object to be processed.

// Specify the Simple Message Queue (SMQ, formerly MNS) topic.
$topic = "imm-blindwatermark-test";

// Extract the watermark from the specified image.
$style = "image/deblindwatermark,s_low,t_text";
$encodedTopic = rtrim(base64_encode($topic), '='); // The Base64-encoded topic name. Remove the equal sign (=) at the end.
$process = sprintf(
    "%s|sys/notify,topic_%s",
    $style,
    $encodedTopic
);

// Create a request object for asynchronous processing.
$request = new Oss\Models\AsyncProcessObjectRequest(
    bucket: $bucketName,      // The name of the bucket.
    key: $sourceKey,          // Specify the name of the image to be processed.
    asyncProcess: $process    // The asynchronous processing instruction.
);

// Call the asyncProcessObject method to asynchronously process the object.
$result = $client->asyncProcessObject($request);

// Display the returned result.
printf(
    'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code.
    'request id:' . $result->requestId . PHP_EOL .   // The ID of the request.
    'async process result:' . var_export($result, true) . PHP_EOL // The result of asynchronous processing.
);

Referencias