Example #1
0
 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;
 }
Example #2
0
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);
        }
    }
}
output(array('sucess' => 1));
Example #3
0
    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();
    }
Example #4
0
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;
}