edit-icon download-icon

Screenshot

Last Updated: Apr 19, 2018

MPS allows you to take JPG screenshots at a specified time of a video file stored in OSS. It provides a series of screenshot APIs such as SubmitSnapshotJob and QuerySnapshotJobList.

Submit a screenshot task

You can submit a screenshot task over SubmitSnapshotJob.

  1. $region = '<region>';
  2. $access_key_id = '<access_key_id>';
  3. $access_key_secret = '<access_key_secret>';
  4. $pipeline_id = '<pipeline_id>';
  5. $oss_location='<oss_location>';
  6. $input_bucket='<input_bucket>';
  7. $input_object='<input_object>';
  8. $output_bucket='<output_bucket>';
  9. $output_object='<output_object>';
  10. $time='<time>';
  11. $interval='<interval>';
  12. $num='<num>';
  13. $frame_type='<frame_type>';
  14. $width='<width>';
  15. $height='<height>';
  16. $input=array(
  17. 'Location'=>$oss_location,
  18. 'Bucket' =>$input_bucket,
  19. 'Object' =>$input_object
  20. );
  21. $output=array(
  22. 'Location' =>$oss_location,
  23. 'Bucket' => $output_bucket,
  24. 'Object' => $output_object
  25. );
  26. $snapshot_config = array(
  27. 'OutputFile' => $output,
  28. 'Time' => $time,
  29. 'Interval'=> $interval,
  30. 'Num'=> $num,
  31. 'FrameType'=> $frame_type,
  32. "Width"=> $width,
  33. "Height"=> $height
  34. );
  35. $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
  36. $client = new DefaultAcsClient($profile);
  37. $request = new Mts\SubmitSnapshotJobRequest();
  38. $request->setPipelineId($pipelineId);
  39. $request->setInput(json_encode($input));
  40. $request->setSnapshotConfig(json_encode($snapshot_config));
  41. // If an error occurs, ClientException or ServerException may be thrown
  42. $response = $client->getAcsResponse($request);
  43. $snapshotJob = $response->SnapshotJob;
  44. echo 'snapshot id:' . $snapshotJob->Id . "\n";

Query a screenshot task

If you already have the screenshot task ID, you can use the ID to call QuerySnapshotJobList to query the screenshot information.

  1. $region = '<region>';
  2. $accessKeyId = '<accessKeyId>';
  3. $accessKeySecret = '<accessKeySecret>';
  4. // Known screenshot IDs. Multiple screenshot tasks are separated by commas&nbsp;(,)
  5. $snapshotIds = '<snapshotId>';
  6. $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
  7. $client = new DefaultAcsClient($profile);
  8. $request = new Mts\QuerySnapshotJobListRequest();
  9. $request->setSnapshotJobIds($snapshotIds);
  10. // If an error occurs, ClientException or ServerException may be thrown
  11. $response = $client->getAcsResponse($request);
  12. $snapshots = $response->SnapshotJobList->SnapshotJob;
  13. foreach ($snapshots as $snapshot) {
  14. echo 'snapshot id:' . $snapshot->Id . ', count:' . $snapshot->Count . "\n";
  15. }
Thank you! We've received your feedback.