public function testRequest() { $operatorName = getenv('UPYUN_OPERATOR_NAME'); $operatorPwd = getenv('UPYUN_OPERATOR_PWD'); $bucketName = getenv('UPYUN_FILE_BUCKET'); $sugar = new \Sugar\AvPretreatment($operatorName, $operatorPwd); $data = array('bucket_name' => $bucketName, 'source' => '/video/20130514_190031.mp4', 'notify_url' => 'http://your.notifyurl.com/', 'tasks' => array(array('type' => 'hls', 'hls_time' => 6, 'bitrate' => '500', 'rotate' => 'auto', 'format' => 'mp4'), array('type' => 'thumbnail', 'thumb_single' => false, 'thumb_amount' => 100, 'format' => 'png'))); $sugar->request($data); $ids = $sugar->getTaskIds(); $this->assertEquals(2, count($ids)); }
public function get_transcode_progress_bar() { $video_id = $this->input['id'] ? explode(',', $this->input['id']) : array(); if (!$video_id) { return; } $_task_ids = array(); $completed = array(); foreach ($video_id as $id) { $file = CACHE_DIR . $id . '.data'; if (!file_exists($file)) { $completed[$id] = 100; } else { $task_ids = @file_get_contents($file); if ($task_ids) { $task_ids = explode('|', $task_ids); if ($task_ids[0] == '*') { $completed[$id] = 100; } else { $_task_ids[$id] = $task_ids[0]; } } } } $output = array(); if ($_task_ids) { try { $sugar = new \Sugar\AvPretreatment(SPACEOPERATORS, SPACEOPERATORSPASSWORD, TRANSCODE_PROGRESS_BAR); //操作员的帐号密码 $data = array('bucket_name' => $this->user['extend']['bucket_name']['value'], 'task_ids' => implode(',', $_task_ids)); //返回对应的任务ids $progress = $sugar->request($data, 3, 'GET'); if (is_array($progress['tasks']) && !empty($progress['tasks'])) { foreach ($progress['tasks'] as $tid => $progress_value) { $output[array_search($tid, $_task_ids)] = $progress_value; } } } catch (\Exception $e) { //echo "request failed:", $e->getMessage(); $this->addItem_withkey('error', $e->getMessage()); $this->output(); } } if ($output) { foreach ($output as $vid => $val) { $completed[$vid] = $val; } } $this->addItem_withkey('progress', $completed); $this->output(); }
public function transcode($param) { if (!$param) { return false; } $filepath = $param['url']; $sugar = new \Sugar\AvPretreatment(SPACEOPERATORS, SPACEOPERATORSPASSWORD); //操作员的帐号密码 $data = array('bucket_name' => $this->user['extend']['bucket_name']['value'], 'source' => $filepath, 'notify_url' => $this->settings['form_api_param']['notify-url'] . 'callback_type=transcode&video_id=' . $param['video_id'] . '&access_token=' . $this->user['token'] . '&upload_type=' . $param['ext-param']['upload_type'], 'tasks' => array(array('type' => 'hls', 'hls_time' => 6, 'bitrate' => DEFAULT_BITRATE, 'rotate' => 'auto'), array('type' => 'thumbnail', 'thumb_single' => false, 'thumb_amount' => 1, 'thumb_start' => DEFAULT_IMG_START, 'format' => 'png'), array('type' => 'video', 'return_info' => true, 'bitrate' => DEFAULT_BITRATE))); if ($param['ext-param']['client_id']) { $data['notify_url'] .= '&client_id=' . $param['ext-param']['client_id']; } //file_put_contents(CACHE_DIR . 'data.txt', var_export($data, 1), FILE_APPEND); try { //返回对应的任务ids $task_ids = $sugar->request($data); log2file($this->user, 'debug', '提交转码任务', $data, $task_ids); return $task_ids; } catch (\Exception $e) { //echo "request failed:", $e->getMessage(); //$this->addItem_withkey('error', $e->getMessage()); //$this->output(); log2file($this->user, 'error', $e->getMessage(), $data); } }