public function snapPicture($source_path, $targerdir) { $mediainfo = new mediainfo($source_path); $data = $mediainfo->getMeidaInfo(); $_snap_pos = defined('SNAP_PIC_POS') && intval(SNAP_PIC_POS) ? intval(SNAP_PIC_POS) : 3; $snaptime = intval($data['General']['Duration'] / $_snap_pos); $snapw = $data['Video']['Width'] ? $data['Video']['Width'] : 480; $snaph = $data['Video']['Height'] ? $data['Video']['Height'] : 360; $preview = hg_snap($snaptime, $targerdir, $snapw, $snaph, $source_path, 0, 'preview'); if (!$preview) { return false; } if (defined("TARGET_VIDEO_DOMAIN")) { $server_host = ltrim(TARGET_VIDEO_DOMAIN, 'http://'); } else { global $gGlobalConfig; $server_host = $gGlobalConfig['videouploads']['host']; } $path = str_replace(TARGET_DIR, 'http://' . $server_host . '/', $targerdir . $preview); return $path; }
); * 错误返回: 001 - 未指定文件传输,002 - 非法的文件类型, 003 - 视频移动失败 */ if (!in_array($_INPUT['auth'], $gToken)) { error_output('009', '通信令牌错误'); } $content = @file_get_contents(TRANSCODE_STAT); $info = json_decode($content, true); if ($info['files']) { $script = explode('/', TRANSCODE_SCRIPT); $cmd = PSCMD . $script[count($script) - 1]; exec($cmd, $out, $t); $pid = intval($out[0]); if (!$pid) { include ROOT_DIR . 'lib/mediainfo.class.php'; $mediainfo = new mediainfo(); foreach ($info['files'] as $filepath) { if (!is_file(UPLOAD_DIR . $filepath)) { continue; } $mediainfo->setFile(UPLOAD_DIR . $filepath); $data = $mediainfo->getMeidaInfo(); if (!$data) { continue; } $id = explode('/', $filepath); $id = $id[count($id) - 1]; $id = explode('.', $id); $id = $id[0]; hg_file_write(UPLOAD_DIR . FILE_QUEUE . $id, $filepath); }
if (!hg_mkdir(UPLOAD_DIR . $video_dir) || !is_writeable(UPLOAD_DIR . $video_dir)) { error_output('004', UPLOAD_DIR . '目录不可写入文件'); } if (!hg_mkdir(UPLOAD_DIR . FILE_QUEUE) || !is_writeable(UPLOAD_DIR . FILE_QUEUE)) { error_output('004', UPLOAD_DIR . FILE_QUEUE . '目录不可写入文件'); } $targerdir = TARGET_DIR . $video_dir . $last_id . '.ssm/'; hg_mkdir($targerdir); $filepath = $video_dir . $last_id . $filetype; $_INPUT['client'] = intval($_INPUT['client']); //file_put_contents($targerdir . 'uploading', $filesize . "\n" . $_FILES['videofile']['tmp_name'] . "\n" . UPLOAD_DIR . $filepath); if (!@move_uploaded_file($_FILES['videofile']['tmp_name'], UPLOAD_DIR . $filepath)) { error_output('003', '视频未成功移动到指定目录'); } include ROOT_DIR . 'lib/mediainfo.class.php'; $mediainfo = new mediainfo(UPLOAD_DIR . $filepath); $data = $mediainfo->getMeidaInfo(); $snaptime = intval($data['General']['Duration'] / 3); $snapw = $data['Video']['Width']; $snaph = $data['Video']['Height']; $preview = hg_snap($snaptime, $targerdir, $snapw, $snaph, UPLOAD_DIR . $filepath, 0, 'preview'); if ($_INPUT['client'] > -1 && $gVodApi['host']) { $vod = array('vodid' => $last_id, 'totalsize' => $filesize, 'type' => $filetype, 'title' => str_replace($filetype, '', $original), 'vod_leixing' => $_INPUT['vod_leixing'] ? $_INPUT['vod_leixing'] : 1, 'admin_id' => $_INPUT['admin_id'], 'admin_name' => $_INPUT['admin_name']); $vod['audio'] = $data['Audio']['Format'] . '-' . $data['Audio']['Format profile'] . ' ' . $data['Audio']['Format version']; $vod['audio_channels'] = $data['Audio']['Channel positions']; $vod['sampling_rate'] = $data['Audio']['Sampling rate']; $vod['bitrate'] = $data['General']['Overall bit rate']; $vod['duration'] = $data['General']['Duration']; $vod['video'] = $data['Video']['Format'] . ' ' . $data['Video']['Format profile']; $vod['width'] = $data['Video']['Width']; $vod['height'] = $data['Video']['Height'];
if (count($start) != count($duration) || count($svodid) != count($start)) { error_output('006', '视频段信息不匹配'); } include ROOT_DIR . 'lib/mediainfo.class.php'; $video_dir = hg_num2dir($vodid); $targerdir = TARGET_DIR . $video_dir . $vodid . '.ssm/'; $mp4 = $targerdir . $vodid . '.mp4'; if (!is_file($mp4)) { error_output('004', '原视频不存在'); } $source_file = $targerdir . $vodid . '_s.mp4'; $rename = @rename($mp4, $source_file); if (!$rename) { error_output('005', '视频权限限制,无法编辑视频'); } $mediainfo = new mediainfo($source_file); $source_file_data = $mediainfo->getMeidaInfo(); $source = array(); foreach ($svodid as $k => $vid) { $video_dir = hg_num2dir($vid); $targerdir = TARGET_DIR . $video_dir . $vid . '.ssm/'; if ($vid == $vodid) { $sourcef = $source_file; $data = $source_file_data; } else { $sourcef = $targerdir . $vid . '.mp4'; if (!is_file($sourcef)) { error_output('006', '指定片段视频不存在'); } $mediainfo->setFile($sourcef); $data = $mediainfo->getMeidaInfo();
function getVideoInfoById($id) { if (!$id) { return false; } $time = 0; $video_dir = hg_num2dir($id); include ROOT_DIR . 'lib/mediainfo.class.php'; $mediainfo = new mediainfo(MP4_TARGET_DIR . $video_dir . $id . '.ssm/' . $id . '.mp4'); $data = $mediainfo->getMeidaInfo(); $sourceinfo = @file_get_contents(MP4_TARGET_DIR . $video_dir . $id . '.ssm/source_media_info'); $sourceinfo = json_decode($sourceinfo, true); if (!$data && !$sourceinfo) { $_INPUT['status'] = -1; hg_update_vod(array(), '', ''); return false; } $info = array(); $targerdir = MP4_TARGET_DIR . $video_dir . $id . '.ssm/'; $info['id'] = $id; $out = @file_get_contents(MP4_TARGET_DIR . $video_dir . $id . '.ssm/out'); // frame=20302 fps= 17 q=14.0 size= 272224kB time=2582.58 bitrate= 863.5kbits/s dup=0 drop=39852 //duplicate frame(s)!Pos:5193.4s 129587f (99%) 263.62fps Trem: 0min 574mb A-V:0.029 [687:236] preg_match_all('/frame=\\s*\\d*\\s*fps=\\s*\\d*\\s*q=\\s*[0-9\\.]*\\s*size=\\s*(\\d*)kB\\s*time=\\s*([0-9\\.]*)\\s*bitrate=\\s*([0-9\\.]*)/is', $out, $result); preg_match_all('/frame=\\s*\\d*\\s*fps=\\s*\\d*\\s*q=\\s*[0-9\\.\\-]*\\s*Lsize=\\s*(\\d*)/is', $out, $complete); preg_match_all('/\\(([\\d\\.]*)%\\)/is', $out, $mecoder); $mecoder = $mecoder[1]; $mecoder_progress = $mecoder[count($mecoder) - 1]; $count = count($result[0]) - 1; //print_r($result); $progress = $result[1][$count]; $curtime = $result[2][$count]; $curbitrate = $result[3][$count]; $complete = $complete[1][0]; $info['audio'] = $data['Audio']['Format'] . '-' . $data['Audio']['Format profile'] . ' ' . $data['Audio']['Format version']; $info['audio_channels'] = $data['Audio']['Channel positions']; $info['sampling_rate'] = $data['Audio']['Sampling rate']; $info['bitrate'] = $data['General']['Overall bit rate']; $info['duration'] = $data['General']['Duration']; $info['video'] = $data['Video']['Format'] . ' ' . $data['Video']['Format profile']; $info['width'] = $data['Video']['Width']; $info['height'] = $data['Video']['Height']; $info['aspect'] = $data['Video']['Display aspect ratio']; $info['frame_rate'] = $data['Video']['Frame rate']; $info['img_src'] = THUMB_URL . $video_dir . $id . '.ssm/preview.jpg'; $info['transize'] = $progress * 1024; $info['status'] = 0; //print_r($sourceinfo); if ($complete) { $info['status'] = 1; //转码完成 $progress = $complete; $info['totalsize'] = $data['General']['File size']; } else { if (!$curbitrate) { $curbitrate = 70; } else { $curbitrate = $curbitrate / 8; } $speed = $curbitrate; $info['totalsize'] = $sourceinfo['General']['Duration'] * $curbitrate / 1000 * 1024; } if ($mecoder_progress && !$info['transize']) { $info['totalsize'] = $info['totalsize'] + $sourceinfo['General']['File size']; $info['transize'] = intval($sourceinfo['General']['File size'] * (100 - $mecoder_progress) / 100); $speed = mt_rand(20, 120); } $info['speed'] = $speed; $info['mecoder_progress'] = $mecoder_progress; $mediainfo_file = $targerdir . 'media_info'; hg_file_write($mediainfo_file, json_encode($data)); $file = $targerdir . $id . '.mp4'; if (is_file($file)) { $mp4 = THUMB_URL . $video_dir . $id . '.ssm/' . $id . '.mp4'; } hg_update_vod($info, $mp4, $video_dir . $id . '.ssm/'); return $info; }
$svodid = $_INPUT['svodid']; if (!$svodid) { error_output('002', '未指定源视频vodid'); } $start = $_INPUT['start']; $duration = $_INPUT['duration']; if (!is_array($svodid)) { $svodid = array($svodid); $start = array($start); $duration = array($duration); } if (count($svodid) != count($start) || count($svodid) != count($duration)) { error_output('003', '视频信息不匹配'); } include ROOT_DIR . 'lib/mediainfo.class.php'; $mediainfo = new mediainfo(); $source = array(); foreach ($svodid as $k => $sid) { $video_dir = hg_num2dir($sid); $targerdir = TARGET_DIR . $video_dir . $sid . '.ssm/'; $mp4 = $targerdir . $sid . '.mp4'; $mediainfo->setFile($mp4); $data = $mediainfo->getMeidaInfo(); $source[] = array('source' => $mp4, 'start' => intval($start[$k]), 'duration' => intval($duration[$k]), 'mediainfo' => $data); } $file_id = $_INPUT['vodid']; if (!$file_id) { $file_id = hg_get_video_id(); } $dir = hg_num2dir($file_id); $video_dir = hg_num2dir($file_id);