赞
踩
获取视频上传凭证,这个时候会产生一个“上传中”的空videoid,实际上是没有上传内容的;
通过获取到的uploadAuth/uploadAddress/videoId进行上传您本地的视频完成了2和3之后才会出现“正常”状态下的视频。
1:视频合成第一步创建云剪辑工程
- /**
- * 使用AK&SK初始化账号Client
- * @param string $accessKeyId
- * @param string $accessKeySecret
- * @return Vod Client
- */
- public static function createClient($accessKeyId, $accessKeySecret){
- $config = new Config([
- // 您的AccessKey ID
- "accessKeyId" => $accessKeyId,
- // 您的AccessKey Secret
- "accessKeySecret" => $accessKeySecret
- ]);
- // 访问的域名
- $config->endpoint = "vod.cn-beijing.aliyuncs.com";
- $config->endpoint = "vod.cn-shanghai.aliyuncs.com";
- return new Vod($config);
- }
-
-
- /**
- * 创建云剪辑工程
- */
- public static function cloudClip($info){
- $client = self::createClient("", "");
- $addEditingProjectRequest = new AddEditingProjectRequest([
- "title" => $info['Title'],
- 'description' => $info['Description'],
- 'coverURL' => $info['CoverURL'],
- ]);
- return $client -> addEditingProject($addEditingProjectRequest);
- }
-
- $info = [
- 'Title' => 'zjzj',
- 'Description' => '123456789',
- 'CoverURL' => 'http://api.cloudtanke.com/static/images/login_logo.png',
- 'FileName' => 'zjzj.mp4',
- ];
-
- $cloudClip = self::cloudClip($info);#创建云剪辑工程
2:第二步 获取视频上传地址和凭证 (如果报错:The storageLocation does not exist 的话 , 请查看服务地址。改成上海试试)
- /**
- * 获取视频上传地址和凭证
- */
- public static function createVideo($info){
- $client = self::createClient("", "");
- $createUploadVideoRequest = new CreateUploadVideoRequest([
- "fileName" => $info['FileName'],
- "title" => $info['Title'],
- ]);
- return $client->createUploadVideo($createUploadVideoRequest);
- }
-
- $videoId = self::createVideo($info);
3:第三步 查看文档 基于OSS原生SDK上传视频到点播
- $uploadAuth = json_decode(base64_decode($videoId->body->uploadAuth),true);
- $uploadAddress = json_decode(base64_decode($videoId->body->uploadAddress),true);
-
- $localFile = $_SERVER['DOCUMENT_ROOT'].'/uploads/20210409/eb0b8db0e74c61d11529613e3a3c5f2d.mp4';
-
- $ossClient = self::initOssClient($uploadAuth,$uploadAddress,$localFile);#基于OSS原生SDK上传视频
-
- /**
- * 基于OSS原生SDK上传视频
- * @param $uploadAuth
- * @param $uploadAddress
- * @param $localFile
- * @return null
- * @throws \OSS\Core\OssException
- */
- public static function initOssClient($uploadAuth, $uploadAddress,$localFile) {
- $ossClient = new OssClient($uploadAuth['AccessKeyId'], $uploadAuth['AccessKeySecret'], $uploadAddress['Endpoint'],
- false, $uploadAuth['SecurityToken']);
- $ossClient->setTimeout(86400*7); // 设置请求超时时间,单位秒,默认是5184000秒, 建议不要设置太小,如果上传文件很大,消耗的时间会比较长
- $ossClient->setConnectTimeout(10); // 设置连接超时时间,单位秒,默认是10秒
-
- //return $ossClient->uploadFile($uploadAddress['Bucket'], $uploadAddress['FileName'], $localFile);
- return $ossClient->multiuploadFile($uploadAddress['Bucket'], $uploadAddress['FileName'], $localFile);
- }
4:第四步 视频合成
合成视频 视频+音频 音频上传如第二步操作一样
$result这个数组里面包含很多个二维数组,一维数组不会报错,但是会上传不成功
- $result = [
- "VideoTracks" => [
- [
- "VideoTrackClips" =>[
- [
- "MediaId" => $videoId->body->videoId,
- "Effects" => [
- [
- "Type" => "Volume",
- "Gain" => "0"
- ]
- ]
- ]
- ]
- ],
- ],
- "AudioTracks" => [
- [
- "AudioTrackClips" =>[
- [
- "MediaId" => $audioId->body->videoId,
- "TimelineIn" => 5
- ]
- ]
- ]
- ]
- ];
-
- $resultJson = json_encode($result);
-
- $arr=self::videoPost($cloudClip->body->project->projectId,$resultJson);#视频合成
-
- /**
- * 视频合成
- */
- public function videoPost($projectId,$result){
- $client = self::createClient("", "");
- $produceEditingProjectVideoRequest = new ProduceEditingProjectVideoRequest([
- 'projectId' => $projectId,
- 'timeline' => $result
- ]);
- return $client->produceEditingProjectVideo($produceEditingProjectVideoRequest);
- }
-
-
-
-
-
完结!!!
补充:
1:use的路径一定要准确!!!!
- use AlibabaCloud\SDK\Vod\V20170321\Models\AddEditingProjectRequest;
- use AlibabaCloud\SDK\Vod\V20170321\Models\CreateUploadVideoRequest;
- use AlibabaCloud\SDK\Vod\V20170321\Models\GetPlayInfoRequest;
- use AlibabaCloud\SDK\Vod\V20170321\Models\GetVideoPlayAuthRequest;
- use AlibabaCloud\SDK\Vod\V20170321\Models\ProduceEditingProjectVideoRequest;
- use AlibabaCloud\SDK\Vod\V20170321\Models\RefreshUploadVideoRequest;
- use AlibabaCloud\SDK\Vod\V20170321\Vod;
- use app\common\controller\Frontend;
- use Darabonba\OpenApi\Models\Config;
- use OSS\OssClient;
2:SDK包 安装新本SDK 使用composer可
写代码的时候 找不到 文件 打开https://github.com/alibabacloud-sdk-php/vod-20170321加载到sdk下面
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。