Overview

For more information about how to install and use the SDK, see Media library SDK-PHP.

A media set contains an input file and several output files. Besides basic information, an input file contains detailed Media set information. You can query details about the Videos and Screenshots in the output files.

Input

include_once 'aliyun-php-sdk-core/Config.php';
 use Mts\Request\V20140618 as Mts;
 $accessKeyID = 'test'; //eplace the value with your AccessKeyID
 $accessKeySecret = 'test'; //Replace the value with your AccessKeySecret
 $profile = DefaultProfile::getProfile('cn-hangzhou',
                                       $accessKeyID,
                                       $accessKeySecret);
 $client = new DefaultAcsClient($profile);
function queryMedia($client, $mediaID)
{
    $request = new Mts\QueryMediaListRequest();
    $request->setAcceptFormat('JSON');
    $request->setMediaIds($mediaID);
    $request->setIncludeMediaInfo("true");
    $response = $client->getAcsResponse($request);
    return $response;
}
function printMediaInfo($mediaInfo)
{
    print_r('Number of Streams: '.$mediaInfo->{'Format'}->{'NumStreams'}."\n");
    if (array_key_exists('Streams', $mediaInfo) &&
        array_key_exists('AudioStreamList', $mediaInfo->{'Streams'}) &&
        array_key_exists('AudioStream', $mediaInfo->{'Streams'}->{'AudioStreamList'})) {
        $audioStreams = $mediaInfo->{'Streams'}->{'AudioStreamList'}->{'AudioStream'};
        print_r('Audio Streams:'."\n");
        for ($i = 0; $i < count($audioStreams); $i++) {
            print_r("\t[".$i."]"."\n");
            print_r("\t\tCodecName: ".$audioStreams[$i]->{'CodecName'}."\n");
            print_r("\t\tChannels: ".$audioStreams[$i]->{'Channels'}."\n");
            print_r("\t\tSamplerate: ".$audioStreams[$i]->{'Samplerate'}."\n");
            print_r("\t\tDuration: ".$audioStreams[$i]->{'Duration'}."\n");
            print_r("\t\tBitrate: ".$audioStreams[$i]->{'Bitrate'}."\n");
        }
    }
    if (array_key_exists('Streams', $mediaInfo) &&
        array_key_exists('VideoStreamList', $mediaInfo->{'Streams'}) &&
        array_key_exists('VideoStream', $mediaInfo->{'Streams'}->{'VideoStreamList'})) {
        $videoStreams = $mediaInfo->{'Streams'}->{'VideoStreamList'}->{'VideoStream'};
        print_r('Video Streams:'."\n");
        for ($i = 0; $i < count($videoStreams); $i++) {
            print_r("\t[".$i."]"."\n");
            print_r("\t\tCodecName: ".$videoStreams[$i]->{'CodecName'}."\n");
            print_r("\t\tProfile: ".$videoStreams[$i]->{'Profile'}."\n");
            print_r("\t\tDuration: ".$videoStreams[$i]->{'Duration'}."\n");
            print_r("\t\tPixFmt: ".$videoStreams[$i]->{'PixFmt'}."\n");
            print_r("\t\tFps: ".$videoStreams[$i]->{'Fps'}."\n");
            print_r("\t\tBitrate: ".$videoStreams[$i]->{'Bitrate'}."\n");
            print_r("\t\tResolution: ".$videoStreams[$i]->{'Width'}.'x'.$videoStreams[$i]->{'Height'}."\n");
        }
    }
}
$mediaID = 'test'; //Replace the value with your desired media ID
$medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
for ($i = 0; $i < count($medias); $i++) {
    printMediaInfo($medias[$i]->{'MediaInfo'});
}

Output

  • Videos
    function queryMedia($client, $mediaID)
    {
        $request = new Mts\QueryMediaListRequest();
        $request->setAcceptFormat('JSON');
        $request->setMediaIds($mediaID);
        $request->setIncludePlayList("true");
        $response = $client->getAcsResponse($request);
        return $response;
    }
    function printOutputVideos($videos)
    {
        print_r('Number of Output Video: '.count($videos)."\n");
        for ($i = 0; $i < count($videos); $i++) {
            print_r("\t[".$i."]"."\n");
            print_r("\t\tMediaWorkflowName: ".$videos[$i]->{'MediaWorkflowName'}."\n");
            print_r("\t\tActivityName: ".$videos[$i]->{'ActivityName'}."\n");
            print_r("\t\tFormat: ".$videos[$i]->{'Format'}."\n");
            print_r("\t\tDuration: ".$videos[$i]->{'Duration'}."\n");
            print_r("\t\tFps: ".$videos[$i]->{'Fps'}."\n");
            print_r("\t\tBitrate: ".$videos[$i]->{'Bitrate'}."\n");
            print_r("\t\tSize: ".$videos[$i]->{'Size'}."\n");
            print_r("\t\tResolution: ".$videos[$i]->{'Width'}.'x'.$videos[$i]->{'Height'}."\n");
            print_r("\t\tURL: ".$videos[$i]->{'File'}->{'URL'}."\n");
        }
    }
    $mediaID = 'test'; //Replace the value with your desired media ID
    $medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
    for ($i = 0; $i < count($medias); $i++) {
        printOutputVideos($medias[$i]->{'PlayList'}->{'Play'});
    }
  • Screenshots
    function queryMedia($client, $mediaID)
    {
        $request = new Mts\QueryMediaListRequest();
        $request->setAcceptFormat('JSON');
        $request->setMediaIds($mediaID);
        $request->setIncludeSnapshotList("true");
        $response = $client->getAcsResponse($request);
        return $response;
    }
    function printOutputSnapshots($snapshots)
    {
        print_r('Number of Output Snapshot: '.count($snapshots)."\n");
        for ($i = 0; $i < count($snapshots); $i++) {
            print_r("\t[".$i."]"."\n");
            print_r("\t\tMediaWorkflowName: ".$snapshots[$i]->{'MediaWorkflowName'}."\n");
            print_r("\t\tActivityName: ".$snapshots[$i]->{'ActivityName'}."\n");
            print_r("\t\tType: ".$snapshots[$i]->{'Type'}."\n");
            print_r("\t\tCount: ".$snapshots[$i]->{'Count'}."\n");
            print_r("\t\tURL: ".$snapshots[$i]->{'File'}->{'URL'}."\n");
        }
    }
    $mediaID = 'test'; //Replace the value with your desired media ID
    $medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
    for ($i = 0; $i < count($medias); $i++) {
        printOutputSnapshots($medias[$i]->{'SnapshotList'}->{'Snapshot'});
    }