截圖
更新時間:
視頻截圖是指對視頻截取指定時間、指定尺寸的圖片,用于生產(chǎn)視頻封面、雪碧圖、播放器進(jìn)度條縮略圖等場景,截圖作業(yè)支持指定時間點(diǎn)、時間間隔、截圖數(shù)量、類型以及是否拼圖等。您可以通過媒體處理控制臺、API或SDK提交截圖作業(yè)。本文提供了媒體處理PHP SDK截圖模塊相關(guān)功能的API調(diào)用示例。
前提條件
使用前請先安裝及完成PHP SDK相關(guān)配置,詳細(xì)信息,請參見前言。更多SDK及API調(diào)用示例,請參見OpenAPI。
提交截圖作業(yè)
調(diào)用SubmitSnapshotJob提交截圖作業(yè),接口參數(shù)和返回字段詳細(xì)信息請參見提交截圖作業(yè),調(diào)用示例如下:
<?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"; #轉(zhuǎn)碼模板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
* 正式環(huán)境下 建議 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();
查詢截圖作業(yè)
調(diào)用QuerySnapshotJobList查詢截圖作業(yè),接口參數(shù)和返回字段詳細(xì)信息請參見查詢截圖作業(yè),調(diào)用示例如下:
<?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
* 正式環(huán)境下 建議 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();
相關(guān)文檔
文檔內(nèi)容是否對您有幫助?