예제 #1
0
파일: yun.php 프로젝트: h3len/Project
 public function download_and_transcode()
 {
     //下载
     $data = $this->input;
     if (!$data) {
         return false;
     }
     $is_forcecode = intval($data['is_forcecode']);
     $url = $data['hostwork'] . '/' . $data['video_path'] . $data['video_filename'];
     //通过url下载视频
     $fileformat = substr($data['video_filename'], strrpos($data['video_filename'], '.'));
     $v_videodir = create_video_dir();
     $vod_dir_names = $v_videodir[0];
     $video_dir = $v_videodir[1];
     $filename = $vod_dir_names . $fileformat;
     $video_path = $video_dir;
     $video_base_path = TARGET_DIR;
     $video_filename = $filename;
     $source_hostwork = defined("SOURCE_VIDEO_DOMIAN") ? 'http://' . ltrim(SOURCE_VIDEO_DOMIAN, 'http://') : '';
     $source_base_path = UPLOAD_DIR;
     $source_path = 'yun/' . hg_build_dowload_dir();
     $source_filename = $data['video_filename'];
     $filepath = $source_base_path . $source_path;
     if (hg_mkdir($filepath)) {
         $file = file_get_contents($url);
         file_put_contents($filepath . $data['video_filename'], $file);
     }
     if (!hg_mkdir(TARGET_DIR . $video_dir) || !is_writeable(TARGET_DIR . $video_dir)) {
         $this->errorOutput(NOWRITE);
     }
     $sql = "UPDATE " . DB_PREFIX . "vodinfo SET source_hostwork='" . $source_hostwork . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t  video_base_path = '" . $video_base_path . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t  source_base_path = '" . $source_base_path . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t  source_path = '" . $source_path . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t  video_path = '" . $video_path . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t  video_filename = '" . $video_filename . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t  source_filename = '" . $source_filename . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t  is_forcecode = '" . $is_forcecode . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t  hostwork = 'http://" . TARGET_VIDEO_DOMAIN . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t  WHERE id = '" . $data['id'] . "'";
     $this->db->query($sql);
     if (defined('IS_TRANSCODE') && IS_TRANSCODE) {
         $sql = "UPDATE " . DB_PREFIX . "vodinfo SET status=0 WHERE id = '" . $data['id'] . "'";
         $this->db->query($sql);
         $ret = $this->submit_transcode($tr_data, $video_dir, $vod_dir_names, $data['id'], unserialize($data['img_info']));
         if (!$ret) {
             $ret['error'] = 'transcode';
         }
     } else {
         $target_file = TARGET_DIR . $video_path . $video_filename;
         $ret = copy($filepath . $data['video_filename'], $target_file);
         if (!$ret) {
             $ret['error'] = 'download';
         }
     }
     $this->publish_video($data['id'], 'insert');
     $this->addItem($ret);
     $this->output();
 }
예제 #2
0
파일: create.php 프로젝트: h3len/Project
 private function check_has_videofile($vod_config)
 {
     if (!$_FILES['videofile']['tmp_name']) {
         $this->errorOutput(NOFILE);
     }
     $original = rawurldecode($_FILES['videofile']['name']);
     if ($this->settings['video_cloud'] && $this->settings['video_file_cloud'] == 1) {
         include CUR_CONF_PATH . 'lib/cloud/' . $this->settings['video_cloud'] . '.php';
         $cloud = new $this->settings['video_cloud']();
         $cloud->setFiles($_FILES['videofile']);
         $cloud->setInput($this->input);
         $cloud->setSettings($this->settings);
         $ret = $cloud->upload();
         $videoinfo = $cloud->getVideoInfo();
         $this->input['content_id'] = $videoinfo['content_id'];
         $this->input['extend_data'] = $videoinfo['extend_data'];
         $this->input['notranscode'] = $videoinfo['notranscode'];
         $this->dir_info['original'] = $original;
         if ($ret != 'success') {
             $this->errorOutput($ret);
         }
         return 1;
     }
     //判断空间够不够存放视频
     if (function_exists('disk_free_space')) {
         if ($_FILES['videofile']['size'] > disk_free_space(UPLOAD_DIR)) {
             $this->errorOutput(DISC_SPACE_NOT_ENOUGH);
         }
     }
     $filetype = strtolower(strrchr($original, '.'));
     $allowtype = explode(',', $this->settings['video_type']['allow_type']);
     if (!in_array($filetype, $allowtype)) {
         $this->errorOutput(FORBIDTYPE);
     }
     $v_videodir = create_video_dir();
     $vod_dir_names = $v_videodir[0];
     $video_dir = $v_videodir[1];
     if (!hg_mkdir(UPLOAD_DIR . $video_dir) || !is_writeable(UPLOAD_DIR . $video_dir)) {
         $this->errorOutput(NOWRITE);
     }
     if (!hg_mkdir(TARGET_DIR . $video_dir) || !is_writeable(TARGET_DIR . $video_dir)) {
         $this->errorOutput(NOWRITE);
     }
     //将上传的文件移动到原视频目录
     $source_filename = 'video_' . $vod_dir_names . $filetype;
     $filepath = $video_dir . $source_filename;
     if (!@move_uploaded_file($_FILES['videofile']['tmp_name'], UPLOAD_DIR . $filepath)) {
         $this->errorOutput(FAILMOVE);
     }
     $this->dir_info = array('output_filename' => $vod_dir_names . '', 'output_format' => $vod_config['output_format'], 'target_dir' => $video_dir, 'source_filename' => $source_filename, 'filepath' => $filepath, 'original' => substr($original, 0, strrpos($original, '.')));
     return 0;
 }
예제 #3
0
파일: videomark.php 프로젝트: h3len/Project
 private function videomark($type)
 {
     if (!$this->input['id']) {
         $this->errorOutput(NOID);
         //任务id
     }
     $vid = intval($this->input['id']);
     $start = $this->input['start'];
     //对应每个视频片段的开始时间
     $duration = $this->input['duration'];
     //对应每个视频片段的时长
     $source_dir = $this->input['source_dir'];
     //视频片段的原文件目录
     $is_water_marked = $this->input['is_water_marked'];
     //视频片段的是否已经加过水印
     $is_forcecode = $this->input['is_forcecode'];
     //标识视频是否已经经过强制转码
     $video_base_path = $this->input['video_base_path'];
     //视频的基路径
     if (!is_array($start)) {
         foreach (array("start", "duration", "source_dir") as $v) {
             ${$v} = array(${$v});
         }
     }
     if (count($start) != count($duration) || count($start) != count($source_dir)) {
         $this->errorOutput(NOMATCH);
     }
     /****************查询视频配置信息*****************************/
     $vod_config = transcode_config();
     /***************配置一下转码完成之后视频的存放目录****************/
     if ($type == 'transcode_mark') {
         //判断当前该视频是不是正在转码,如果正在转码就删除该任务
         if ($t_server = checkStatusFromAllServers($vid)) {
             $s_tran = new transcode($t_server);
             $s_tran->stop_transcode_task($vid);
         }
         //拆条的时候要判断原视频是否正在转码中,如果正在转码中,暂时不拆条
         $sql = "SELECT * FROM " . DB_PREFIX . "vodinfo WHERE id = '" . $vid . "'";
         $cur_video = $this->db->query_first($sql);
         if ($cur_video['original_id']) {
             if (checkStatusFromAllServers($cur_video['original_id'])) {
                 $sql = " UPDATE " . DB_PREFIX . "vodinfo SET status = -1 WHERE id =  {$vid}";
                 $this->db->query($sql);
                 $this->addLogs('拆条有误', '', '', '当前拆条的原视频正在转码中,该视频id:' . $vid);
                 $this->errorOutput('当前拆条的原视频正在转码中,请稍后对该视频拆条');
             }
         }
         $v_videodir = create_video_dir();
         $vod_dir_names = $v_videodir[0];
         $target_dir = $v_videodir[1];
         $all_target_dir = TARGET_DIR . $target_dir;
         if (!hg_mkdir($all_target_dir) || !is_writeable($all_target_dir)) {
             $this->errorOutput(NOWRITE);
         }
         $output_filename = $vod_dir_names . '';
         //为了兼容老版本
         if (defined("TARGET_VIDEO_DOMAIN")) {
             $server_host = ltrim(TARGET_VIDEO_DOMAIN, 'http://');
         } else {
             $server_host = $this->settings['videouploads']['host'];
         }
         $sql = " UPDATE " . DB_PREFIX . "vodinfo SET video_base_path = '" . TARGET_DIR . "', video_path = '" . $target_dir . "',video_filename = '" . $output_filename . "." . $vod_config['output_format'] . "',hostwork = 'http://" . $server_host . "' WHERE id =  {$vid}";
         $this->db->query($sql);
     } else {
         //快编的时候由于要覆盖原视频,所以$target_dir目录是原来视频的目录,从数据库查询
         $sql = "SELECT video_base_path,video_path,video_filename,transcode_server FROM " . DB_PREFIX . "vodinfo WHERE id = {$vid}";
         $arr = $this->db->query_first($sql);
         //检测该视频有没有被拆过条,如果有的话就不允许快编
         if ($this->checkVideoIsSplit($vid)) {
             $this->addLogs('快编有误', '', '', '该视频已经有拆条不能快编,该视频id:' . $vid);
             $this->errorOutput('该视频已经有拆条不能快编');
         }
         //判断当前该视频是不是正在转码,如果正在转码就删除该任务
         foreach (array($vid, $vid . '_more') as $_vid) {
             if ($t_server = checkStatusFromAllServers($_vid)) {
                 $s_tran = new transcode($t_server);
                 $s_tran->stop_transcode_task($_vid);
             }
         }
         $target_dir = $arr['video_path'];
         $filename = explode('.', $arr['video_filename']);
         $output_filename = $filename[0];
         if ($this->input['audit_auto']) {
             $this->settings['App_mediaserver']['extends'] = $this->input['audit_auto'];
         }
         $all_target_dir = $arr['video_base_path'] . $target_dir;
     }
     //更新当前清晰度,表明当前视频使用哪个转码配置进行转码的
     $sql = " UPDATE " . DB_PREFIX . "vodinfo SET cur_clarity = '" . $vod_config['unique_id'] . "',status = 0,app_uniqueid = 'livmedia',mod_uniqueid = 'livmedia' WHERE id =  {$vid}";
     $this->db->query($sql);
     //选取转码服务器
     $tran_server = select_servers($vid);
     if (!$tran_server) {
         $this->errorOutput(NO_SELECT_TRANSERVER);
     }
     $source_conf = array();
     foreach ($source_dir as $k => $v) {
         $source_conf[] = array('source' => $video_base_path[$k] . $source_dir[$k], 'start' => $start[$k], 'duration' => $duration[$k], 'is_water_marked' => $is_water_marked[$k], 'is_recodec' => $is_forcecode[$k], 'url' => $tran_server['need_file'] ? defined("TARGET_VIDEO_DOMAIN") ? 'http://' . ltrim(TARGET_VIDEO_DOMAIN, 'http://') . '/' . $source_dir[$k] : $this->settings['videouploads']['protocol'] . $this->settings['videouploads']['host'] . '/' . $source_dir[$k] : '');
     }
     /**************用curl将视频连同转码参数一并提交过去****************/
     $this->settings['App_mediaserver']['dir'] = $this->settings['App_mediaserver']['dir'] . 'admin/';
     $data = array("sourceFile" => $source_conf, "id" => "{$vid}", "app_id" => APPID, "app_key" => APPKEY, "type" => $type, "targetDir" => $all_target_dir, "output_filename" => $output_filename, "config" => $vod_config, "callback" => $this->settings['App_mediaserver'], "absolute_path" => '1');
     //根据选取到转码服务器是否需要携带文件,选择各自的提交方式
     if ($tran_server['need_file']) {
         $data['upload_file_in_callback'] = "1";
     }
     //头信息
     if ($this->settings['metadata']) {
         $metadata = $this->settings['metadata'];
         foreach ($metadata as $k => $v) {
             if (!$v) {
                 unset($metadata[$k]);
             } else {
                 $metadata[$k] = urlencode($v);
             }
         }
         $data['metadata'] = $metadata;
     }
     $trans = new transcode($tran_server);
     $ret = $trans->addTranscodeTask($data);
     $return = json_decode($ret, 1);
     if ($return['return'] == 'fail') {
         $sql = " UPDATE " . DB_PREFIX . "vodinfo SET status = -1 WHERE id = {$vid}";
         $this->db->query($sql);
         hg_do_transcode_fail($data, $vid);
         //将转码失败的信息记录下来
     }
     echo $ret;
 }
예제 #4
0
파일: functions.php 프로젝트: h3len/Project
function create_video_dir()
{
    $vod_dir_names = TIMENOW . hg_rand_num(2);
    $video_dir = date('Y', TIMENOW) . '/' . hg_split_num($vod_dir_names, 4, '/') . $vod_dir_names . '.ssm/';
    if (file_exists(UPLOAD_DIR . $video_dir) || file_exists(TARGET_DIR . $video_dir)) {
        return create_video_dir();
    }
    return array($vod_dir_names, $video_dir);
}
예제 #5
0
파일: create.php 프로젝트: h3len/Project
 private function check_has_videofile($vod_config)
 {
     if (!$_FILES['videofile']['tmp_name']) {
         $this->errorOutput(NOFILE);
     }
     //判断空间够不够存放视频
     if (function_exists('disk_free_space')) {
         if ($_FILES['videofile']['size'] > disk_free_space(UPLOAD_DIR)) {
             $this->errorOutput(DISC_SPACE_NOT_ENOUGH);
         }
     }
     $original = urldecode($_FILES['videofile']['name']);
     $filetype = strtolower(strrchr($original, '.'));
     $allowtype = explode(',', $this->settings['video_type']['allow_type']);
     if (!in_array($filetype, $allowtype)) {
         $this->errorOutput(FORBIDTYPE);
     }
     $v_videodir = create_video_dir();
     $vod_dir_names = $v_videodir[0];
     $video_dir = $v_videodir[1];
     if (!hg_mkdir(UPLOAD_DIR . $video_dir) || !is_writeable(UPLOAD_DIR . $video_dir)) {
         $this->errorOutput(NOWRITE);
     }
     if (!hg_mkdir(TARGET_DIR . $video_dir) || !is_writeable(TARGET_DIR . $video_dir)) {
         $this->errorOutput(NOWRITE);
     }
     //将上传的文件移动到原视频目录
     $source_filename = 'video_' . $vod_dir_names . $filetype;
     $filepath = $video_dir . $source_filename;
     if (!@move_uploaded_file($_FILES['videofile']['tmp_name'], UPLOAD_DIR . $filepath)) {
         $this->errorOutput(FAILMOVE);
     }
     $this->dir_info = array('output_filename' => $vod_dir_names . '', 'output_format' => $vod_config['output_format'], 'target_dir' => $video_dir, 'source_filename' => $source_filename, 'filepath' => $filepath, 'original' => substr($original, 0, strrpos($original, '.')));
 }