All Products
Search
Document Center

ApsaraVideo Media Processing:Capture snapshots

Last Updated:Jun 16, 2026

Video snapshots capture frames of a specific size at designated points in time, for use as video thumbnails, sprites, or progress bar thumbnails. When you submit a snapshot job, you can specify the capture time, interval, count, snapshot type, and whether to compose an image sprite. You can submit snapshot jobs in the ApsaraVideo Media Processing (MPS) console or by using the API or SDKs. This topic provides PHP SDK sample code for submitting and querying snapshot jobs in ApsaraVideo Media Processing (MPS).

Prerequisites

MPS SDK for PHP is installed and configured. For more information, see MPS SDK for PHP. To obtain more information about the SDK and view examples on how to use the SDK to call API operations, visit OpenAPI Explorer.

Submit a snapshot job

Call the SubmitSnapshotJob operation to submit a snapshot job. For more information about the request and response parameters, see 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"; # The ID of the transcoding template. Select a template based on your business requirements.
    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
     * We recommend that you set the protocol parameter to HTTPS in a production environment.
     */
    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();

Query one or more snapshot jobs

Call the QuerySnapshotJobList operation to query one or more snapshot jobs. For more information about the request and response parameters, see 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
     * We recommend that you set the protocol parameter to HTTPS in a production environment.
     */
    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();

References