video_factory.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <?php
  2. /* API 文档
  3. * 点播 https://www.qcloud.com/doc/api/257/1965
  4. */
  5. class VideoFactory
  6. {
  7. public function __construct($m_config = array())
  8. {
  9. if (empty($m_config)) {
  10. $m_config = load_auto_cache("m_config");
  11. }
  12. $this->config = array(
  13. 'SecretId' => $m_config['qcloud_secret_id'],
  14. 'SecretKey' => $m_config['qcloud_secret_key'],
  15. 'RequestMethod' => 'GET',
  16. 'DefaultRegion' => 'gz'
  17. );
  18. fanwe_require(APP_ROOT_PATH . 'system/QcloudApi/QcloudApi.php');
  19. }
  20. private function loadService($module_name)
  21. {
  22. return QcloudApi::load($module_name, $this->config);
  23. }
  24. public function GetVodRecordFiles($channel_id, $begin_time)
  25. {
  26. $m_config = load_auto_cache('m_config');
  27. // 0:腾讯云互动直播, 1:腾讯云直播, 2:金山云,3:星域,4:方维云
  28. if ($m_config['video_type'] == 2) {
  29. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_ksyun.php');
  30. $service = new VideoKsyun($m_config);
  31. return $service->GetRecord($channel_id);
  32. }
  33. if ($m_config['video_type'] == 4) {
  34. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_fanwe.php');
  35. $service = new VideoFanwe($m_config);
  36. $data = $service->GetRecord($channel_id);
  37. return array('totalCount' => count($data), 'urls' => $data);
  38. }
  39. if ($m_config['video_type'] == 5) {
  40. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_aliyun.php');
  41. $service = new VideoAliyun($m_config);
  42. return $service->GetRecord($channel_id);
  43. }
  44. if (!empty($m_config['qcloud_security_key'])) {
  45. //直播码 方式
  46. return $this->GetZhibomaRecordFiles($channel_id);
  47. } else {
  48. $service = $this->loadService(QcloudApi::MODULE_LIVE);
  49. $ret = $service->GetVodRecordFiles(array(
  50. 'channelId' => $channel_id,
  51. 'startTime' => to_date($begin_time, 'Y-m-d H:i:s'),
  52. ));
  53. if ($ret === false) {
  54. // 请求失败,解析错误信息
  55. $error = $service->getError();
  56. return array(
  57. 'status' => 0,
  58. 'error' => $error->getMessage(),
  59. );
  60. }
  61. return $ret;
  62. }
  63. }
  64. public function GetZhibomaRecordFiles($channel_id)
  65. {
  66. $m_config = load_auto_cache('m_config');
  67. $key = $m_config['qcloud_auth_key'];
  68. $t = get_gmtime() + 86400;
  69. $url = "http://fcgi.video.qcloud.com/common_access?" . http_build_query(array(
  70. 'cmd' => $m_config['vodset_app_id'],
  71. 'interface' => 'Live_Tape_GetFilelist',
  72. 't' => $t,
  73. 'sign' => md5($key . $t),
  74. 'Param.s.channel_id' => $channel_id,
  75. ));
  76. $res = $this->accessService($url);
  77. $filesInfo = array();
  78. foreach ($res['output']['file_list'] as $file) {
  79. $filesInfo[] = array(
  80. 'fileId' => $file['file_id'],
  81. );
  82. }
  83. return array('status' => 1, 'totalCount' => $res['output']['all_count'], 'filesInfo' => $filesInfo);
  84. }
  85. public function GetVodUrls($channel_id, $begin_time)
  86. {
  87. $ret = $this->GetVodRecordFiles($channel_id, $begin_time);
  88. if (empty($ret['filesInfo'])) {
  89. return array(
  90. 'status' => 0,
  91. 'error' => 'has no file',
  92. );
  93. }
  94. $file_id = $ret['filesInfo'][0]['fileId'];
  95. $service = $this->loadService(QcloudApi::MODULE_VOD);
  96. $ret = $service->DescribeVodPlayUrls(array('fileId' => $file_id));
  97. if ($ret === false) {
  98. // 请求失败,解析错误信息
  99. $error = $service->getError();
  100. return array(
  101. 'status' => 0,
  102. 'error' => $error->getMessage(),
  103. );
  104. }
  105. if (count($ret['playSet']) == 1 && $ret['playSet'][0]['definition'] == 0) {
  106. $ret['playSet'][0]['definition'] = 20;
  107. }
  108. $urls = array();
  109. foreach ($ret['playSet'] as $play) {
  110. $urls[$play['definition']] = $play['url'];
  111. }
  112. return array(
  113. 'status' => 1,
  114. 'file_id' => $file_id,
  115. 'urls' => $urls,
  116. );
  117. }
  118. public function DescribeVodPlayUrls($file_id)
  119. {
  120. if (!$file_id) {
  121. return array(
  122. 'status' => 0,
  123. 'error' => 'file_id invalid',
  124. );
  125. }
  126. $service = $this->loadService(QcloudApi::MODULE_VOD);
  127. $ret = $service->DescribeVodPlayUrls(array('fileId' => $file_id));
  128. if ($ret === false) {
  129. // 请求失败,解析错误信息
  130. $error = $service->getError();
  131. return array(
  132. 'status' => 0,
  133. 'error' => $error->getMessage(),
  134. );
  135. }
  136. if (count($ret['playSet']) == 1 && $ret['playSet'][0]['definition'] == 0) {
  137. $ext = substr($ret['playSet'][0]['url'], strrpos($ret['playSet'][0]['url'], '.') + 1);
  138. if($ext == 'm3u8') {
  139. $ret['playSet'][0]['definition'] = 210;
  140. } else {
  141. $ret['playSet'][0]['definition'] = 20;
  142. }
  143. }
  144. $urls = array();
  145. foreach ($ret['playSet'] as $play) {
  146. $urls[$play['definition']] = $play['url'];
  147. }
  148. return array(
  149. 'file_id' => $file_id,
  150. 'urls' => $urls,
  151. );
  152. }
  153. public function StopLVBChannel($channel_id)
  154. {
  155. if (!$channel_id) {
  156. return array(
  157. 'status' => 0,
  158. );
  159. }
  160. $m_config = load_auto_cache('m_config');
  161. // 0:腾讯云互动直播, 1:腾讯云直播, 2:金山云,3:星域,4:方维云
  162. if ($m_config['video_type'] == 2) {
  163. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_ksyun.php');
  164. $service = new VideoKsyun($m_config);
  165. return $service->Stop($channel_id);
  166. }
  167. if ($m_config['video_type'] == 4) {
  168. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_fanwe.php');
  169. $service = new VideoFanwe($m_config);
  170. return $service->Stop($channel_id);
  171. }
  172. if ($m_config['video_type'] == 5) {
  173. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_aliyun.php');
  174. $service = new VideoAliyun($m_config);
  175. return $service->Stop($channel_id);
  176. }
  177. if (!empty($m_config['qcloud_security_key'])) {
  178. //直播码 方式
  179. return $this->StopZhibomaChannel($channel_id);
  180. } else {
  181. $service = $this->loadService(QcloudApi::MODULE_LIVE);
  182. $ret = $service->StopLVBChannel(array('channelIds.1' => $channel_id));
  183. if ($ret === false) {
  184. // 请求失败,解析错误信息
  185. $error = $service->getError();
  186. return array(
  187. 'status' => 0,
  188. 'error' => $error->getMessage(),
  189. );
  190. }
  191. return array('status' => 1, 'channel_id' => $channel_id);
  192. }
  193. }
  194. public function StopZhibomaChannel($channel_id)
  195. {
  196. $m_config = load_auto_cache('m_config');
  197. $key = $m_config['qcloud_auth_key'];
  198. $t = get_gmtime() + 86400;
  199. $url = "http://fcgi.video.qcloud.com/common_access?" . http_build_query(array(
  200. 'cmd' => $m_config['vodset_app_id'],
  201. 'interface' => 'Live_Channel_SetStatus',
  202. 't' => $t,
  203. 'sign' => md5($key . $t),
  204. 'Param.s.channel_id' => $channel_id,
  205. 'Param.n.status' => 0,
  206. ));
  207. $this->accessService($url);
  208. return array('status' => 1, 'channel_id' => $channel_id);
  209. }
  210. public function Query($channel_id)
  211. {
  212. if (!$channel_id) {
  213. return array(
  214. 'status' => 0,
  215. );
  216. }
  217. $m_config = load_auto_cache('m_config');
  218. // 0:腾讯云互动直播, 1:腾讯云直播, 2:金山云,3:星域,4:方维云
  219. if ($m_config['video_type'] == 2) {
  220. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_ksyun.php');
  221. $service = new VideoKsyun($m_config);
  222. $data = $service->Query($channel_id);
  223. return array(
  224. 'channel_id' => $channel_id,
  225. 'status' => $data['stream_status'],
  226. );
  227. }
  228. if ($m_config['video_type'] == 4) {
  229. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_fanwe.php');
  230. $service = new VideoFanwe($m_config);
  231. return $service->Query($channel_id);
  232. }
  233. if ($m_config['video_type'] == 5) {
  234. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_aliyun.php');
  235. $service = new VideoAliyun($m_config);
  236. $data = $service->Query($channel_id);
  237. return array(
  238. 'channel_id' => $channel_id,
  239. 'status' => $data['stream_status'],
  240. );
  241. }
  242. if (empty($m_config['qcloud_security_key'])) {
  243. $service = $this->loadService(QcloudApi::MODULE_LIVE);
  244. $package = array(
  245. 'channelId' => $channel_id,
  246. );
  247. $ret = $service->DescribeLVBChannel($package);
  248. if ($ret === false) {
  249. // 请求失败,解析错误信息
  250. $error = $service->getError();
  251. return array(
  252. 'status' => 0,
  253. 'error' => $error->getMessage(),
  254. );
  255. }
  256. $channel_info = $ret['channelInfo'][0];
  257. $upstream_address = $channel_info['upstream_list'][0]['sourceAddress'];
  258. return array(
  259. 'channel_id' => $channel_info['channel_id'],
  260. 'status' => $channel_info['channel_status'],
  261. 'upstream_address' => $upstream_address . "&record=flv",
  262. 'downstream_address' => array(
  263. 'rtmp' => $channel_info['rtmp_downstream_address'],
  264. 'hls' => $channel_info['hls_downstream_address'],
  265. 'flv' => $channel_info['flv_downstream_address'],
  266. ),
  267. );
  268. } else {
  269. $key = $m_config['qcloud_auth_key'];
  270. $t = get_gmtime() + 86400;
  271. $url = "http://fcgi.video.qcloud.com/common_access?" . http_build_query(array(
  272. 'cmd' => $m_config['vodset_app_id'],
  273. 'interface' => 'Live_Channel_GetStatus',
  274. 't' => $t,
  275. 'sign' => md5($key . $t),
  276. 'Param.s.channel_id' => $channel_id,
  277. ));
  278. $res = $this->accessService($url);
  279. $channel_info = array();
  280. $channel_info['status'] = $res['output'][0]['status'];
  281. return $channel_info;
  282. }
  283. }
  284. private function accessService($url)
  285. {
  286. $ch = curl_init($url);
  287. curl_setopt($ch, CURLOPT_HEADER, false);
  288. curl_setopt($ch, CURLOPT_NOBODY, false); //对body进行输出。
  289. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  290. $package = curl_exec($ch);
  291. $res = json_decode($package, true);
  292. if ($res['ret']) {
  293. return array(
  294. 'status' => 0,
  295. 'error' => $res['message'],
  296. );
  297. }
  298. return $res;
  299. }
  300. /*
  301. * outputSourceType 1表示只有RTMP输出,2表示只有HLS输出,3表示两者都有
  302. */
  303. public function Create($video_id, $record = 'mp4', $user_id = 0, $is_private = 0)
  304. {
  305. $m_config = load_auto_cache('m_config');
  306. // 0:腾讯云互动直播, 1:腾讯云直播, 2:金山云,3:星域,4:方维云,5:阿里云
  307. if ($m_config['video_type'] == 2) {
  308. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_ksyun.php');
  309. $service = new VideoKsyun($m_config);
  310. $data = $service->Create($video_id);
  311. return array(
  312. 'channel_id' => $data['stream_id'],
  313. 'upstream_address' => $data['push_rtmp'],
  314. 'downstream_address' => array(
  315. 'rtmp' => $data['play_rtmp'],
  316. 'flv' => $data['play_flv'],
  317. 'hls' => $data['play_hls'],
  318. ),
  319. );
  320. }
  321. if ($m_config['video_type'] == 4) {
  322. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_fanwe.php');
  323. $service = new VideoFanwe($m_config);
  324. return $service->Create($video_id);
  325. }
  326. if ($m_config['video_type'] == 5) {
  327. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_aliyun.php');
  328. $service = new VideoAliyun($m_config);
  329. $data = $service->Create($video_id);
  330. if($data['status'] == 0){
  331. ajax_return($data);
  332. }
  333. return array(
  334. 'channel_id' => $data['stream_id'],
  335. 'upstream_address' => $data['push_rtmp'],
  336. 'downstream_address' => array(
  337. 'rtmp' => $data['play_rtmp'],
  338. 'flv' => $data['play_flv'],
  339. 'hls' => $data['play_hls'],
  340. ),
  341. );
  342. }
  343. if (!empty($m_config['qcloud_security_key'])) {
  344. //直播码 方式
  345. return $this->GetChannelInfo($video_id, 'b', $video_id, $user_id, $is_private, $record);
  346. } else {
  347. $service = $this->loadService(QcloudApi::MODULE_LIVE);
  348. $package = array(
  349. 'channelName' => $video_id,
  350. 'outputSourceType' => 3,
  351. 'sourceList.1.name' => $video_id,
  352. 'sourceList.1.type' => 1,
  353. );
  354. $ret = $service->CreateLVBChannel($package);
  355. if ($ret === false) {
  356. // 请求失败,解析错误信息
  357. $error = $service->getError();
  358. ajax_return(array(
  359. 'status' => 0,
  360. 'error' => $error->getMessage(),
  361. ));
  362. }
  363. $channel_id = $ret['channel_id'];
  364. $upstream_address = $ret['channelInfo']['upstream_address'];
  365. $downstream_address = $ret['channelInfo']['downstream_address'][0];
  366. //在返回的hls地址中,加入/live/这一层
  367. //@author jiangzuru
  368. $s1 = $downstream_address['hls_downstream_address'];
  369. if (strpos($s1, "com/live/") === false) {
  370. $pos1 = strpos($s1, "com/");
  371. $downstream_address['hls_downstream_address'] = substr_replace($s1, "live/", $pos1 + 4, 0);
  372. }
  373. //后台开启录制 或者 非私密直播 录制视频
  374. $has_save_video = intval($m_config['has_save_video']);
  375. $save_video = '';
  376. if ($has_save_video && $is_private != 1) {
  377. $save_video = "&record=" . $record . "&record_interval=5400";
  378. }
  379. return array(
  380. 'channel_id' => $channel_id,
  381. 'upstream_address' => $upstream_address . $save_video,
  382. 'downstream_address' => array(
  383. 'rtmp' => $downstream_address['rtmp_downstream_address'],
  384. 'flv' => $downstream_address['flv_downstream_address'],
  385. 'hls' => $downstream_address['hls_downstream_address'],
  386. ),
  387. );
  388. }
  389. }
  390. public function GetChannelInfo(
  391. $video_id,
  392. $layer = 'b',
  393. $session_id = 0,
  394. $user_id = 0,
  395. $is_private = 0,
  396. $record = 'mp4'
  397. ) {
  398. $m_config = load_auto_cache('m_config');
  399. $bizId = $m_config['qcloud_bizid'];
  400. $key = $m_config['qcloud_security_key'];
  401. $stream_id = $session_id . $layer . $user_id . "_" . substr(md5($video_id . microtime_float()), 12);
  402. if ($session_id == 0) {
  403. $session_id = $video_id;
  404. }
  405. //格式化,补足32长
  406. //$session_id = str_pad($session_id,32,'0',STR_PAD_LEFT);
  407. $time = to_date(get_gmtime() + 86400, 'Y-m-d H:i:s');
  408. $txTime = strtoupper(base_convert(strtotime($time), 10, 16));
  409. //$stream_id = bizid+"_"+stream_id 如 8888_test123456
  410. $stream_id = $bizId . "_" . $stream_id; //直播码
  411. // 24小时失效
  412. $ext_str = $this->get_acc_sign($key, $stream_id, 86400);
  413. $ext_str = "?bizid=" . $bizId . "&" . $ext_str . "&mix=layer:{$layer};session_id:{$session_id};t_id:1";
  414. $upstream_address = "rtmp://" . $bizId . ".livepush.myqcloud.com/live/" . $stream_id . $ext_str;
  415. //后台开启录制 或者 非私密直播 录制视频
  416. $has_save_video = intval($m_config['has_save_video']);
  417. $save_video = '';
  418. if ($has_save_video && $is_private != 1) {
  419. $save_video = "&record=" . $record . "&record_interval=5400";
  420. }
  421. return array(
  422. 'channel_id' => $stream_id,
  423. 'upstream_address' => $upstream_address . $save_video,
  424. 'downstream_address' => array(
  425. 'rtmp' => "rtmp://" . $bizId . ".liveplay.myqcloud.com/live/" . $stream_id,
  426. 'flv' => "http://" . $bizId . ".liveplay.myqcloud.com/live/" . $stream_id . ".flv",
  427. 'hls' => "http://" . $bizId . ".liveplay.myqcloud.com/live/" . $stream_id . ".m3u8"
  428. ),
  429. );
  430. }
  431. public function get_acc_sign($key, $stream_id, $len = 300)
  432. {
  433. $time = to_date(get_gmtime() + $len, 'Y-m-d H:i:s');
  434. //$time = '2017-01-22 23:59:59';
  435. $txTime = strtoupper(base_convert(strtotime($time), 10, 16));
  436. //txSecret的生成方法是 = MD5(KEY+ stream_id + txTime)
  437. $txSecret = md5($key . $stream_id . $txTime);
  438. $ext_str = http_build_query(array(
  439. "txSecret" => $txSecret,
  440. "txTime" => $txTime,
  441. ));
  442. return $ext_str;
  443. }
  444. public function Sign($arg_str)
  445. {
  446. $m_config = load_auto_cache("m_config");
  447. return base64_encode(hash_hmac('sha1', $arg_str, $m_config['qcloud_secret_key'], true));
  448. }
  449. public function NewSign(){
  450. $m_config = load_auto_cache("m_config");
  451. $secret_id = $m_config['qcloud_secret_id'];
  452. $secret_key = $m_config['qcloud_secret_key'];
  453. // 确定签名的当前时间和失效时间
  454. $current = time();
  455. $expired = $current + 86400; // 签名有效期:1天
  456. // 向参数列表填入参数
  457. $arg_list = array(
  458. "secretId" => $secret_id,
  459. "currentTimeStamp" => $current,
  460. "expireTime" => $expired,
  461. "random" => rand());
  462. // 计算签名
  463. $orignal = http_build_query($arg_list);
  464. $signature = base64_encode(hash_hmac('SHA1', $orignal, $secret_key, true).$orignal);
  465. return $signature;
  466. }
  467. //删除视频
  468. public function DeleteVodFiles($channel_id, $begin_time)
  469. {
  470. $ret = $this->GetVodRecordFiles($channel_id, $begin_time);
  471. $delvodset = array();
  472. $service = $this->loadService(QcloudApi::MODULE_VOD);
  473. foreach ($ret['filesInfo'] as $file_info) {
  474. $file_id = $file_info['fileId'];
  475. $delvodset[$file_id] = $service->DeleteVodFile(array('fileId' => $file_id, 'priority' => 0));
  476. }
  477. return $delvodset;
  478. }
  479. public function DeleteVodFilesByFileName($file_name)
  480. {
  481. $ret = $this->DescribeVodPlayInfo($file_name);
  482. $delvodset = array();
  483. $service = $this->loadService(QcloudApi::MODULE_VOD);
  484. foreach ($ret['fileSet'] as $file_info) {
  485. $file_id = $file_info['fileId'];
  486. $delvodset[$file_id] = $service->DeleteVodFile(array('fileId' => $file_id, 'priority' => 0));
  487. }
  488. return $delvodset;
  489. }
  490. public function DescribeVodPlayInfo($file_name)
  491. {
  492. $service = $this->loadService(QcloudApi::MODULE_VOD);
  493. $ret = $service->DescribeVodPlayInfo(array('fileName' => $file_name));
  494. if ($ret === false) {
  495. // 请求失败,解析错误信息
  496. $error = $service->getError();
  497. return array(
  498. 'status' => 0,
  499. 'error' => $error->getMessage(),
  500. );
  501. }
  502. return $ret;
  503. }
  504. public function ModifyVodInfo($file_id, $data)
  505. {
  506. $file_name = $data['id'] . '_' . to_date($data['begin_time'],
  507. 'Y-m-d-H-i-s') . '_' . to_date($data['begin_time'], 'Y-m-d-H-i-s');
  508. $service = $this->loadService(QcloudApi::MODULE_VOD);
  509. $ret = $service->ModifyVodInfo(array(
  510. 'fileId' => $file_id,
  511. 'fileName' => $file_name,
  512. ));
  513. if ($ret === false) {
  514. // 请求失败,解析错误信息
  515. $error = $service->getError();
  516. return array(
  517. 'status' => 0,
  518. 'error' => $error->getMessage(),
  519. );
  520. }
  521. return $file_name;
  522. }
  523. /** 文档地址 https://www.qcloud.com/document/product/266/1393
  524. * @param $url
  525. */
  526. public function MultiPullVodFile($url, $video_id, $begin_time)
  527. {
  528. $service = $this->loadService(QcloudApi::MODULE_VOD);
  529. $file_name = $video_id . '_' . to_date($begin_time,
  530. 'Y-m-d-H-i-s') . '_' . to_date($begin_time, 'Y-m-d-H-i-s');
  531. $ret = $service->MultiPullVodFile(array(
  532. 'pullset.1.url' => $url,
  533. 'pullset.1.fileName' => $file_name,
  534. ));
  535. if ($ret === false) {
  536. // 请求失败,解析错误信息
  537. $error = $service->getError();
  538. return array(
  539. 'status' => 0,
  540. 'error' => $error->getMessage(),
  541. );
  542. }
  543. return $ret;
  544. }
  545. /**
  546. * 视频拼接 https://www.qcloud.com/document/product/266/7821
  547. * @param unknown_type $channel_id
  548. * @return multitype:number NULL multitype:multitype:unknown
  549. */
  550. public function ConcatVideo($channel_id, $new_file_name)
  551. {
  552. $res = $this->GetZhibomaRecordFiles($channel_id);
  553. if ($res['totalCount'] > 1) {
  554. $params = array();
  555. $params['name'] = $new_file_name;
  556. $params['dstType.0'] = 'mp4';
  557. $i = 0;
  558. foreach ($res['filesInfo'] as $file) {
  559. $params['srcFileList.' . $i . '.fileId'] = $file['fileId'];
  560. $i = $i + 1;
  561. }
  562. $service = $this->loadService(QcloudApi::MODULE_VOD);
  563. $ret = $service->ConcatVideo($params);
  564. /*
  565. array (
  566. 'codeDesc' => 'Success',
  567. 'vodTaskId' => 'concat-d0cef54c78075e5657dc934fc1b38d98',
  568. )
  569. */
  570. if ($ret['codeDesc'] != 'Success') {
  571. // 请求失败,解析错误信息
  572. $error = $service->getError();
  573. return array(
  574. 'status' => 0,
  575. 'v_status' => 0,
  576. 'error' => $error->getMessage(),
  577. );
  578. } else {
  579. //code 错误码, 0: 成功, 其他值: 失败
  580. //vodTaskId 描述拼接任务的唯一id,可以通过此id查询任务状态
  581. return array(
  582. 'status' => 1,
  583. 'v_status' => 1,
  584. 'error' => '合并任务已提交,请等待合并,大致需要5分钟',
  585. 'vodtaskid' => $ret['vodTaskId'],
  586. );
  587. }
  588. } else {
  589. //只有一个文件时,不需要调用:合并视频功能
  590. return array(
  591. 'status' => 1,
  592. 'v_status' => 0,
  593. 'error' => '单文件视频不需要合并',
  594. );
  595. }
  596. }
  597. }