视频截图是指对视频截取指定时间、指定尺寸的图片,用于生产视频封面、雪碧图、播放器进度条缩略图等场景,截图作业支持指定时间点、时间间隔、截图数量、类型以及是否拼图等。本文提供PHP SDK V2.0使用截图相关功能的API调用示例。
完整代码
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\SubmitSnapshotJobRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
class Sample {
/**
* 使用AK&SK初始化账号Client
* @return Mts Client
*/
public static function createClient(){
$config = new Config([
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
"accessKeyId" => getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
"accessKeySecret" => getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
]);
$config->endpoint = "mts.cn-hangzhou.aliyuncs.com";
return new Mts($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
$client = self::createClient();
$submitSnapshotJobRequest = new SubmitSnapshotJobRequest([
//作业输入
"input" => "{\"Bucket\":\"example-bucket\",\"Location\":\"example-location\",\"Object\":\"example%2Ftest.flv\"}",
//截图配置
"snapshotConfig" => "{\"OutputFile\":{\"Bucket\":\"example-001\",\"Location\":\"example-location\",\"Object\":\"{Count}.jpg\"},\"Time\":\"5\",\"Num\":\"10\",\"Interval\":\"20\"}",
//用户自定义数据
"userData" => "testid-001",
//管道ID
"pipelineId" => "dd3dae411e704030b921e52698e5****"
]);
$runtime = new RuntimeOptions([]);
try {
// 复制代码运行请自行打印 API 的返回值
$client->submitSnapshotJobWithOptions($submitSnapshotJobRequest, $runtime);
}
catch (Exception $error) {
if (!($error instanceof TeaError)) {
$error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
}
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
var_dump($error->message);
// 诊断地址
var_dump($error->data["Recommend"]);
Utils::assertAsString($error->message);
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main(array_slice($argv, 1));
相关文档
文档内容是否对您有帮助?