简介

SDK的安装和使用,详情参考 媒体库SDK-PHP

一个媒体包含一个输入文件和若干输出文件。输入除了基本信息之外,还有详细的 媒体信息。输出可以查询视频和截图的详细信息。

输入媒体信息

include_once 'aliyun-php-sdk-core/Config.php';
 use Mts\Request\V20140618 as Mts;
 $accessKeyID = 'test'; // 替换成真实的id
 $accessKeySecret = 'test'; // 替换成真实的secret
 $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'; // 替换成真实的mediaID
$medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
for ($i = 0; $i < count($medias); $i++) {
    printMediaInfo($medias[$i]->{'MediaInfo'});
}

输出

  • 视频
    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'; // 替换成真实的mediaID
    $medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
    for ($i = 0; $i < count($medias); $i++) {
        printOutputVideos($medias[$i]->{'PlayList'}->{'Play'});
    }
  • 截图
    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'; // 替换成真实的mediaID
    $medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
    for ($i = 0; $i < count($medias); $i++) {
        printOutputSnapshots($medias[$i]->{'SnapshotList'}->{'Snapshot'});
    }