<?php
/**
* $Id: handler.video.php,v 1.10 2004/11/29 22:04:34 openface Exp $
*
* _ _ _ _
* _ __ ___ __| (_)__ _ (_)_ _ __| |_____ _____ _ _
* | ' \/ -_) _` | / _` | | | ' \/ _` / -_) \ / -_) '_|
* |_|_|_\___\__,_|_\__,_| |_|_||_\__,_\___/_\_\___|_|
*
* Standalone Indexer Script for Media Files
* jason hines, <hide@address.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
* General Public License for more details.
*/
/* video thumbnail directory */
define("_VIDTHUMBPATH",_CACHEPATH."/vidthumbs");
define("_VIDTHUMBURL",_CACHEURL."/vidthumbs");
/* path to ffmpeg binary */
define("_FFMPEG","/usr/bin/ffmpeg");
/**
* Group handler class for videos. Uses FFMpeg to generate
* thumbnails of the video files. Specific handlers may
* extend this class. (such as realplayer,quicktime,etc)
*
* @version $Revision: 1.10 $
* @package mediaIndexer
* @subpackage handlers
* @author jason hines, <hide@address.com>
*/
class videoHandler extends defaultHandler {
public $iconName = "video.gif";
public function videoHandler() {
if (!is_executable(_FFMPEG)) {
_addMessage("WARNING! ". _FFMPEG . " not found. Is ffmpeg installed?");
}
}
// ffmpeg -y -t 00:00:00.01 -f mov -i YouAre.mov -s 80x80 -f singlejpeg test.jpg
public function printListing(file $file) {
// generate thumbnail image if not exists
$ext = _getExtension($file->path);
$tname = $file->hash . ".jpg";
if (!file_exists(_VIDTHUMBPATH."/".$tname) || filesize(_VIDTHUMBPATH."/".$tname)==0) {
if (!is_writable(_VIDTHUMBPATH)) {
mkdir(_VIDTHUMBPATH);
}
// thumnail doesn't exist, generate it
//_addMessage("Generating video thumbnail ".basename($file->path)." ...");
$cmd = _FFMPEG ." -y -t 00:00:00.1 -i "._MEDIAPATH.escapeshellarg($file->path)." -s "._THUMBSIZE." -f singlejpeg "._VIDTHUMBPATH."/{$tname}";
exec($cmd,$out,$ret);
if ($ret != 0) {
//_addMessage("Unable to generate video thumbnail ".basename($file->path).".");
$imgurl = _BASEURL."/img/na.gif";
} else {
$imgurl = _VIDTHUMBURL."/{$tname}";
}
} else {
$imgurl = _VIDTHUMBURL."/{$tname}";
}
echo "<a href=\"?file="._encodeuri($file->path)."\">";
echo "<img class=\"fade\" src=\"{$imgurl}\" alt=\"{$file->path} Video Thumbnail\" border=\"0\" align=\"left\" />";
echo _truncate($file->title,25) . "</a><br />";
echo "<small>({$file->filesize})</small>\n";
if (!empty($file->desc)) {
echo "<div class=\"description\">" . _parseText($file->desc) . "</div>\n";
}
echo "<br />";
}
}
?>