视频截图是指对视频截取指定时间、指定尺寸的图片,用于生产视频封面、雪碧图、播放器进度条缩略图等场景,截图作业支持指定时间点、时间间隔、截图数量、类型以及是否拼图等。您可以通过媒体处理控制台、API或SDK提交截图作业。本文提供了媒体处理PHP SDK截图模块相关功能的API调用示例。
前提条件
提交截图作业
调用SubmitSnapshotJob提交截图作业,接口参数和返回字段详细信息请参见提交截图作业,调用示例如下:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use AlibabaCloud\Darabonba\Env\Env;
use AlibabaCloud\Tea\Tea;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Console\Console;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\SubmitSnapshotJobRequest;
class Sample {
private $pipelineId = "<PipelineId>";
private $templateId = "S00000001-100020"; #转码模板ID,按需配置
private $ossLocation = "<OssLocation>";
private $bucket = "<bucket name>";
private $oss_input_object = "input.mp4";
private $oss_output_object = "output_{Count}.jpg";
/**
* @param string $accessKeyId
* @param string $accessKeySecret
* @param string $regionId
* @return Mts
* 正式环境下 建议 protocol = "HTTPS";
*/
public static function createClient($accessKeyId, $accessKeySecret, $regionId){
$config = new Config([]);
$config->accessKeyId = $accessKeyId;
$config->accessKeySecret = $accessKeySecret;
$config->regionId = $regionId;
$config->protocol = "HTTP";
return new Mts($config);
}
/**
* @return void
*/
public static function main(){
$sample = new Sample;
$client = self::createClient(Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_ID"), Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), 'cn-shanghai');
$request = new SubmitSnapshotJobRequest([
"input" => json_encode(array(
'Location' => $sample->ossLocation,
'Bucket' => $sample->bucket,
'Object' => urlencode($sample->oss_input_object))
),
"snapshotConfig" => $sample->snapshotConfig(),
"pipelineId" => $sample->pipelineId,
]);
$response = $client->submitSnapshotJob($request);
Console::log(Utils::toJSONString(Tea::merge($response->body)));
}
function snapshotConfig() {
$outputfile = array(
'Location' => $this->ossLocation,
'Bucket' => $this->bucket,
'Object' => urlencode($this->oss_output_object));
$snapshotConfig['OutputFile'] = $outputfile;
$snapshotConfig['Time'] = 2;
$snapshotConfig['Num'] = 10;
$snapshotConfig['Interval'] = 20;
return json_encode($snapshotConfig);
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();
查询截图作业
调用QuerySnapshotJobList查询截图作业,接口参数和返回字段详细信息请参见查询截图作业,调用示例如下:
<?php
namespace AlibabaCloud\SDK\Sample;
use AlibabaCloud\SDK\Mts\V20140618\Mts;
use AlibabaCloud\Darabonba\Env\Env;
use AlibabaCloud\Tea\Tea;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Console\Console;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Mts\V20140618\Models\QuerySnapshotJobListRequest;
class Sample {
/**
* @param string $accessKeyId
* @param string $accessKeySecret
* @param string $regionId
* @return Mts
* 正式环境下 建议 protocol = "HTTPS";
*/
public static function createClient($accessKeyId, $accessKeySecret, $regionId){
$config = new Config([]);
$config->accessKeyId = $accessKeyId;
$config->accessKeySecret = $accessKeySecret;
$config->regionId = $regionId;
$config->protocol = "HTTP";
return new Mts($config);
}
/**
* @return void
*/
public static function main(){
$sample = new Sample;
$client = self::createClient(Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_ID"), Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), 'cn-shanghai');
$request = new QuerySnapshotJobListRequest([
"snapshotJobIds" => "72dfa5e67974c736******"
]);
$response = $client->querySnapshotJobList($request);
Console::log(Utils::toJSONString(Tea::merge($response->body)));
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
Sample::main();