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; }
/** * 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"; } } }