全部产品
媒体转码

截图

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

对存储于OSS上的视频文件截取指定时间的JPG格式图像。提供一系列截图接口 ,比如SubmitSnapshotJob,QuerySnapshotJobList。

提交截图作业

可以直接通过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. // 如果出错,可能会抛出ClientException或ServerException异常
  42. $response = $client->getAcsResponse($request);
  43. $snapshotJob = $response->SnapshotJob;
  44. echo 'snapshot id:' . $snapshotJob->Id . "\n";

查询截图作业

如果已经知道snapshotJobId,可以通过snapshotJobId调用QuerySnapshotJobList接口查询截图信息。

  1. $region = '<region>';
  2. $accessKeyId = '<accessKeyId>';
  3. $accessKeySecret = '<accessKeySecret>';
  4. // 已知的截图snapshotIds,多个截图任务用','分隔
  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. // 如果出错,可能会抛出ClientException或ServerException异常
  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. }
本文导读目录
本文导读目录
以上内容是否对您有帮助?