All Products
Search
Document Center

Video Management

Last Updated: Mar 08, 2019

Initialize a client

  1. require_once './aliyun-php-sdk/aliyun-php-sdk-core/Config.php'; // Assume that your source code file is in the same directory as the **aliyun-php-sdk** directory.
  2. use vod\Request\V20170321 as vod;
  3. function init_vod_client($accessKeyId, $accessKeySecret) {
  4. $regionId = 'cn-shanghai'; // The region of ApsaraVideo for VOD. Enter cn-shanghai for a region in China.
  5. $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
  6. return new DefaultAcsClient($profile);
  7. }

Obtain video information

  1. function get_video_info($client, $videoId) {
  2. $request = new vod\GetVideoInfoRequest();
  3. $request->setVideoId($videoId);
  4. $request->setAcceptFormat('JSON');
  5. return $client->getAcsResponse($request);
  6. }
  7. try {
  8. $client = init_vod_client('<Your AccessKey ID>', '<Your AccessKey Secret>');
  9. $videoInfo = get_video_info($client, 'Your video ID');
  10. var_dump($videoInfo);
  11. } catch (Exception $e) {
  12. print $e->getMessage()."\n";
  13. }

For more information about request and response parameters, see GetVideoInfo.

Modify video information

  1. function update_video_info($client, $videoId) {
  2. $request = new vod\UpdateVideoInfoRequest();
  3. $request->setVideoId($videoId);
  4. $request->setTitle('New Title'); // Modify the video title.
  5. $request->setDescription('New Description'); // Modify the video description.
  6. $request->setCoverURL('http://img.alicdn.com/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png'); // Change the video thumbnail.
  7. $request->setTags('tag1,tag2'); // Change video tags. Separate multiple video tags with a comma (,).
  8. $request->setCateId(0); // Change the video category. You can choose ApsaraVideo for VOD console > Global Settings > Categories to view the category ID (at https://vod.console.aliyun.com/#/vod/settings/category).
  9. $request->setAcceptFormat('JSON');
  10. return $client->getAcsResponse($request);
  11. }
  12. try {
  13. $client = init_vod_client('<Your AccessKey ID>', '<Your AccessKey Secret>');
  14. $videoInfo = update_video_info($client, 'Your video ID');
  15. var_dump($videoInfo);
  16. } catch (Exception $e) {
  17. print $e->getMessage()."\n";
  18. }

For more information about request and response parameters, see UpdateVideoInfo.

Delete videos

  1. function delete_videos($client, $videoIds) {
  2. $request = new vod\DeleteVideoRequest();
  3. $request->setVideoIds($videoIds); // Delete one or more videos, where **videoIds** indicates the IDs of videos to be deleted. Separate multiple video IDs with a comma (,).
  4. $request->setAcceptFormat('JSON');
  5. return $client->getAcsResponse($request);
  6. }
  7. try {
  8. $client = init_vod_client('<Your AccessKey ID>', '<Your AccessKey Secret>');
  9. $delInfo = delete_videos($client, 'vid1,vid2');
  10. var_dump($delInfo);
  11. } catch (Exception $e) {
  12. print $e->getMessage()."\n";
  13. }

For more information about request and response parameters, see DeleteVideo.

Obtain source file information (including the source file download address)

  1. function get_mezzanine_info($client, $videoId) {
  2. $request = new vod\GetMezzanineInfoRequest();
  3. $request->setVideoId($videoId);
  4. $request->setAuthTimeout(3600*5); // The expiration time of the source file download address, in seconds. The default value is 3600.
  5. $request->setAcceptFormat('JSON');
  6. return $client->getAcsResponse($request);
  7. }
  8. try {
  9. $client = init_vod_client('<Your AccessKey ID>', '<Your AccessKey Secret>');
  10. $mezzanine = get_mezzanine_info($client, 'Your video ID');
  11. var_dump($mezzanine);
  12. } catch (Exception $e) {
  13. print $e->getMessage()."\n";
  14. }

For more information about request and response parameters, see GetMezzanineInfo.

Obtain a video list

  1. function get_video_list($client) {
  2. $request = new vod\GetVideoListRequest();
  3. // For example, set the start time to one month ago (in UTC) and the end time to the current time (in UTC) for filtering videos.
  4. $localTimeZone = date_default_timezone_get();
  5. date_default_timezone_set('UTC');
  6. $utcNow = gmdate('Y-m-d\TH:i:s\Z');
  7. $utcMonthAgo = gmdate('Y-m-d\TH:i:s\Z', time() - 30*86400);
  8. date_default_timezone_set($localTimeZone);
  9. $request->setStartTime($utcMonthAgo); // The start time for video creation, in UTC.
  10. $request->setEndTime($utcNow); // The end time for video creation, in UTC.
  11. #$request->setStatus('Uploading,Normal,Transcoding'); // The video status. Videos in all states are obtained by default. Separate multiple video states with a comma (,).
  12. #$request->setCateId(0); // Filter videos by category.
  13. $request->setPageNo(1);
  14. $request->setPageSize(20);
  15. $request->setAcceptFormat('JSON');
  16. return $client->getAcsResponse($request);
  17. }
  18. try {
  19. $client = init_vod_client('<Your AccessKey ID>', '<Your AccessKey Secret>');
  20. $videoList = get_video_list($client);
  21. var_dump($videoList);
  22. } catch (Exception $e) {
  23. print $e->getMessage()."\n";
  24. }

For more information about request and response parameters, see GetVideoList.

Delete media streams

  1. // Delete one or more video or audio streams and their storage files. The deleted streams cannot be played if the CDN cache expires, so proceed with caution.
  2. function delete_stream($client, $videoId, $jobIds) {
  3. $request = new vod\DeleteStreamRequest();
  4. $request->setVideoId($videoId);
  5. $request->setJobIds($jobIds); // The IDs of media stream transcoding jobs. Separate multiple job IDs with a comma (,). You can obtain the job ID through the GetPlayInfo operation.
  6. $request->setAcceptFormat('JSON');
  7. return $client->getAcsResponse($request);
  8. }
  9. try {
  10. $client = init_vod_client('<Your AccessKey ID>', '<Your AccessKey Secret>');
  11. $delStream = delete_stream($client, 'Your video ID', 'jobId1,jobId2');
  12. var_dump($delStream);
  13. } catch (Exception $e) {
  14. print $e->getMessage()."\n";
  15. }

For more information about request and response parameters, see DeleteStream.