功能说明:对 AVI,FLV,M4V,MKV,MOV,MP4,WMV 文件进行压缩,裁剪,转换的 WEBSERVICE API。
https://www.xiliapi.com/api
module=video
//(string) 必须。
auth=秘钥,在“我的后台”可以获取
//(string) 必须。测试密钥,结果可能会带水印或截取片段。测试密钥会不定时更新,不能长期使用。
notifyUrl=https://www.mydomain.com/imageAPINotify
//(string) 必须。你服务器上接收压缩结果通知的 URL,必须是一个外网可以访问的以 http 或 https 开头的 URL。
oriFileUrl=https://www.mydomain.com/files/company.mp4
//(string) 必须。你服务器上需要压缩或转换的文件,必须是一个外网可以访问的以 http 或 https 开头的 URL。
oriFileHash=7fa367231a53a43435c3fefe8048b1de
//(string) 必须。你服务器上需要压缩或转换的文件的MD5值。
width=720
//(int) 非必须。默认960。需要裁剪文件的宽度(像素)。推荐 720 或 960。最大接受1280
grade=4
//(int) 非必须。压缩等级,默认4。推荐为 4,最大 7,最小 1。1 为最清晰
convert=mp4
//(string) 非必须。默认保持原格式。可接受 avi,flv,m4v,mkv,mov,mp4,wmv
接收成功
{
"status":true,
//(boolean)
"msg":{"all":"ok"},
//(object)
}
接收失败
{
"status":false,
//(boolean)
"msg":{"auth":"密钥不正确","notifyUrl":"不能访问"},
//(object) 错误的信息。
}
$url = 'https://你的文件地址';
$oriFileHash = md5_file($url);
$postUrl = 'https://www.xiliapi.com/api';
$postData = [
'module' => 'video',
'auth' => '秘钥,在“我的后台”可以获取',
'notifyUrl' => 'https://你的接收结果地址',
'oriFileUrl' => $url,
'oriFileHash' => $oriFileHash,
'width' => 720,
'grade' => 4,
'convert' => 'mp4'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
exit;
上面定义的 notifyUrl
包含上面调用时候的所有数据,另加下面的数据
处理成功:
status=true
//(boolean) 处理成功。
processedFile=https://www.xiliapi.com/processed/download?id=7fa367561a53a43435c3fefe8048b1de
//(string) 处理后的文件下载地址。此链接通知后3个小时内有效。
processedHash=7fa367561a53a43435c3fefe8048b1de
//(string) 处理后的文件的md5值。
processedSize=586500
//(int) 处理后的文件大小,单位 bit。
处理失败:
status=false
//(boolean) 处理失败。
msg=源文件下载失败
//(string) 失败原因概述:源文件下载失败,源文件有错误,源文件类型不正确,源文件太大。