阿里云点播php上传,媒体上传

初始化客户端

使用前请先初始化客户端,请参见

获取视频上传地址和凭证

调用CreateUploadVideo接口,完成获取视频上传地址和凭证功能。

接口参数和返回字段请参见/**

* 获取视频上传地址和凭证

* @param client 发送请求客户端

* @return CreateUploadVideoResponse 获取视频上传地址和凭证响应数据

*/

function createUploadVideo($client) {

$request = new vod\CreateUploadVideoRequest();

$request->setTitle("Sample Title");

$request->setFileName("videoFile.mov");

$request->setDescription("Video Description");

$request->setCoverURL("http://192.168.0.0/16/tps/TB1qnJ1PVXXXXXCXXXXXXXXXXXX-700-700.png");

$request->setTags("tag1,tag2");

$request->setAcceptFormat('JSON');

return $client->getAcsResponse($request);

}

try {

$client = initVodClient('', '');

$uploadInfo = createUploadVideo($client);

var_dump($uploadInfo);

} catch (Exception $e) {

print $e->getMessage()."\n";

}

刷新视频上传凭证

调用RefreshUploadVideo接口,完成刷新视频上传凭证功能。

接口参数和返回字段请参见/**

* 刷新视频上传凭证

* @param client 发送请求客户端

* @return RefreshUploadVideoResponse 刷新视频上传凭证响应数据

*/

function refreshUploadVideo($client, $videoId) {

$request = new vod\RefreshUploadVideoRequest();

$request->setVideoId($videoId);

$request->setAcceptFormat('JSON');

return $client->getAcsResponse($request);

}

try {

$client = initVodClient('', '');

$refreshInfo = refreshUploadVideo($client, 'videoId');

var_dump($refreshInfo);

} catch (Exception $e) {

print $e->getMessage()."\n";

}

获取图片上传地址和凭证

调用CreateUploadImage接口,完成获取图片上传地址和凭证功能。

接口参数和返回字段请参见/**

* 获取图片上传地址和凭证

* @param client 发送请求客户端

* @return CreateUploadImageResponse 获取图片上传地址和凭证响应数据

*/

function createUploadImage($client, $imageType, $imageExt) {

$request = new vod\CreateUploadImageRequest();

$request->setImageType($imageType);

$request->setImageExt($imageExt);

$request->setAcceptFormat('JSON');

return $client->getAcsResponse($request);

}

try {

$client = initVodClient('', '');

$imageInfo = createUploadImage($client, 'cover', 'jpg');

var_dump($imageInfo);

} catch (Exception $e) {

print $e->getMessage()."\n";

}

获取辅助媒资上传地址和凭证

调用CreateUploadAttachedMedia接口,完成获取辅助媒资上传地址和凭证功能。/**

* 获取辅助媒资(水印、字幕等)上传地址和凭证

* @param client 发送请求客户端

* @return CreateUploadAttachedMediaResponse 获取辅助媒资上传地址和凭证响应数据

*/

function createUploadAttachedMedia($client) {

$request = new vod\CreateUploadAttachedMediaRequest();

$request->setBusinessType("watermark");

$request->setMediaExt("gif");

$request->setTitle("this is a sample");

return $client->getAcsResponse($request);

}

try {

$client = initVodClient('', '');

$result = createUploadAttachedMedia($client);

var_dump($result);

} catch (Exception $e) {

print $e->getMessage()."\n";

}

URL批量拉取上传

调用UploadMediaByURL接口,完成URL批量拉取上传功能。

接口参数和返回字段请参见/**

* URL批量拉取上传

* @param client 发送请求客户端

* @return UploadMediaByURLResponse URL批量拉取上传响应数据

*/

function uploadMediaByURL($client) {

$request = new vod\UploadMediaByURLRequest();

$url = "http://192.168.0.0/16/***.mp4";

$request->setUploadURLs($url);

$uploadMetadataList = array();

$uploadMetadata = array();

$uploadMetadata["SourceUrl"] = $url;

$uploadMetadata["Title"] = "upload by url sample";

$uploadMetadataList[] = $uploadMetadata;

$request->setUploadMetadatas(json_encode($uploadMetadataList));

return $client->getAcsResponse($request);

}

try {

$client = initVodClient('', '');

$result = uploadMediaByURL($client);

var_dump($result);

} catch (Exception $e) {

print $e->getMessage()."\n";

}

注册媒资信息

调用RegisterMedia接口,完成注册媒资信息功能。

接口参数和返回字段请参见/**

* 注册媒资信息

* @param client 发送请求客户端

* @return RegisterMediaResponse 注册媒资信息响应数据

*/

function registerMedia($client) {

$request = new vod\RegisterMediaRequest();

$metaDataArray= array();

$metaData= array();

$metaData["Title"] = "registerMedia by url sample";

$metaData["FileURL"] = "https://192.168.0.0/16/vod_sample.mp4";

$metaDataArray[] = $metaData;

$request->setRegisterMetadatas(json_encode($metaDataArray));

return $client->getAcsResponse($request);

}

try {

$client = initVodClient('', '');

$result = registerMedia($client);

var_dump($result);

} catch (Exception $e) {

print $e->getMessage()."\n";

}

获取URL上传信息

调用GetURLUploadInfos接口,完成获取URL上传信息功能。

接口参数和返回字段请参见/**

* 获取URL上传信息

* @param client 发送请求客户端

* @return GetURLUploadInfosResponse 获取URL上传信息响应数据

*/

function getURLUploadInfos($client) {

$request = new vod\GetURLUploadInfosRequest();

// URL列表

$urls = array();

$urls[] = "http://192.168.0.0/16/sample1.mp4";

$urls[] = "http://192.168.0.0/16/sample2.mp4";

// 对URL进行编码

$uploadURLs = array();

foreach ($urls as $url) {

$uploadURLs[] = urlencode($url);

}

// 设置上传的URL列表,用逗号分隔

$request->setUploadURLs(implode(",", $uploadURLs));

// 也可以传入jobId查询

//$request->setJobIds("jobId1****,jobId2****")

return $client->getAcsResponse($request);

}

try {

$client = initVodClient('', '');

$result = getURLUploadInfos($client);

var_dump($result);

} catch (Exception $e) {

print $e->getMessage()."\n";

}