Ejemplo n.º 1
0
function hg_snap($time, $snapdir, $width, $height, $source, $times = 0, $spec_fname = '')
{
    $maxtimes = 2;
    if (!$spec_fname) {
        $spec_fname = $time;
    }
    $file = $spec_fname . '.jpg';
    $jpg = $snapdir . $file;
    $time1 = hg_mc_sec2format($time);
    $cmd = FFMPEG_CMD . ' -ss ' . $time1 . ' -s ' . $width . 'x' . $height . ' -y "' . $jpg . '" -i "' . $source . '" -vframes 1';
    exec($cmd, $out, $s);
    if (!is_file($snapdir . $file) && $times < $maxtimes) {
        $times = intval($times) + 1;
        $file = hg_snap($time - $times * 40, $snapdir, $width, $height, $source, $times, $spec_fname);
    }
    return $file;
}
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
$height = intval($_INPUT['height']);
if (!$width && !$height) {
    $width = intval($info['width']);
    $height = intval($info['height']);
} elseif (!$height) {
    $height = $width * $info['height'] / $info['width'];
} elseif (!$width) {
    $width = $height * $info['width'] / $info['height'];
}
$snaps = array();
if ($_REQUEST['data']) {
    $visit_url = '';
}
for ($i = 0; $i < $count; $i++) {
    $time = $i * $timestep + $stime;
    $jpg = hg_snap($time, $snapdir, $width, $height, $source);
    $pre = $visit_url;
    if (!is_file($snapdir . $jpg)) {
        $jpg = $width . '_fail.jpg';
        $pre = '';
    }
    $snaps[] = $pre . $jpg;
}
if ($_REQUEST['data'] && count($snaps) == 1) {
    $file = $snapdir . $snaps[0];
    $filesize = @filesize($file);
    header('Content-Type: image/jpeg');
    if (!$filesize) {
        exit;
    }
    header('Cache-control: max-age=31536000');
Ejemplo n.º 4
0
}
$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'];
    $vod['aspect'] = $data['Video']['Display aspect ratio'];
    $vod['frame_rate'] = $data['Video']['Frame rate'];
    $vod['img_src'] = THUMB_URL . $video_dir . $last_id . '.ssm/preview.jpg';
    include_once ROOT_DIR . 'lib/curl.class.php';
    $curl = new curl($gVodApi['host'], $gVodApi['dir'] . 'admin/', $gVodApi['token']);
Ejemplo n.º 5
0
 public function snappics()
 {
     $id = $this->input['id'];
     if (!$id) {
         $this->errorOutput(NOID);
     }
     if (isset($this->input['stime'])) {
         $stime = intval($this->input['stime']);
         //开始时间 单位秒
         $stime = $stime ? $stime : 200;
         //开始时间 单位秒
     }
     $etime = intval($this->input['etime']);
     //结束时间 可以不设置
     $aspect = $this->input['aspect'];
     if ($etime && $etime < $stime) {
         $this->errorOutput(TIMEERROR);
     }
     $info = $this->getMediaInfo($id);
     //获取视频信息
     if ($info) {
         if (!$info['aspect']) {
             $info['aspect'] = '4:3';
         }
         if (!$info['width']) {
             $info['width'] = 400;
         }
         if (!$info['height']) {
             $info['height'] = 300;
         }
         $aspect = explode(':', $info['aspect']);
         if (!intval($aspect[0])) {
             $rate = 4 / 3;
         } else {
             $rate = $aspect[1] / $aspect[0];
         }
         $vrate = $info['height'] / $info['width'];
         if ($rate != $vrate) {
             $info['height'] = intval($info['width'] * $vrate);
         }
     }
     if (!$stime) {
         $stime = $info['duration'] / 3;
     }
     if (!$etime) {
         //$etime = $stime;
         $etime = $info['duration'];
     }
     $count = intval($this->input['count']);
     //截取图片数
     $count = $count ? $count : 1;
     $dir = ceil($stime / 6000) . '/';
     $section = $etime - $stime;
     if ($section >= $count) {
         if ($count - 1 == 0) {
             $timestep = $section;
         } else {
             $timestep = intval($section / ($count - 1));
         }
     } else {
         $timestep = 1;
     }
     $snapdir = TARGET_DIR . $info['video_path'] . 'snap/' . $dir;
     hg_mkdir($snapdir);
     if (defined("TARGET_VIDEO_DOMAIN")) {
         $visit_url = 'http://' . ltrim(TARGET_VIDEO_DOMAIN, 'http://') . '/' . $info['video_path'] . 'snap/' . $dir;
     } else {
         $visit_url = $this->settings['videouploads']['protocol'] . $this->settings['videouploads']['host'] . '/' . $info['video_path'] . 'snap/' . $dir;
     }
     $width = intval($this->input['width']);
     $height = intval($this->input['height']);
     if (!$width && !$height) {
         $width = intval($info['width']);
         $height = intval($info['height']);
     } elseif (!$height) {
         $height = $width * $info['height'] / $info['width'];
     } elseif (!$width) {
         $width = $height * $info['width'] / $info['height'];
     }
     $snaps = array();
     if ($this->input['data']) {
         $visit_url = '';
     }
     //$source = TARGET_DIR . $info['video_path'] .$info['video_filename'];
     $source = $info['video_base_path'] . $info['video_path'] . $info['video_filename'];
     for ($i = 0; $i < $count; $i++) {
         $time = $i * $timestep + $stime;
         $jpg = hg_snap($time, $snapdir, $width, $height, $source);
         $pre = $visit_url;
         if (!is_file($snapdir . $jpg)) {
             $jpg = $width . '_fail.jpg';
             $pre = '';
         }
         $snaps[] = $pre . $jpg;
     }
     if ($this->input['data'] && count($snaps) == 1) {
         $file = $snapdir . $snaps[0];
         $filesize = @filesize($file);
         header('Content-Type: image/jpeg');
         if (!$filesize) {
             exit;
         }
         header('Cache-control: max-age=31536000');
         header('Expires: ' . gmdate("D, d M Y H:i:s", time() + 31536000) . ' GMT');
         header('Content-Disposition: inline; filename="snap.jpg"');
         header('Content-Transfer-Encoding: binary');
         header('Content-Length: ' . $filesize);
         readfile($file);
         exit;
     } else {
         if ($this->input['debug']) {
             foreach ($snaps as $k => $v) {
                 $snaps[$k] = '<img src="' . $v . '", width="300" alt="' . $v . '" /><br />' . $v;
             }
         }
         $this->addItem($snaps);
         $this->output();
     }
 }