全部产品
媒体转码

媒体详细信息

更新时间:2017-06-07 13:26:11   分享:   

返回:简介 >>

媒体库管理-媒体详细信息-示例代码-PHP

  • 简介

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

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

  • 输入

    • 媒体信息

      1. include_once 'aliyun-php-sdk-core/Config.php';
      2. use Mts\Request\V20140618 as Mts;
      3. $accessKeyID = 'test'; // 替换成真实的id
      4. $accessKeySecret = 'test'; // 替换成真实的secret
      5. $profile = DefaultProfile::getProfile('cn-hangzhou',
      6. $accessKeyID,
      7. $accessKeySecret);
      8. $client = new DefaultAcsClient($profile);
      1. function queryMedia($client, $mediaID)
      2. {
      3. $request = new Mts\QueryMediaListRequest();
      4. $request->setAcceptFormat('JSON');
      5. $request->setMediaIds($mediaID);
      6. $request->setIncludeMediaInfo("true");
      7. $response = $client->getAcsResponse($request);
      8. return $response;
      9. }
      10. function printMediaInfo($mediaInfo)
      11. {
      12. print_r('Number of Streams: '.$mediaInfo->{'Format'}->{'NumStreams'}."\n");
      13. if (array_key_exists('Streams', $mediaInfo) &&
      14. array_key_exists('AudioStreamList', $mediaInfo->{'Streams'}) &&
      15. array_key_exists('AudioStream', $mediaInfo->{'Streams'}->{'AudioStreamList'})) {
      16. $audioStreams = $mediaInfo->{'Streams'}->{'AudioStreamList'}->{'AudioStream'};
      17. print_r('Audio Streams:'."\n");
      18. for ($i = 0; $i < count($audioStreams); $i++) {
      19. print_r("\t[".$i."]"."\n");
      20. print_r("\t\tCodecName: ".$audioStreams[$i]->{'CodecName'}."\n");
      21. print_r("\t\tChannels: ".$audioStreams[$i]->{'Channels'}."\n");
      22. print_r("\t\tSamplerate: ".$audioStreams[$i]->{'Samplerate'}."\n");
      23. print_r("\t\tDuration: ".$audioStreams[$i]->{'Duration'}."\n");
      24. print_r("\t\tBitrate: ".$audioStreams[$i]->{'Bitrate'}."\n");
      25. }
      26. }
      27. if (array_key_exists('Streams', $mediaInfo) &&
      28. array_key_exists('VideoStreamList', $mediaInfo->{'Streams'}) &&
      29. array_key_exists('VideoStream', $mediaInfo->{'Streams'}->{'VideoStreamList'})) {
      30. $videoStreams = $mediaInfo->{'Streams'}->{'VideoStreamList'}->{'VideoStream'};
      31. print_r('Video Streams:'."\n");
      32. for ($i = 0; $i < count($videoStreams); $i++) {
      33. print_r("\t[".$i."]"."\n");
      34. print_r("\t\tCodecName: ".$videoStreams[$i]->{'CodecName'}."\n");
      35. print_r("\t\tProfile: ".$videoStreams[$i]->{'Profile'}."\n");
      36. print_r("\t\tDuration: ".$videoStreams[$i]->{'Duration'}."\n");
      37. print_r("\t\tPixFmt: ".$videoStreams[$i]->{'PixFmt'}."\n");
      38. print_r("\t\tFps: ".$videoStreams[$i]->{'Fps'}."\n");
      39. print_r("\t\tBitrate: ".$videoStreams[$i]->{'Bitrate'}."\n");
      40. print_r("\t\tResolution: ".$videoStreams[$i]->{'Width'}.'x'.$videoStreams[$i]->{'Height'}."\n");
      41. }
      42. }
      43. }
      44. $mediaID = 'test'; // 替换成真实的mediaID
      45. $medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
      46. for ($i = 0; $i < count($medias); $i++) {
      47. printMediaInfo($medias[$i]->{'MediaInfo'});
      48. }
  • 输出

    • 视频

      1. function queryMedia($client, $mediaID)
      2. {
      3. $request = new Mts\QueryMediaListRequest();
      4. $request->setAcceptFormat('JSON');
      5. $request->setMediaIds($mediaID);
      6. $request->setIncludePlayList("true");
      7. $response = $client->getAcsResponse($request);
      8. return $response;
      9. }
      10. function printOutputVideos($videos)
      11. {
      12. print_r('Number of Output Video: '.count($videos)."\n");
      13. for ($i = 0; $i < count($videos); $i++) {
      14. print_r("\t[".$i."]"."\n");
      15. print_r("\t\tMediaWorkflowName: ".$videos[$i]->{'MediaWorkflowName'}."\n");
      16. print_r("\t\tActivityName: ".$videos[$i]->{'ActivityName'}."\n");
      17. print_r("\t\tFormat: ".$videos[$i]->{'Format'}."\n");
      18. print_r("\t\tDuration: ".$videos[$i]->{'Duration'}."\n");
      19. print_r("\t\tFps: ".$videos[$i]->{'Fps'}."\n");
      20. print_r("\t\tBitrate: ".$videos[$i]->{'Bitrate'}."\n");
      21. print_r("\t\tSize: ".$videos[$i]->{'Size'}."\n");
      22. print_r("\t\tResolution: ".$videos[$i]->{'Width'}.'x'.$videos[$i]->{'Height'}."\n");
      23. print_r("\t\tURL: ".$videos[$i]->{'File'}->{'URL'}."\n");
      24. }
      25. }
      26. $mediaID = 'test'; // 替换成真实的mediaID
      27. $medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
      28. for ($i = 0; $i < count($medias); $i++) {
      29. printOutputVideos($medias[$i]->{'PlayList'}->{'Play'});
      30. }
    • 截图

      1. function queryMedia($client, $mediaID)
      2. {
      3. $request = new Mts\QueryMediaListRequest();
      4. $request->setAcceptFormat('JSON');
      5. $request->setMediaIds($mediaID);
      6. $request->setIncludeSnapshotList("true");
      7. $response = $client->getAcsResponse($request);
      8. return $response;
      9. }
      10. function printOutputSnapshots($snapshots)
      11. {
      12. print_r('Number of Output Snapshot: '.count($snapshots)."\n");
      13. for ($i = 0; $i < count($snapshots); $i++) {
      14. print_r("\t[".$i."]"."\n");
      15. print_r("\t\tMediaWorkflowName: ".$snapshots[$i]->{'MediaWorkflowName'}."\n");
      16. print_r("\t\tActivityName: ".$snapshots[$i]->{'ActivityName'}."\n");
      17. print_r("\t\tType: ".$snapshots[$i]->{'Type'}."\n");
      18. print_r("\t\tCount: ".$snapshots[$i]->{'Count'}."\n");
      19. print_r("\t\tURL: ".$snapshots[$i]->{'File'}->{'URL'}."\n");
      20. }
      21. }
      22. $mediaID = 'test'; // 替换成真实的mediaID
      23. $medias = queryMedia($client, $mediaID)->{'MediaList'}->{'Media'};
      24. for ($i = 0; $i < count($medias); $i++) {
      25. printOutputSnapshots($medias[$i]->{'SnapshotList'}->{'Snapshot'});
      26. }

返回:简介 >>

本文导读目录
本文导读目录
以上内容是否对您有帮助?