//一些引用文件:视频截图使用
include_once VENDOR_PATH . 'aliyun-openapi-php-sdk-master/aliyun-php-sdk-core/Config.php';
require_once VENDOR_PATH . 'aliyun-oss-php-sdk-master/aliyun-oss-php-sdk.phar';
use Mts\Request\V20140618 as Mts;
//对数据库里的视频进行截图
public function snapshot_old()
{
//获取阿里云的配置
$arrAliyun = config('aliyun_oss');
$region = $arrAliyun['mts_region'];
$access_key_id = $arrAliyun['access_key_id'];
$access_key_secret = $arrAliyun['access_key_secret'];
$pipeline_id = $arrAliyun['pipeline_id'];//
$oss_location = $arrAliyun['oss_region'];//输入OSS Bucket所在数据中心(OSS Location)
$input_bucket = $arrAliyun['bucket'];//
$input_object = urlencode('rm660739/video/201803/1521605649362.mp4');//要截图的视频文件(OSS Object),须进行UrlEncode,使用UTF-8编码
$output_bucket = $input_bucket;//截图输出文件所在OSS Bucket
$output_object = urlencode('{ObjectPrefix}{FileName}.jpg');//截图输出文件 (OSS Object),截图输出文件格式为jpg,输出文件名须进行UrlEncode,使用UTF-8编码。
$output_object = urlencode('rm179162/transcode/1521660643_8679.mp4.jpg');//截图输出文件 (OSS Object),截图输出文件格式为jpg,输出文件名须进行UrlEncode,使用UTF-8编码。
$time = '1000';//截图时间,单位毫秒
$interval = '5';//截图间隔时间,若指定则表示异步模式序列截图,Interval必须大于等于0,单位秒
$num = '1';//截图数量
$frame_type = 'normal';//'intra'截图类型,普通帧normal,I帧intra默认
$width = '1024';//截图输出图片宽度,单位px,范围8-4096
$height = '768';//
$input = array(
'Location' => $oss_location,
'Bucket' => $input_bucket,
'Object' => $input_object
);
$output=array(
'Location' => $oss_location,
'Bucket' => $output_bucket,
'Object' => $output_object
);
$snapshot_config = array(
'OutputFile' => $output,
'Time' => $time,
//'Interval' => $interval,
//'Num' => $num,
'FrameType' => $frame_type,
//"Width" => $width,
//"Height" => $height
);
$profile = \DefaultProfile::getProfile($region, $access_key_id, $access_key_secret);
$client = new \DefaultAcsClient($profile);
$request = new Mts\SubmitSnapshotJobRequest();
$request->setPipelineId($pipeline_id);
$request->setInput(json_encode($input));
$request->setSnapshotConfig(json_encode($snapshot_config));
// 如果出错,可能会抛出ClientException或ServerException异常
$response = $client->getAcsResponse($request);
$snapshotJob = $response->SnapshotJob;
printx($snapshotJob);
}
结果:
参考资料:
https://helpcdn.aliyun.com/document_detail/56337.html
写完之后,发现了一个更简单的,连接口都不用调了,在原有连接上加几个参数就行了:
http://a-image-demo.oss-cn-qingdao.aliyuncs.com/demo.mp4?spm=a2c4g.11186623.2.5.zOhgnZ&x-oss-process=video/snapshot,t_50000,f_jpg,w_0,h_0
参考资料:https://help.aliyun.com/document_detail/64555.html?spm=5176.11065259.1996646101.searchclickresult.13be256aj0Gl0i
|