function genLocalStreamImage($stream_id, $req_time, $req_size) { global $mvLocalVideoPath, $mvStreamImageTable; //zsh edit return false; if (!$stream_id) { return false; } if (!$req_time) { $req_time = 0; } if (!$req_size) { $req_size = '320x240'; } list($im_width, $im_height, $ext) = MV_StreamImage::getSizeType($req_size); if ($req_size == null) { $s = ''; } else { $s = '_' . $im_width . 'x' . $im_height; } $img_dir = MV_StreamImage::getLocalImageDir($stream_id); $img_file = $img_dir . "/" . $req_time . $s . "." . $ext; $streampath = $mvLocalVideoPath . MV_StreamImage::getLocalStreamPath($stream_id); if (is_file($streampath)) { //check if the ffmpeg extension is installed: $extension = "ffmpeg"; $extension_soname = $extension . "." . PHP_SHLIB_SUFFIX; $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname; // load extension if (!extension_loaded($extension)) { if (!dl($extension_soname)) { return false; } } $mov = new ffmpeg_movie($streampath); $fps = $mov->getFrameRate(); if ($req_time == 0) { $ff_frame = $mov->getFrame(1); } else { $ff_frame = $mov->getFrame($req_time * $fps); } if ($ff_frame) { $ff_frame->resize($im_width, $im_height); $gd_image = $ff_frame->toGDImage(); if ($gd_image) { if ($ext == 'png') { imagepng($gd_image, $img_file); imagedestroy($gd_image); } else { imagejpeg($gd_image, $img_file); imagedestroy($gd_image); } } } if (is_file($img_file) && ($req_size == '320x240' || $req_size == '')) { $insAry = array(); $insAry[stream_id] = $stream_id; $insAry[time] = $req_time; $db =& wfGetDB(DB_WRITE); if ($db->insert($mvStreamImageTable, $insAry)) { return $img_file; } else { //probably error out before we get here return false; } } } return $img_file; }
function get_fd_mvd_page(&$mvd_page, $content = '') { global $wgOut, $mvDefaultVideoPlaybackRes; // print_r($mvd_page); // "<div id=\"mv_ctail_{$mvd_page->id}\" style=\"position:relative\">" if (isset($this->mv_interface->smwProperties['playback_resolution'])) { // for now just put in a hack that forces no size adjustment $img_url = MV_StreamImage::getStreamImageURL($mvd_page->stream_id, $mvd_page->start_time, null, true); } else { $img_url = MV_StreamImage::getStreamImageURL($mvd_page->stream_id, $mvd_page->start_time, $mvDefaultVideoPlaybackRes, true); } $oe_class = ''; //color annnotative layers seperatly: $oe_class .= ' ' . htmlspecialchars(strtolower($mvd_page->mvd_type)); //preset classes for rendering on page load (will repaint but whatever) if ($this->oddEvenToggle) { $this->oddEvenToggle = false; $oe_class .= ' even'; } else { $this->oddEvenToggle = true; $oe_class .= ' odd'; } // style=\"background:#".$this->getMvdBgColor($mvd_page)."\" " $wgOut->addHTML('<fieldset class="mv_fd_mvd' . htmlspecialchars($oe_class) . '" id="mv_fd_mvd_' . htmlspecialchars($mvd_page->id) . '" ' . 'name="' . htmlspecialchars($mvd_page->wiki_title) . '" ' . 'image_url="' . htmlspecialchars($img_url) . '" >'); /*$wgOut->addHTML("<legend id=\"mv_ld_{$mvd_page->id}\">" . $this->get_mvd_menu($mvd_page) . "</legend>");*/ // $menu_html = $this->get_mvd_menu($mvd_page); $wgOut->addHTML("<div id=\"mv_fcontent_{$mvd_page->id}\">"); if ($content == '') { $this->outputMVD($mvd_page); } else { $wgOut->addHTML($content); } $wgOut->addHTML("</div>"); $wgOut->addHTML("</fieldset>"); }
$mvTitle = new MV_Title('Stream:' . $stream_name); if (!$mvTitle->doesStreamExist()) { print $stream_name . " does not exist ... creating\n"; // print 'do stream desc'."\n"; if (!isset($MVStreams)) { $MVStreams = array(); } // init the stream (legacy from old stream insert system) $MVStreams[$stream->name] = new MV_Stream($stream); do_add_stream($mvTitle, $stream); } $stream_id = $mvTitle->getStreamId(); print 'got stream id: ' . $stream_id . "\n"; //check for & update stream files: do_stream_file_check($stream); $filedir = '/video/metavid/mvprime_stream_images/' . MV_StreamImage::getRelativeImagePath($stream_id); if (!is_dir($filedir)) { shell_exec("mkdir {$filedir}"); shell_exec("chmod -R 777 {$filedir}"); } echo "working on: {$filename} \n"; $ocroutput = ""; //@@TODO we should do sequential output and parse the OCR file if it already exists. //make sure we can write to the ocr file: $ocrfileloc = "{$workingdir}/{$stream_name}.ocr"; $fh = @fopen($ocrfileloc, 'a') or die("\nError: can't write to ocr file\n"); fclose($fh); //gets duration from ffmpeg $dbw = $dbr = wfGetDB(DB_MASTER); for ($i = 0; $i < $duration; $i += $interval) { //only run the ffmpeg cmd if we have to:
require_once 'maintenance_util.inc.php'; if (count($args) == 0 || isset($options['help'])) { print ' USAGE php ogg_thumb_insert.php stream_name filename interval duration EXAMPLE where stream.ogg is 10min 20 seconds long and we get a frame every 5 seconds: ogg_thumb_insert.php stream_name stream.ogg 5 620 Notes: if possible you want to use the source footage rather than the ogg to generate the thumbnails (ie the mpeg2 or dv) '; exit; } $stream_name = $args[0]; $filename = $args[1]; $interval = $args[2]; $duration = $args[3]; $MV_Stream = MV_Stream::newStreamByName($stream_name); $stream_id = $MV_Stream->getStreamId(); $filedir = '../stream_images/' . MV_StreamImage::getRelativeImagePath($stream_id); $dbw = $dbr = wfGetDB(DB_MASTER); for ($i = 0; $i < $duration; $i += $interval) { shell_exec("ffmpeg -ss {$i} -i {$filename} -vcodec mjpeg -vframes 1 -an -f rawvideo -y {$filedir}/{$i}.jpg"); if (is_file("{$filedir}/{$i}.jpg")) { $dbw->query("INSERT INTO `mv_stream_images` (`stream_id`, `time`) VALUES ({$stream_id}, {$i})"); } else { print "failed to create file: {$filedir}/{$i}.jpg \n"; } }
/** * for each image add it to the image directory */ function do_process_images($stream, $force = false) { global $mvLocalImgLoc, $MVStreams, $wgDBname; $dbr = wfGetDB(DB_SLAVE); $dbw = wfGetDB(DB_MASTER); // get all images for the current stream: $sql = "SELECT * FROM `metavid`.`image_archive`\n\t\t\t\tWHERE `stream_fk`= {$stream->id}"; $image_res = $dbr->query($sql); $img_count = $dbr->numRows($image_res); print "Found " . $img_count . " images for stream " . $stream->name . "\n"; // grab from metavid and copy to local directory structure: $i = $j = 0; $mv_stream_id = $MVStreams[$stream->name]->getStreamId(); // if force we can clear out existing images: if ($force) { print "force update flag (remove all existing images)\n"; $local_img_dir = MV_StreamImage::getLocalImageDir($mv_stream_id); $res = $dbr->query("SELECT * FROM `{$wgDBname}`.`mv_stream_images` WHERE `stream_id`={$mv_stream_id}"); while ($row = $dbr->fetchObject($res)) { $local_img_file = $local_img_dir . '/' . $row->time . '*.jpg'; shell_exec('rm -f ' . $local_img_file); } // remove db entries: $dbw->query("DELETE FROM `{$wgDBname}`.`mv_stream_images` WHERE `stream_id`={$mv_stream_id}"); } while ($row = $dbr->fetchObject($image_res)) { // if(isset($row-> $relative_time = $row->time - $stream->adj_start_time; // status updates: if ($i == 10) { print "On image {$j} of {$img_count} time: " . seconds2npt($relative_time) . " {$metavid_img_url}\n"; $i = 0; } $j++; $i++; // get streamImage obj: $local_img_dir = MV_StreamImage::getLocalImageDir($mv_stream_id); $metavid_img_url = 'http://metavid.org/image_media/' . $row->id . '.jpg'; $local_img_file = $local_img_dir . '/' . $relative_time . '.jpg'; // check if the image already exist in the new table $sql = "SELECT * FROM `{$wgDBname}`.`mv_stream_images` " . "WHERE `stream_id`={$mv_stream_id} " . "AND `time`={$relative_time}"; $img_check = $dbr->query($sql); $doInsert = true; if ($dbr->numRows($img_check) != 0) { // make sure its there and matches what it should be: if (is_file($local_img_file)) { $row = $dbr->fetchObject($img_check); // print "file $local_img_file skiped, stream_id:" . $mv_stream_id . " time: " . seconds2npt($relative_time) . "\n"; continue; } else { // grab but don't insert: $doInsert = false; } } if ($doInsert) { // insert: $dbw->insert('mv_stream_images', array('stream_id' => $MVStreams[$stream->name]->getStreamId(), 'time' => $relative_time)); $img_id = $dbw->insertId(); // $grab = exec('cd ' . $img_path . '; wget ' . $im_url); } if (is_file($local_img_file)) { echo "skipped {$local_img_file} \n"; continue; } // print "run copy: $metavid_img_url, $local_img_file \n"; if (!copy($metavid_img_url, $local_img_file)) { echo "failed to copy {$metavid_img_url} to {$local_img_file}...\n"; } else { // all good don't report anything' // print "all good\n"; } } }
function getStreamImageURL($size = null, $req_time = null, $foce_server = '') { global $mvDefaultVideoPlaybackRes; if ($size == null) { $size = $mvDefaultVideoPlaybackRes; } if ($req_time == null) { $req_time = $this->getStartTime(); if (!$req_time) { $req_time = '0:00:00'; } } if ($foce_server == '') { //get the image path: (and generate the image if necessary) return MV_StreamImage::getStreamImageURL($this->getStreamId(), $req_time, $size); } else { return $foce_server . $this->getStreamName() . '?t=' . $req_time; } }
function mv_frame_server($stream_name = '', $req_time = '', $req_size = '') { global $wgRequest; $stream_id = ''; // try loading vals from $wgRequest if not set $stream_name = $stream_name == '' ? $wgRequest->getVal('stream_name') : $stream_name; if ($stream_name == null) { $stream_id = $wgRequest->getVal('stream_id'); } $req_time = $req_time == '' ? $wgRequest->getVal('t') : $req_time; $req_size = $req_size == '' ? $wgRequest->getVal('size') : $req_size; $redirect_req = $wgRequest->getVal('redirect') == 'true' ? true : false; if ($stream_id == '') { $mvStream = mvGetMVStream($stream_name); $stream_id = $mvStream->getStreamId(); } else { $mvStream = new MV_Stream(array('id' => $stream_id)); } if ($mvStream->db_load_stream()) { global $mvServeImageRedirect, $mvExternalImages; if ($mvServeImageRedirect || $redirect_req || $mvExternalImages) { header("Location:" . MV_StreamImage::getStreamImageURL($stream_id, $req_time, $req_size, true)); } else { // serve up the image directly MV_StreamImage::getStreamImageRaw($stream_id, $req_time, $req_size, true); } exit; } else { return 'error: invalid stream name'; } }
function get_fd_mvd_page(&$mvd_page, $content = '') { global $wgOut; //print_r($mvd_page); //"<div id=\"mv_ctail_{$mvd_page->id}\" style=\"position:relative\">" if (isset($this->mv_interface->smwProperties['playback_resolution'])) { //for now just put in a hack that forces no size adjustment $img_url = MV_StreamImage::getStreamImageURL($mvd_page->stream_id, $mvd_page->start_time, null, true); } else { $img_url = MV_StreamImage::getStreamImageURL($mvd_page->stream_id, $mvd_page->start_time, 'medium', true); } $type = substr($mvd_page->wiki_title, 0, strpos($mvd_page->wiki_title, ':')); $wgOut->addHTML("<fieldset class=\"mv_fd_mvd {$type}\" style=\"background:#" . $this->getMvdBgColor($mvd_page) . "\" " . "id=\"mv_fd_mvd_{$mvd_page->id}\" name=\"{$mvd_page->wiki_title}\" " . "image_url=\"{$img_url}\" >"); $wgOut->addHTML("<legend id=\"mv_ld_{$mvd_page->id}\">" . $this->get_mvd_menu($mvd_page) . "</legend>"); $wgOut->addHTML("<div id=\"mv_fcontent_{$mvd_page->id}\">"); if ($content == '') { $this->outputMVD($mvd_page); } else { $wgOut->addHTML($content); } $wgOut->addHTML("</div>\n"); $wgOut->addHTML("</fieldset>"); }
function formatResult($skin, $result) { global $wgUser, $wgLang, $mvImageArchive; $sit = new MV_Sitting(array('id' => $this->sitting_id)); $sit->db_load_sitting(); #make sure the first letter is upper case (makeTitle() should do that) $result->title = strtoupper($result->title[0]) . substr($result->title, 1); $img_url = $mvImageArchive . $result->title . '?size=icon&time=0:00:00'; $img_url = MV_StreamImage::getStreamImageURL($result->stream_id, '0:00:00', 'icon', true); $img_html = '<img src="' . $img_url . '" width="80" height="60">'; $title = Title::makeTitle(MV_NS_STREAM, $result->title); $rlink = $skin->makeLinkObj($title, $img_html . ' ' . $title->getText()); //if admin expose an edit link if ($this->existing == 'false') { $rlink .= ' ' . $skin->makeKnownLinkObj(Title::makeTitle(MV_NS_STREAM, $title->getText()), 'edit', 'action=edit'); } else { $rlink .= ' ' . $skin->makeKnownLinkObj(Title::makeTitle(MV_NS_SITTING, $sit->name), 'add', 'action=edit&mv_action=add&stream_id=' . $result->stream_id); } return $rlink; }
function getEmbedVideoHtml($options = array()) { global $mvDefaultFlashQualityKey, $mvDefaultVideoQualityKey, $mvDefaultMP4QualityKey; //init options if unset: $vid_id = isset($options['id']) ? $options['id'] : ''; $size = isset($options['size']) ? $options['size'] : ''; $force_server = isset($options['force_server']) ? $options['force_server'] : ''; $autoplay = isset($options['autoplay']) ? $options['autoplay'] : false; $showmeta = isset($options['showmeta']) ? $options['showmeta'] : false; $tag = 'video'; if ($size == '') { global $mvDefaultVideoPlaybackRes; $size = $mvDefaultVideoPlaybackRes; list($vWidth, $vHeight) = explode('x', $size); } else { list($vWidth, $vHeight, $na) = MV_StreamImage::getSizeType($size); } $stream_web_url = $this->getWebStreamURL($mvDefaultVideoQualityKey); $flash_stream_url = $this->getWebStreamURL($mvDefaultFlashQualityKey); $mp4_stream_url = $this->getWebStreamURL($mvDefaultMP4QualityKey); // print "looking for q: $mvDefaultFlashQualityKey "; // print "FOUND: $flash_stream_url"; $roe_url = $this->getROEURL(); //if no urls available return missing: if (!$stream_web_url && !$flash_stream_url && !$mp4_stream_url) { return wfMsgWikiHtml('mv_error_stream_missing'); } if ($stream_web_url || $flash_stream_url || $mp4_stream_url) { $o = ''; /*if($this->dispVideoPlayerTime){ $o.='<span id="mv_videoPlayerTime">'.$this->getStartTime().' to '. htmlspecialchars( $this->getEndTime() ) . '</span>'; }*/ $o .= '<' . htmlspecialchars($tag) . ' '; $o .= $vid_id == '' ? '' : ' id="' . htmlspecialchars($vid_id) . '" '; $o .= 'poster="' . $this->getStreamImageURL($size, null, $force_server) . '" ' . 'roe="' . $roe_url . '" '; $o .= $showmeta ? 'show_meta_link="true" ' : 'show_meta_link="false" '; $o .= $autoplay ? ' autoplay="true" ' : ''; $o .= 'style="width:' . htmlspecialchars($vWidth) . 'px;height:' . htmlspecialchars($vHeight) . 'px" ' . 'controls="true" embed_link="true" >'; if ($stream_web_url) { $o .= '<source timeFormat="anx" type="' . htmlspecialchars(MV_StreamFile::getTypeForQK($mvDefaultVideoQualityKey)) . '" src="' . $stream_web_url . '"></source>'; } if ($flash_stream_url) { $o .= '<source timeFormat="anx" type="' . htmlspecialchars(MV_StreamFile::getTypeForQK($mvDefaultFlashQualityKey)) . '" src="' . $flash_stream_url . '"></source>'; } if ($mp4_stream_url) { $o .= '<source timeFormat="mp4" type="' . htmlspecialchars(MV_StreamFile::getTypeForQK($mvDefaultMP4QualityKey)) . '" src="' . $mp4_stream_url . '"></source>'; } $o .= '</' . htmlspecialchars($tag) . '>'; return $o; } }