Jump to content

Video Thumbnail Class Help


ShoeLace1291

Recommended Posts

I downloaded a class for generating video thumbnails, but the site I downloaded it from has no support for it and the example provided is worthless.  Maybe I just don't understand it or maybe it doesn't even work(which I doubt).  I have my own "video" class that pulls the videos from the database, there's the example.php file, and the thumbnail class(downloaded) called snapshot.php.  Basically, what I need to know is how to output the file.  Here is my script:

 

My video class:

<?php

class video {

function latest(){

	ob_start();

		$query = mysql_query("SELECT * FROM videos ORDER BY videoID DESC LIMIT 5") or die("Video Error1: ".mysql_error());
		if(mysql_num_rows($query) == 0){
			echo "<h2>There are no videos to display at this time.</h2>";
		} else {
		while($video=mysql_fetch_array($query)){
				$videoID=$video["videoID"];
				$title=$video["title"];
				$author=$video["authorID"];
				$description=$video["description"];
				$metaTags=$video["metaTags"];
				$dateposted=$video["dateposted"];

					if(strlen($title) > 15){
						$title = substr($title, 0, 14)."...";
					}

					$cfg['snapshot'] = array(
							'program' => '/usr/bin/mplayer',
							'outdir' => '/tmp',
							'progressive' => False,
							'baseline' => True,
							'optimize' => 100,
							'smooth' => 0,
							'quality' => 90,
							'frames' => 5,
							'delete' => False
);

					(object) $img = new Snapshot( $cfg['snapshot'] );
					$img->getOutfile();

				$template = new template;					
				$variables = array(
								   'VIDEO_ID' => $videoID,
								   'TITLE' => $title,
								   'DESCRIPTION' => $description,
								   'SNAPSHOT' => $img->getOutfile()
								   );
				$file = "template/video_links.tpl";
				echo $template->passvars($variables, $file);

			}
		}

	$ret=ob_get_contents();
	ob_end_clean();
	return $ret;

}

 

The script of the example:

<?php

// @example 

// Define class settings
$cfg['snapshot'] = array(
	'program' => '/usr/bin/mplayer',
	'outdir' => '/tmp',
	'progressive' => False,
	'baseline' => True,
	'optimize' => 100,
	'smooth' => 0,
	'quality' => 90,
	'frames' => 5,
	'delete' => False
);

// Path to the input file
(string) $file = "videos/Material Hazard Demo.wmv";

// Load the Snapshot class
include_once('classes/snapshot.php');

try {

// Create the $img object
(object) $img = new Snapshot( $cfg['snapshot'] );

// Extract a jpeg image from defined video file
if ( $img->extract( $file ) ) {
	if ( is_file($img->getOutfile()) ) {
		// If you have set the parameter delete to Fale, you have
		// to delete the extracted file manually with the remove() method.
		echo $file." was successfuly extracted to <a href=\"file://".$img->getOutfile()."\">".$img->getOutfile()."</a><br/>\n";
	} else {
		echo "Sorry, but I can't find any output file!";
	}
} else {
	echo "Can't extract an image from the movie [".$file."]!";
}

// You also can stream the image (send image header)
// if you set the second parameter to True
//if ( !$img->extract( $file, True ) ) {
//	echo "Can't extract ".$file;
//}

// You can remove the outfile manullay if $delete is False
//if ( $cfg['snapshot']['delete'] === False ) {
//	if ( !$img->remove($img->getOutfile()) )
//		die( "Can't delete the output file [".$img->getOutfile()."]!" );
//}

} catch ( Exception $error ) {
echo "Error: ".$error->getMessage()."; on line ".$error->getLine()." in ".$error->getFile()."\n";
}

?>

 

Note that I pass variables to a template file with $template->passvars($variable, $file) with SNAPSHOT as the variable for the snapshot image.  This has been irritating me for quite some time now, so any help provided would be much appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/162651-video-thumbnail-class-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.