コード例 #1
0
 public function get_transcode_task_info($arr)
 {
     $trans = new transcode($arr);
     $ret = $trans->get_transcode_status();
     $ret = json_decode($ret, 1);
     return $ret;
 }
コード例 #2
0
 public function run()
 {
     /**************************************查询出数据库里面正在转码的视频******************************************/
     $sql = "SELECT * FROM " . DB_PREFIX . "vodinfo WHERE status = 0  AND vod_leixing != 4 ";
     $q = $this->db->query($sql);
     $videos = array();
     while ($r = $this->db->fetch_array($q)) {
         $videos[] = $r['id'];
     }
     if (!$videos) {
         $this->errorOutput(NO_VIDEO_IS_TRANSCODING);
     }
     /**************************************查询出当前正在开启的服务器********************************************/
     $sql = " SELECT * FROM " . DB_PREFIX . "transcode_center WHERE is_open = 1 ";
     $q = $this->db->query($sql);
     $servers = array();
     while ($r = $this->db->fetch_array($q)) {
         $servers[] = $r;
     }
     if (!$servers) {
         $this->errorOutput(NO_TRANSERVER_CAN_USE);
     }
     /**************************************查询出所有正在使用的转码服务器中正在转码的视频*****************************/
     $ids = array();
     //存储正在转码中视频id
     foreach ($servers as $k => $v) {
         $trans = new transcode(array('host' => $v['trans_host'], 'port' => $v['trans_port']));
         $task = json_decode($trans->get_transcode_status(), 1);
         if ($task['return'] == 'success' && $task['running']) {
             if ($task['waiting']) {
                 $task['running'] = array_merge($task['running'], $task['waiting']);
             }
             foreach ($task['running'] as $_k => $_v) {
                 if (!in_array($_v['id'], $ids)) {
                     $ids[] = $_v['id'];
                 }
             }
         }
     }
     /***************算出页面中正在转码的视频与实际服务器中转码视频以及等待的视频的差集,算出来视频id就是遗漏的视频**************/
     $diffIds = array_diff($videos, $ids);
     if (!$diffIds) {
         $this->errorOutput(NO_VIDEO_LEAVE_OUT);
     }
     //将找出遗漏的视频提交重新转码
     $curl = new curl($this->settings['App_mediaserver']['host'], $this->settings['App_mediaserver']['dir'] . 'admin/');
     $curl->setSubmitType('get');
     foreach ($diffIds as $k => $v) {
         $curl->initPostData();
         $curl->addRequestData('id', $v);
         $curl->addRequestData('force_recodec', 1);
         $curl->request('retranscode.php');
     }
     $this->addItem('遗漏的视频:' . implode(',', $diffIds) . '已经提交重新转码');
     $this->output();
 }
コード例 #3
0
 public function run()
 {
     /**************************************查询出数据库里面经过多码流但未成功的视频**********************************/
     $sql = "SELECT * FROM " . DB_PREFIX . "vodinfo WHERE is_morebitrate = 0 AND clarity != '' ";
     $q = $this->db->query($sql);
     $videos = array();
     while ($r = $this->db->fetch_array($q)) {
         $videos[] = $r['id'] . '_more';
         //多码流的任务格式
     }
     if (!$videos) {
         $this->errorOutput(NO_FAILED_VIDEOS_FROM_MORE);
     }
     /**************************************查询出当前正在开启的服务器********************************************/
     $sql = " SELECT * FROM " . DB_PREFIX . "transcode_center WHERE is_open = 1 ";
     $q = $this->db->query($sql);
     $servers = array();
     while ($r = $this->db->fetch_array($q)) {
         $servers[] = $r;
     }
     if (!$servers) {
         $this->errorOutput(NO_TRANSERVER_CAN_USE);
     }
     /**************************************查询出所有正在使用的转码服务器中正在转码的视频*****************************/
     $ids = array();
     //存储正在转码中视频id
     foreach ($servers as $k => $v) {
         $trans = new transcode(array('host' => $v['trans_host'], 'port' => $v['trans_port']));
         $task = json_decode($trans->get_transcode_status(), 1);
         if ($task['return'] == 'success' && $task['running']) {
             if ($task['waiting']) {
                 $task['running'] = array_merge($task['running'], $task['waiting']);
             }
             foreach ($task['running'] as $_k => $_v) {
                 if (!in_array($_v['id'], $ids)) {
                     $ids[] = $_v['id'];
                 }
             }
         }
     }
     /***************算出失败的视频与实际服务器中转码视频以及等待的视频的差集,算出来视频id就是正真多码流失败的视频**************/
     $diffIds = array_diff($videos, $ids);
     if (!$diffIds) {
         $this->errorOutput(NO_VIDEO_LEAVE_OUT);
     }
     $real_failed = array();
     foreach ($diffIds as $v) {
         $real_failed[] = str_replace('_more', '', $v);
     }
     //更新数据库
     $sql = "UPDATE " . DB_PREFIX . "vodinfo SET clarity = '' WHERE id IN (" . implode(',', $real_failed) . ")";
     $this->db->query($sql);
     $this->addItem('多码流失败的视频:' . implode(',', $diffIds) . '已经提交处理');
     $this->output();
 }
コード例 #4
0
ファイル: functions.php プロジェクト: h3len/Project
function checkStatusFromAllServers($id = '')
{
    if (!$id) {
        return false;
    }
    //获取开启的转码服务器
    if (!($servers = hg_get_transcode_servers())) {
        return false;
    }
    if (!class_exists('transcode')) {
        include_once CUR_CONF_PATH . 'lib/transcode.class.php';
    }
    foreach ($servers as $k => $v) {
        $t_server = array('host' => $v['trans_host'], 'port' => $v['trans_port']);
        $transcode = new transcode($t_server);
        $ret = $transcode->get_transcode_status("{$id}");
        //返回状态
        $ret = json_decode($ret, 1);
        //查询到有该任务并且不是回调失败
        if ($ret['return'] == 'success' && $ret['status'] != 'callback_failed') {
            return $t_server;
        }
    }
    return false;
}
コード例 #5
0
 public function count()
 {
     if (!$this->input['server_id']) {
         $this->errorOutput(NO_SERVER_ID);
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "transcode_center  WHERE id = '" . intval($this->input['server_id']) . "'";
     $arr = $this->db->query_first($sql);
     $trans = new transcode(array('host' => $arr['trans_host'], 'port' => $arr['trans_port']));
     $ret = $trans->get_transcode_status();
     $ret = json_decode($ret, 1);
     $total = count($ret['running']) + count($ret['waiting']);
     echo json_encode($total);
 }