All Products
Search
Document Center

ApsaraVideo Media Processing:Query media files based on their OSS URLs

Last Updated:Nov 16, 2023

If you do not know the ID of the media file, such as in live-to-VOD scenarios, you can call the QueryMediaListByURL operation to query a media file by using its Object Storage Service (OSS) URL. Sample code:

<?php
require_once './aliyun-php-sdk-core/Config.php'; 
use Mts\Request\V20140618 as Mts;

function initMtsClient($accessKeyId, $accessKeySecret) {
    $regionId = 'cn-shanghai';  // The ID of the region in which your MPS service is deployed.
    $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
    return new DefaultAcsClient($profile);
}

try {
    $client = initMtsClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'));
    $response = queryMediaListByURL($client);
    print_r($response);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

function queryMediaListByURL($client) {
    $request = new Mts\QueryMediaListByURLRequest();
    $ossDomain = 'http://<bucket name>.oss-cn-shanghai.aliyuncs.com/';
    $ossObject = urlencode('test/video.mp4');
    $request->setFileURLs($ossDomain.$ossObject);
    return $client->getAcsResponse($request);
}