@@ -6,15 +6,15 @@ discard block |
||
| 6 | 6 | class MediaEncodeOption extends MediaResOption |
| 7 | 7 | {
|
| 8 | 8 | /* 以下属性是"视频转码"方法必须的属性 */ |
| 9 | - private $encodeTemplate; //模板名称。可以设置系统或者用户自定义模板。用户模板名称可以登录后台查看和设置,系统模板见附录系统模板列表 |
|
| 10 | - public $usePreset = 0; //是否使用系统模板。默认0。如果为1,则encodeTemplate必须设置系统模板名称 |
|
| 11 | - public $force = 0; //是否强制覆盖。默认0,如果为1,当output文件已经存在的时候会强制覆盖,否则不执行转码并结束任务 |
|
| 9 | + private $encodeTemplate; //模板名称。可以设置系统或者用户自定义模板。用户模板名称可以登录后台查看和设置,系统模板见附录系统模板列表 |
|
| 10 | + public $usePreset = 0; //是否使用系统模板。默认0。如果为1,则encodeTemplate必须设置系统模板名称 |
|
| 11 | + public $force = 0; //是否强制覆盖。默认0,如果为1,当output文件已经存在的时候会强制覆盖,否则不执行转码并结束任务 |
|
| 12 | 12 | /* 以下属性是"视频转码"方法可选的属性 */ |
| 13 | - private $watermark; //水印资源 |
|
| 14 | - private $watermarkTemplate; //用户自定义水印模板 |
|
| 15 | - private $notifyUrl; //通知url,任务结束之后会调用这个url |
|
| 16 | - private $seek; //截取音视频的开始位置 |
|
| 17 | - private $duration; //截取音视频的长度 |
|
| 13 | + private $watermark; //水印资源 |
|
| 14 | + private $watermarkTemplate; //用户自定义水印模板 |
|
| 15 | + private $notifyUrl; //通知url,任务结束之后会调用这个url |
|
| 16 | + private $seek; //截取音视频的开始位置 |
|
| 17 | + private $duration; //截取音视频的长度 |
|
| 18 | 18 | |
| 19 | 19 | /**设置转码模板。必须。模板在顽兔控制台"多媒体处理"中配置*/ |
| 20 | 20 | public function setEncodeTemplate($encodeTemplate) |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | if (isset($this->notifyUrl)) |
| 51 | 51 | $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl); |
| 52 | 52 | if (isset($this->seek)) |
| 53 | - $httpBody .= '&seek=' . $this->seek; |
|
| 53 | + $httpBody .= '&seek=' . $this->seek; |
|
| 54 | 54 | if (isset($this->duration)) |
| 55 | 55 | $httpBody .= '&duration=' . $this->duration; |
| 56 | 56 | return array(true, "valid", $httpBody); //视频转码参数合法,返回http请求体 |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | /**多媒体操作的输入输出资源信息。视频截图和视频转码都继承该类*/ |
| 128 | 128 | abstract class MediaResOption |
| 129 | 129 | {
|
| 130 | - private $input; //输入的资源 |
|
| 131 | - private $output; //输出的资源 |
|
| 130 | + private $input; //输入的资源 |
|
| 131 | + private $output; //输出的资源 |
|
| 132 | 132 | /**设置输入的文件。*/ |
| 133 | 133 | public function setInputResource($namespace = null, $dir = null, $name = null) |
| 134 | 134 | {
|
@@ -25,12 +25,17 @@ discard block |
||
| 25 | 25 | public function checkOptionParameters() |
| 26 | 26 | {
|
| 27 | 27 | list($valid, $msg) = parent::checkOptionParameters(); //检测输入输出资源是否合法 |
| 28 | - if (!$valid) |
|
| 29 | - return array($valid, $msg, null); |
|
| 30 | - if (empty($this->encodeTemplate)) |
|
| 31 | - return array(false, "encodeTemplate is empty.", null); // 判断是否设置输入输出文件,或者转码模板 |
|
| 32 | - if (($this->usePreset != 0 && $this->usePreset != 1) || ($this->force != 0 && $this->force != 1)) |
|
| 33 | - return array(false, "parameters 'usePreset' or 'force' is invalid.", null); // 判断usePreset和force参数是否为0或1 |
|
| 28 | + if (!$valid) {
|
|
| 29 | + return array($valid, $msg, null); |
|
| 30 | + } |
|
| 31 | + if (empty($this->encodeTemplate)) {
|
|
| 32 | + return array(false, "encodeTemplate is empty.", null); |
|
| 33 | + } |
|
| 34 | + // 判断是否设置输入输出文件,或者转码模板 |
|
| 35 | + if (($this->usePreset != 0 && $this->usePreset != 1) || ($this->force != 0 && $this->force != 1)) {
|
|
| 36 | + return array(false, "parameters 'usePreset' or 'force' is invalid.", null); |
|
| 37 | + } |
|
| 38 | + // 判断usePreset和force参数是否为0或1 |
|
| 34 | 39 | return $this->getOptionsHttpBody(); //返回http请求体 |
| 35 | 40 | } |
| 36 | 41 | /**构建多媒体转码所需的http请求体*/ |
@@ -43,16 +48,21 @@ discard block |
||
| 43 | 48 | $httpBody .= '&usePreset=' . $this->usePreset; |
| 44 | 49 | $httpBody .= '&force=' . $this->force; |
| 45 | 50 | // 可选的参数 |
| 46 | - if (isset($this->watermark)) |
|
| 47 | - $httpBody .= '&watermark=' . $this->watermark->buildResourceId(); |
|
| 48 | - if (isset($this->watermarkTemplate)) |
|
| 49 | - $httpBody .= '&watermarkTemplate=' . urlencode($this->watermarkTemplate); |
|
| 50 | - if (isset($this->notifyUrl)) |
|
| 51 | - $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl); |
|
| 52 | - if (isset($this->seek)) |
|
| 53 | - $httpBody .= '&seek=' . $this->seek; |
|
| 54 | - if (isset($this->duration)) |
|
| 55 | - $httpBody .= '&duration=' . $this->duration; |
|
| 51 | + if (isset($this->watermark)) {
|
|
| 52 | + $httpBody .= '&watermark=' . $this->watermark->buildResourceId(); |
|
| 53 | + } |
|
| 54 | + if (isset($this->watermarkTemplate)) {
|
|
| 55 | + $httpBody .= '&watermarkTemplate=' . urlencode($this->watermarkTemplate); |
|
| 56 | + } |
|
| 57 | + if (isset($this->notifyUrl)) {
|
|
| 58 | + $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl); |
|
| 59 | + } |
|
| 60 | + if (isset($this->seek)) {
|
|
| 61 | + $httpBody .= '&seek=' . $this->seek; |
|
| 62 | + } |
|
| 63 | + if (isset($this->duration)) {
|
|
| 64 | + $httpBody .= '&duration=' . $this->duration; |
|
| 65 | + } |
|
| 56 | 66 | return array(true, "valid", $httpBody); //视频转码参数合法,返回http请求体 |
| 57 | 67 | } |
| 58 | 68 | /*######################以下是可选的参数set方法#######################*/ |
@@ -93,10 +103,13 @@ discard block |
||
| 93 | 103 | public function checkOptionParameters() |
| 94 | 104 | {
|
| 95 | 105 | list($valid, $msg) = parent::checkOptionParameters(); //检测输入输出资源是否合法 |
| 96 | - if (!$valid) |
|
| 97 | - return array($valid, $msg, null); |
|
| 98 | - if (empty($this->time) || !is_int($this->time) || $this->time < 0) |
|
| 99 | - return array(false, "time is empty or invalid.", null); // 是否设置时间,且时间是否合法 |
|
| 106 | + if (!$valid) {
|
|
| 107 | + return array($valid, $msg, null); |
|
| 108 | + } |
|
| 109 | + if (empty($this->time) || !is_int($this->time) || $this->time < 0) {
|
|
| 110 | + return array(false, "time is empty or invalid.", null); |
|
| 111 | + } |
|
| 112 | + // 是否设置时间,且时间是否合法 |
|
| 100 | 113 | return $this->getOptionsHttpBody(); //返回http请求体 |
| 101 | 114 | } |
| 102 | 115 | |
@@ -108,8 +121,9 @@ discard block |
||
| 108 | 121 | $httpBody .= '&output=' . $this->getOutputResId(); |
| 109 | 122 | $httpBody .= '&time=' . $this->time; |
| 110 | 123 | // 可选的参数 |
| 111 | - if (isset($this->notifyUrl)) |
|
| 112 | - $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl); |
|
| 124 | + if (isset($this->notifyUrl)) {
|
|
| 125 | + $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl); |
|
| 126 | + } |
|
| 113 | 127 | return array(true, "valid", $httpBody); //视频转码参数合法,返回http请求体 |
| 114 | 128 | } |
| 115 | 129 | |
@@ -142,14 +156,18 @@ discard block |
||
| 142 | 156 | /**检测参数选项是否合法*/ |
| 143 | 157 | public function checkOptionParameters() |
| 144 | 158 | {
|
| 145 | - if (empty($this->input) || empty($this->output)) |
|
| 146 | - return array(false, "input or output resources is empty."); // 判断是否设置输入输出文件,或者转码模板 |
|
| 159 | + if (empty($this->input) || empty($this->output)) {
|
|
| 160 | + return array(false, "input or output resources is empty."); |
|
| 161 | + } |
|
| 162 | + // 判断是否设置输入输出文件,或者转码模板 |
|
| 147 | 163 | list($valid, $msg) = $this->input->checkResourceInfo(true, true); //检测输入的资源信息是否合法 |
| 148 | - if (!$valid) |
|
| 149 | - return array($valid, $msg); |
|
| 164 | + if (!$valid) {
|
|
| 165 | + return array($valid, $msg); |
|
| 166 | + } |
|
| 150 | 167 | list($valid, $msg) = $this->output->checkResourceInfo(true, true); //检测输入的资源信息是否合法 |
| 151 | - if (!$valid) |
|
| 152 | - return array($valid, $msg); |
|
| 168 | + if (!$valid) {
|
|
| 169 | + return array($valid, $msg); |
|
| 170 | + } |
|
| 153 | 171 | return array(true, null); |
| 154 | 172 | } |
| 155 | 173 | public function getInputResId() |