Mplayer mod for movie thumbnails (Working)

mattyb

Joined: 2005-07-04
Posts: 82
Posted: Sat, 2005-07-09 07:24

Hello Everyone

I tried the ffmpeg mod to create thumbnails for my videos as described in Floridaves thread

http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=29359

I was unhappy with it because of ffmpegs limited amount of supported codecs. Mainly WMV3. I looked around the gallery website and could not find a working mod that utilized mplayer to generate the thumbnails so Floridave suggested I take a whack at it. My linux and php are severely lacking, but nevertheless I was able to create the mod to intergrate mplayer with gallery v1.5. I used his mod for ffmpeg as a starting point and went from there.

Attatched is the zip file for the mod. You'll need to copy the contents over the files on your server. You will obviouslly also need to instal Mplayer and Mencoder onto your server.

Please remember to make backups of your original files before you do this in case you run into any problems. Also I would recommend you make a backup of you config.php file as well.

I am also using Floridaves emmbedded movie mod which you can download via the above mentioned thread.

A couple of things I thought I would mention.

1: This mod uses both Mplayer and Mencoder to work, but since they both come in the same package, you should have both already.

2: I am having trouble with some read write permissions on my server so even with this mod I am still unable to generate a thumb for a wmv3, although all other attempts at generateing thumbs for videos with other codecs have been succesful. Hopefully my webhost will fix this shortly. Please let me know if it works for you.

3: For some reason mencoder doesnt adhere to the original aspect ratio. If you have widescreen movies in your gallery the thumbs will be in standard 4:3 format (no big deal but if some one knows the mencoder argument to fix this I would love to have it.)

4. This mod is only tested on Gallery v1.5. I have no idea if it will work on any other version.

5. Unlike the ffmpeg mod, if you fail to create a thumbnail (lack of a codec) you will retain the generic movie thumbnail provided in the movie mod. mplayer only outputs a file if it can where as ffmpeg always outputs a file even if it is empty. This prohibits gallery from realizing whether or not a thumb was produced. No more lost thumbs.

Well let me know how you all like it. I think my next project will be to enable highlighting movies and thier albums, as using a hidden jpeg is just silly to me since all my movies now have thumbnails.

Good luck,

Matt

AttachmentSize
Mplayer Mod.zip41.06 KB
Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Sat, 2005-07-09 18:37

I just replaced the Mplayer mod.zip file because i found an error when trying to copy a movie to another album. My syntax was incorrect. Hey I'm new, what do you expect. So the 2 of you that had downloded it , please do so again.

Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Mon, 2005-07-11 05:09

Ok well I looked into enabling highlights for movies since they now have thumbnails generated and here is the code to work in conjunction with the mplayer mod to enable highlights. It would be very easy to modify the ffmpeg mod to work with this highlight mod. In fact the first change to the code would just need to be inserted in the same place if you have done the ffmpeg mod. Like i said this assumes you have done the mplayer mod so your code should look like mine below. Here are the code changes.

In AlbumItem.php add the following

/* were we able to generate the thumb? */
                       if(file_exists($tmpThumb)){
                               fs_copy($tmpThumb, "$dir/$name.thumb.jpg");
                               fs_copy($tmpThumb, "$dir/$name.full.jpg");
                               $ret = resize_image("$dir/$name.thumb.jpg", "$dir/$name.thumb.jpg", $thumb_size);

The reaseon the following line: fs_copy($tmpThumb, "$dir/$name.full.jpg"); Was added is that i need an unresized version of the thumb since we use it as the original jpg to create the highlight unlike images in which we use the image itself.

Then also change the following in AlbumItem.php

if ($this->highlight) {
			if (!isset($name)) {
				$srcdir = $dir;
				$srcitem = $this;
				if ($this->isAlbum()) {
					$name = $this->getAlbumName();
					$nestedAlbum = new Album();
					$nestedAlbum->load($name);
					list ($srcalbum, $srcitem) = $nestedAlbum->getHighlightedItem();
					if ($srcalbum !== null && $srcitem !== null) {
						$srcdir = $srcalbum->getAlbumDir();
						$tag = $srcitem->image->type;
					}
					else {
						if (is_object($this->highlightImage)) {
							$this->highlightImage->simpleDelete($dir);
							$this->highlightImage = null;
						}
						return;
					}
				} else {
					$name = $this->image->name;
					$tag = $this->image->type;
				}
			}
			$size = $album->getHighlightSize();

			if ($srcitem->image->thumb_width > 0  && !$srcitem->isMovie()) {
				// Crop it first
				$ret = cut_image("$srcdir/".$srcitem->image->name.".$tag",
						"$dir/$name.tmp.$tag",
						$srcitem->image->thumb_x,
						$srcitem->image->thumb_y,
						$srcitem->image->thumb_width,
						$srcitem->image->thumb_height);

				// Then resize it down
				if ($ret) {
					$ret = resize_image("$dir/$name.tmp.$tag", 
							    "$dir/$name.highlight.$tag",
							    $size);
				}
				fs_unlink("$dir/$name.tmp.$tag");
			}  elseif ($srcitem->isMovie()) {



/*           From Here       */


				$tag = "jpg";
				$ret = cut_image("$srcdir/".$srcitem->image->name.".full.$tag",
						"$dir/$name.tmp.$tag",
						$srcitem->image->thumb_x,
						$srcitem->image->thumb_y,
						$srcitem->image->thumb_width,
						$srcitem->image->thumb_height);

				// Then resize it down
				if ($ret) {
					$ret = resize_image("$dir/$name.tmp.$tag", 
							    "$dir/$name.highlight.$tag",
							    $size);
				}
				fs_unlink("$dir/$name.tmp.$tag");


/*               To Here    */

			} else {
				$ret = resize_image("$srcdir/".$srcitem->image->name.".$tag",
						    "$dir/$name.highlight.$tag",
						    $size);
			}

So you'll need to copy over the code of the original file with the code I provided. The reason we do this is that we would no longer look for a generic thumb for movies we use the one created by mplayer and we use it to create the highlight thumb.

You will then need to comment out the following lines of code as done in the following in view_album.php


	/*			if (!$gallery->album->isMovieByIndex($i)) {
					  Show Highlight Album/Photo only when this i a photo, or Album has a highlight		 */
					$nestedAlbum=$gallery->album->getNestedAlbum($i);
					if (!$gallery->album->isAlbum($i) || $nestedAlbum->hasHighlight()) {
						showChoice(sprintf(_("Highlight %s"),$label), 'do_command.php', array('cmd' => 'highlight', 'index' => $i));
					}	
	/*			}		*/

This is done so that the option to highlight movies and albums with only movies will now appear to the admin in the drop down list.

There are a few bugs that need to be worked out and maybe someone can offer some suggestions.

The first bug is that unlike when you add photos if you only add movies one of them is not automatically selected as the highlight. So until you manually select one as the highlight the parent directory shows the "no highlight" link. Also if you then delete or move the highlighted movie, you have to manually select another to be the highlight.

The second bug is that when you move or delete the movie, the file in the albums directory movie.full.jpg that we created, is not deleted. It will need to be deleted manually via ftp to conserve disk space and to maintain a clean album. If it is left though i dont see it being that big of a deal.

The third bug is that if you delete the entire album the file movie.full.jpg again causes problems. Since gallery doesnt expect that file to be there it doesn't delete it. When it tries to delet the directory it cant because it is not empty. You will receive a warning when loggen in as admin that the album has been deleted but the directory still exists and needs to be deleted.

Anyways none of these seem to be that big of a deal but the need to be fixed nevertheless. Any suggestions on code would be great and hope you enjopy the code. If you find any problems with the code let me know.

Matt

Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Mon, 2005-07-11 07:24

Just an update, My permissions were fixed by my webhost so that mplayer would have full functionality, and everything works. Also i stated that mplayer didnt recognize aspect ratio but it must have just been the codec as the wmv3's that i just generated thumbnails for have the correct aspect ratios. Yeah!!!!!

So it looks as though the few points i had mentioned in the first post are moot as this mod functions exactly as intended for gallery 1.5.

Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Mon, 2005-07-11 07:33

Just noticed something. When the thumbs are built on a wmv3 movie at 30 fps i get a few extra temp jpegs that arent needed so I shortened the length of the temporary movie created by mencoder. Change the .1 to .01 in the following line in AlbumItem.php and it is much mo betta.

$cmd = $gallery->app->use_mencoder." -ss $time -endpos .1 -ovc copy -nosound $dir/$name.$tag -o $tmpThumbFmt.$tmpMovieTyp 2>$tmpThumbFmt.log";
to
$cmd = $gallery->app->use_mencoder." -ss $time -endpos .01 -ovc copy -nosound $dir/$name.$tag -o $tmpThumbFmt.$tmpMovieTyp 2>$tmpThumbFmt.log";

Matt

Login or register to post comments
p51d78th

Joined: 2005-07-18
Posts: 6
Posted: Mon, 2005-07-18 06:23

quick question, what are the intial steps required to instal this

Login or register to post comments
fryfrog

Joined: 2002-10-30
Posts: 3233
Posted: Mon, 2005-07-18 07:03
Quote:
I was unhappy with it because of ffmpegs limited amount of supported codecs. Mainly WMV3.

Is that the main benefit of mplayer vs. ffmpeg? Are there any other benefits that you know of? Any draw-backs?

Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-07-21 03:07

P51d78th
To install this mod you will need to install mplayer on your server. This will add mplayer and mencoder. You can find them here.

http://www.mplayerhq.hu/homepage/design7/dload.html

You should also install the codecs packages. Once you get this installed you can start on the gallery modifications. I dont think you need to install the embedded movie mod but I would suggest you do. It will allow for your movies to play right within gallery. you can find it via the link in the first post. youll just need to copy the files directly over your existing gallery files. Then you can download the mplayer mod via the link in the first post and also install these files directly over your original gallery files on your server. (make backups just in case) also before you copy the albumitem.php onto your server i would suggest you make the change that is in the last of my previous posts. Change the .1 to .01. You can do this in a text editor like notepad. Youll then have the ability to create thumbs for your movies. If you want to be able to highlight your movies and the albums that only have movies you can then attempt to add the code that i provided here as well. You do this the same way, by copying your server files to your pc. Then you open them with the text editor. Make the changes over the existing code and then copying them back to your server. The hardest part of this whole process will probably be getting mplayer installed on your server. I have shell access and was unable to do it myself. I had my webhost do it for me. Then once it was installed i had to call the back to get them to change permissions on a few folders that mplayer wanted access to. After all that it worked like a charm. The highlight mod needs some work but as long as your not deleting or moving the movies around it will work fine. Even then the only problem you will run into on the highlight mod is it not moving the original jpeg created by mplayer around with the rest of the files. you can do this manually. Also if you try to delete an album with my highlight mod youll have to get rid of the directory manually as the jpeg will still be there preventing the directory from being deleted. Good luck and let me know if i can help.

Fryfrog
As far as i understand they both seem to do pretty much the same thing. With mplayer it just took a little extra code because mplayer doesnt have a command similar to ffmpeg's singlejpeg command. Also mplayer supprts a lot more codecs, including Real and windows codecs. I have not noticed any problems so far using mplayer except for the previously stated problem with aspect ratios. But the file that had the prob is a real old one, a wmv1. As far as the mpegs avi's and wmv3s that i have done it does them great. Processing times are fast and the jpegs look great. So as far as drawbacks and advantages go none that i know of except for the codec support.

Login or register to post comments
tidal

Joined: 2004-09-16
Posts: 11
Posted: Thu, 2005-07-21 18:47

good job mattyb... i plan on using this mod when i get some videos to upload

Login or register to post comments
buglerroller

Joined: 2005-07-25
Posts: 28
Posted: Fri, 2005-08-19 19:22

hmm, having server admin install for use, having thumbnail problems as seen here;
http://www.tctunerz.com/index.php?option=com_gallery2&Itemid=42&g2_view=core.ShowItem&g2_itemId=15221

Login or register to post comments
buglerroller

Joined: 2005-07-25
Posts: 28
Posted: Fri, 2005-08-19 20:33

call me a noob if you wish but how does one install this mod?

Login or register to post comments
justchil
justchil's picture

Joined: 2003-02-07
Posts: 225
Posted: Tue, 2005-08-23 13:48

Any success stories yet? I've been unable to get ffmpeg mod to work at all.

Login or register to post comments
Asspalmer

Joined: 2005-10-12
Posts: 1
Posted: Wed, 2005-10-12 22:13

What is the purpose of using mencoder to convert the file to an avi? Can't the same thing be done without using mencoder by doing the following on the mplayer command:

mplayer -nosound -vo jpeg name_of_video_file.wmv -frames 2

So instead of the extra step of using mencoder to create a .01 or .1 second AVI to take the thumbnails from, the -frames 2 flag on the mplayer command will take thumbnails of the first 2 frames of the video file, averting the need for mencoder at all.

The reason it is -frames 2 instead of -frames 1, is because certain filetypes (mpegs to be exact) seem to not produce a thumbnail if 1 is specified.

Anyway, I was wondering if there is any reason you did it the way you did using mencoder, over using the -frames option on mplayer? Is there some pitfall I am overlooking by doing it this way?

Login or register to post comments
rebelstar

Joined: 2005-11-03
Posts: 3
Posted: Thu, 2005-11-03 14:30

Perhaps I'm not understanding the install procedure. Your directions are really straight-forward, but I'm still not seeing thumbnails generated... I just get the generic icon that gallery provides.

I've copied and pasted the code as you've indicated above, understanding it all except for perhaps the second bit of code replacement. I think that if I've made a mistake it is in that bit of code. Can you please show me exactly what code we're replacing/inserting and between which lines exactly we are replacing/inserting that code?

My other concern is that my host hasn't installed the mplayer package and codec packages correctly. I'm not a server guy, so I'm not sure how to do it myself, but is there any direction you can provide here that I can pass along to him? Does the server need to be restarted after installing those packages?

Anyway, I'm excited about this mod and am looking forward to getting it working!

Thanks!

Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Mon, 2005-11-14 10:05

well it has been a while since I have posted but I see there are a few questions so I thought I would chime in. I am no longer using 1.5 so I haven't been playing with these mods. I upgraded to 2. Now I am back to not having thujmbs for my movies as no one has made this same mod to work with G2 and I lack the skills. I looked at modifying the ffmpeg module in G2 and I cant.

Anyways, asspalmer, I was not familiar with mplayer when I wrote the mod, nor am I now. I had seen a suggestion on how to get a jpeg from mplayer somewhere else and modified it for my purposes. I looked through the syntax in the help file included with mplayer and got it to work. My mod works but feel free to modify it and post the cleaner code here. I have no need or desire since I upgraded to G2.

Greg
Other than downloading the zip and changing the numbers in the code from .1 to .01, it should work. The rest of the code changes mentioned above had to do with highlighting the movies and albums containing only movies. If you are not getting thumbnails then you probably do not have mplayer installed correctly. I had some problems getting my to work as my server didnt have the correct permisions on somke of the folders and I was unable to change them via ftp. If I remember right I used the debug mode and was able to see what mplayer was trying to read or write and notified my host of the permisions problems. Once they set up everything correctly it worked perfectly. If you have shell access you should be able to type in the commands that I used in the code (obviously with proper paths and file names not the variables used in the code) and it might give you a heads up as to wether mplayer is working properly. Hope this helps.

PS If anyone is reading this that has some PHP skills, could you please modify the ffmpeg module for G2 or make a new one that utilizes Mplayer. Please. Thanks

Login or register to post comments
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Tue, 2005-11-22 04:08

mattyb

Did you add this to the feature vote?

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Tue, 2005-11-22 11:16

mattyb

this looks really very promising. if it can handle more codecs than ffmpeg and since there seem to precompiled binaries for windows and linux (right?), it looks like the better alternative. i'd suggest we don't modify the ffmpeg module, we should create an mplayer module for g2.
but first get it on feature vote (by filing a RFE on sf.net).

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Tue, 2005-11-22 12:56

why do you use mencoder to generate a short avi?
can't you create a JPG directly from the large movie?

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Tue, 2005-11-22 14:42

* Use mencoder -of help to get a list of output container formats (avi, mpeg)
* Use mplayer -vc help or -vfm help to get a list of decoders
* same with a instead of v for audio
* Use mplayer -vo help to get a list of supported video output drivers (e.g. jpeg)
* Missing!!: command to get available input container formats

do you know a mplayer command to get the available input container formats (avi, mpeg, ...)?

Login or register to post comments
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Wed, 2005-11-23 02:24

Feature was already added - see id 1170042. Yea, everybody go vote for it.

Valiant,
I believe the reason for mencoder is to limit the number of images it outputs. I've used just the commandline mplayer on Linux and it works quite well with WMV9 video's but you need mencoder to limit the capture. Anyways, something to that effect as I've only done it once or twice and didn't read much docs either.
I believe the G1 mod has some comments about it in the code.
What do you mean by, "command to get available input container formats"?

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32356
Posted: Wed, 2005-11-23 04:36
Quote:
What do you mean by, "command to get available input container formats"?

well, optimally, we'd like to know both, which media containers and which codecs are supported by a video toolkit.

container and codec are terms of video / media transport / coding.

containers are the "package" format. avi is a video/audio container format.
codecs encode/decode video/audio data and the result of encoding is stored in a container (e.g. avi).
http://www.google.com/search?hl=en&lr=&safe=off&q=video+container++codec

the container format defines the file extension, usually.

so it would be cool if we could detect both, codecs and container formats. but i only found commands to get a codec list and output container formats, but not input container formats. if we don't know which containers it accepts, we will just try to throw anything at it i guess.

Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-11-24 07:54

Hey Guys
I had seen that it had been added to the feature vote and I gave it a plus 5. I noticed some one yesterday gave it another 5 so it is currently at 12. Doesnt look like the team will be spending anytime on this module anytime soon. I tried to create a whole new module using ffmpeg as a guide, but there is so much going on that I dont even have a clue. Recently I have been trying to just hack the ffmpeg module so that the part that generates the thumbnail is done by mplayer. You would have to have both installed but at least the thumbs would be generated on WMV9. Asspalmers suggestion up above works. This one mplayer -nosound -vo jpeg name_of_video_file.wmv -frames 2. The -vo jpeg tells it to output it as Jpegs and the -frames tells it to only make a few Jpegs. If I was motivated I could redo the original mplayer mod for G1 to reflect these changes, but I am not, especially since I changed to G2. Anyways if I figure out how to make a new module or how to just hack the ffmpeg one I will post it here. Please someone beat me to it. Thanks guys.

Mattyb

Login or register to post comments
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Thu, 2005-11-24 08:21

mattyb,

Heh, that was me who gave it a +5. Well, G2 has always been geared towards photo's vice video's so thats probably why so little attention.
I have a bootload of WMV9 videos but I never had any desire to put them into G2, till recently.
Maybe start a new post in the G2 Module Development forum to gain some awareness and hope someone as tenacious as the guys coding up Google Maps module comes along :-).

EDIT: Someone else requested mplayer awhile ago but looks as the thread died. How about you starting it back up.?
http://gallery.menalto.com/node/28070

valiant,
Should this topic be moved to the Module Development forum?

Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-11-24 12:13

valiant
might just do that.
I am extremely frustrated at the moment. I have been stuck on the same piece of code for about 4 hours now and I am stumped. Maybe you or somebody else here can point me in the right direction. I am hacking ffmpegtoolkit.class. in the function _ffmpeg i comment out the following

$platform->exec(array(array_merge(array($ffmpegPath, '-i', $sourceFilename), $args)));

and replace it with the following. Keep in mind this is just the first steps i am taking trying to get the right commands.

exec('/usr/local/bin/mplayer -nosound -vo jpeg:outdir=/var/www/html/gallery2/modules/ffmpeg/classes/ /usr/local/test/test.wmv -frames 2 2>/var/www/html/gallery2/modules/ffmpeg/classes/temp.log');

This works. I get three jpegs in /var/www/html/gallery2/modules/ffmpeg/classes/ . I then try to replace /usr/local/test/test.wmv with the variable $sourceFilename and I get nothing and no error in the log file. If I replace it with a bad path I get no jpegs (obviously) but I get an error in the log file stating it cant find the file. If I declare a variable at the top, like this

var $jerk;

and then define that variable in the function like this

$jerk = "/usr/local/bin/test.wmv";

I again get no error but also no jpegs. Also I might note that every single log file even when I get the jpegs states "can not find the home directory" even though I dont reference it. What am I doing wrong? I am about to throw my computer out the window as I don't see why this isn't working. Somebody please save my computer. Thanks in advance.

Mattyb

ps I am gonna post this over in the G2 board since we are delving into that and this is the G1 board

Login or register to post comments
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-11-24 12:23

Here is the link to the new thread I started. I didnt want to hijack the one you mentioned Valiant. I put it in G2 Tech zone - Customization. http://gallery.menalto.com/node/40548. See you guys there, and if you havent voted for the mplayer modue, please do so.

Mattyb

Login or register to post comments