Mplayer module - Hacking ffmpeg module to use mplayer for thumb creation

mattyb

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

This is a continuation of this thread.

http://gallery.menalto.com/node/32698

We had gradually changed from talking about G1 to G2 so I figured we had better start this on the G2 side of the house. Any and all help would be appreciated. Please read the above metioned post to see where we are at.

Edit 5/13/2006 Here is the most current version of this module if you do not wish to read the topic or scroll to the end to find the module.

AttachmentSize
mplayer_for_G21_With_WM.zip29.21 KB
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-11-24 13:52

I'd like to move that topic to the G2 Module decvelopment forum and rename it to Mplayer module.
In the end, we want a module for each toolkit and mplayer is another toolkit than ffmpeg.

Are you ok with that?

As I stated in the other topic http://gallery.menalto.com/node/32698, I've started creating a mplayer module. But there is at least one stumbling block.
The question i asked there was:

Quote:
* 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, ...)?

and i explained why we need a list of file formats (containers) that mplayer can handle:

valiant wrote:
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.

and this list shouldn't be hardcoded, since it depends on the available libs / how mplayer was compiled.
so, how do you get a list of the file formats / containers that mplayer can handle?

mattyb
i'm fine if you do the module development, just want to make sure it's going into the right direction.

- you should certainly not output anything to outdir=/var/www/html/gallery2/modules/ffmpeg/classes
we've got g2data/tmp for such operations. you should take a look at how other toolkits manage this.

I've copied the ffmpeg module and removed the watermark option (we can add that back later) and renamed all ffmpeg strings to mplayer:
The mplayer module does NOT work. You need to replace a lot of arguments / operations / ... in MplayerToolkit / MplayerToolkitHelper.class.
Please add your name as name nr. 1 in @author in the files.

http://dev.nei.ch/mplayer-base-not_working.zip

Feel free to ask answers. I guess the toolkit stuff in G2 isn't very intuitive, but you'll learn it, i'm sure.
Good luck :)

 
mattyb

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

Hey Valiant
Actually I wasnt looking to develop the mplayer module as that is way over my head and I wll leave that to the big boys. I was just looking for a quick fix that would in the end have the same result for me and if anyone wanted to use it, them to. I chose that arbitrary directory so that I wouldnt have to keep changing the directory via ftp to see if my code was working. That is by no way what my finished code would look like nor am I any where near finishing it. Anyways, thanks for the help. I hope you or someone else does finish the mplayer module, so I wont have to use my hacked version, but it wont be me.

Thanks again

Mattyb

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-11-24 20:21

well, you have now there a mplayer module (see my link) which is exactly a copy from the ffmpeg module. i just removed watermarking because that only complicates things.
we can add that back later.

so you have there a module which is exactly like the ffmpeg module. so please "hack" this mplayer module instead of the ffmpeg module. in the, you'll have to change the exact same lines. it's not more work if you do that.

since you seem to understand mplayer commands, could you please provide the necessary commands to:
- get a list of supported file types (container types): e.g. avi, mpeg, wmv, ...
- get a list of supported mimetypes (maybe that's the same as the above in this case)
- get a list of supported codecs (i already found this, it's "mplayer -vc help or -vfm help"
- get a list of supported video output drivers (e.g. jpeg). found this already: "mplayer -vo help" (else we can't get jpeg thumbnails)
- find out whether mencoder / mplayer support a time offset such that we can offer to get a thumbnail from second x / frame x iustead of the first frame
- use the offset in mecoder / mplayer when creating the thumbnail

you use the following commands in G1. should we use the same in G2?
// create a movie of a few frames length starting at position $time?
mencoder -ss $time -endpos .1 -ovc copy -nosound $inputFile -o tempFile.avi 2>error.log
// transform this movie in single jpegs
mplayer -nosound -vo jpeg tempFile.avi 2>error2.log

then you check if it was successful, you delete the temp movie and you clean up.

 
mattyb

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

actually i not that familiar with mplayer either. I dont recall where i got the original commands i used in the G1 mod but I believe it was on the gallery website. The new incarnation was from the original post, from a reply by asspalmer. I am going to change back to my original version of uising both mencoder and mplayer so that I can use the affset.
I can apply my hack to your version of the module which I will upload as soon as I get it working. I dont how much time i will have to do it today, as the family is coming over. I am going away for the weekend so i wont get to work on it this weekend either. I think i am progressing fairly well on my hack so as soon as I can sit down for a few hours i think I will be able to finish it. I solved my earlier problem and am working on the next.
Sorry i cant help you on a way to get any supported formats, codecs, or such.

As far as watermarking, I hadnt really looked into that as I dont use watermarking, but does that watermark the thumbnail or the actual movie playing. If it only watermarks the thumb, for my hack, I dont think it will be a problem. Let me know.

Mattyb

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-11-24 22:09

@watermark:
that's not a big issue. it's just the filmreel watermark for movie thumbnails. let's add that later.

in g2, we don't just call the ffmpeg or mplayer toolkit and expect it to just work.
in g2, you must register your toolkit to work for certain mimetypes / file extensions. so if a movie.avi file is added to your gallery, G2 will check if there's a toolkit that can generate thumbnails etc. for .avi files and if so, this toolkit gets called.
that's why we need to find out which filetypes can be handled by mplayer.
i'll ask the mplayer guys.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-11-24 23:45

i just talked to mplayer devs on #mplayerdev irc.freenode.net.

we can use:

mplayer $inputFilename -ss $timeOffsetInSeconds -nosound -vo jpeg:outdir=$outDir -frames 1

to directly generate thumbnails at a certain offset.

note it will always generate 2 thumbnails. 1 for the first frame and the second at the specified time offset! (that's what the dev said)

we also need to identify (dimensions, length) a movie. we can use:
mplayer -identify $inputFileName -nosound -vc dummy -vo null
and then parse for (always showing example output (whole line):
- filetype: ASF file format detected.
- dimensions and format: VIDEO: [MP43] 320x240 24bpp 1000.000 fps 0.0 kbps ( 0.0 kbyte/s)
- video format: ID_VIDEO_FORMAT=MP43
- width (dimensions): ID_VIDEO_WIDTH=320
- height (dimensions): ID_VIDEO_HEIGHT=240
- length in seconds: ID_LENGTH=98.00

i compliled the current cvs version of mplayer. we can get a list of supported filetypes with:
mplayer -demuxer help

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-11-25 00:27

with the above information, we should be able to hack this module together :)

i'm assuming you'll do it, so here are a few hints:

- right now, we only need mplayer, no need to check for mencoder. no need to implement any mencoder functions

- MplayerToolkit.class function _getMovieDimensions
execute mplayer -identify $inputFileName -nosound -vc dummy -vo null
and then parse for the lines
ID_VIDEO_WIDTH
ID_VIDEO_HEIGHT
ID_LENGTH
to get the values

- function performOperation
use the arguments from above, i just found out that seeking (time offset) doesn't always work. then you just get a single jpg of the first frame
for $outDir, use:

global $gallery;
$platform = $gallery->getPlatform();
$slash = $platform->getDirectorySeparator();
$mplayerOutputDir = $platform->tempnam($gallery->getConfig('data.gallery.tmp'), 'mplr_');

then execute:

$gallery->guaranteeTimeLimit(60);
list ($success, $output) = $platform->exec(array($cmd));

then it will generate 1 or more jpg files on success, pick one (the last one) and use it.

check the $success

if (!$success) {
clean up, return error
}

check for the resulting jpg in the $mplayerOutputDir and use it (rename to destfile)
...

then clean up:

if (!$platform->recursiveRmdir($mplayerOutputDir)) {
error handling
}

MplayerToolkitHelper:: function testBinary:
use the mplayer -demuxer help call to find out which filetypes are supported
(call it and parse the result file by file to detect e.g. "AVI" and if you find it, it's supported (= you can return it)

 
mattyb

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

Hello Boys and Girls,

Well I have hacked the ffmpeg module to support thumbnail generation using mplayer. I will post it later in the post but first.

Valiant

It looks as though you have been busy this weekend. You have come up with a lot of good material to start with the creation of a new mplayer module. Since my purpose was to create thumbs for all of my movies, specifically my wmv9's, I really don't have any motivation to create a whole new module for mplayer, other than the giving something back to the gallery community for use of such great program like Gallery. That being said if you would like my help in creating a whole new module I will give what help I can. Please be aware of the following though.

1. I think you are probably overestimating what I can and can't do. Maybe I'm underestinmating me as well, but I don't have the greatest knowledge of Php or of the built in functions of gallery. I am willing to try though.
2. It takes me hours to get something to work the way I intend it to. So in the long run it could be a very long time before we can actually put out something that works.
3. I don't have a whole lot of spare time to do this, so it will be when I can, which again adds to the time it will take for the whole project to be completed.

To everyone else
The following is a replacement file of ffmpegtoolkit.class . I have modified this file to use mplayer for the thumb generation of movie files. What the file specifically does is recreate the thumbs. When a movie is added to the gallery the ffmpeg module steps in and tries to create a thumb. If the format is one that ffmpeg doesnt support, specifically wmv9 it will fail. Well even if it doesnt fail immediately mplayer steps in and recreates the thumb. This obviously adds a little extra server load, but how often do you really create thumbs for movies. You will then end up with a good thumb of you movie.
To create thumbs for movies already on your server you will need to click on the link to edit album. You then need to click on the second tab entitled Album. Scoll down and check the box recreate thumbnails. Click save and the thumbs should be recreated. When you go back to the album I have noticed that not all of the time are the thumbs recreated. First try refreshing your browser. This usually does the trick. If it does not and you still have a movie that does not have a thumb, or has a broken link you can do the following to solve this problem. Below the movie, in the drop down box you should see a link to edit movie. Click on this and you will be brought to the edit movie screen. Click on the third tab entitled thumbnail. You can then change the offset of the thumb if you would like. Click save and the thumb will be created.
I have done a lot of testing on my server and it seems to do what it is supposed to. That being said please back up your files as I dont want anyone blaming me if something goes horriblly wrong. (very unlikely)
Here are the steps to install this mod. You will need ftp access to your server and a text editor.

1. Download the file and unzip.
2. Open the file in your text editor and search for the following $args2. When you find it you will see a path for mplayer. Make sure this is correct. If it isn't put in the proper path.
3. The next line will start $args3 and on that line you will see the following jpeg:outdir=/home/yourname/g2data/tmp. Make sure this path is the correct path for your gallery temp file storage. You will probably only have to change yourname.
4. Then search for $tFile. The path before 00000002.jpg should be the same as in step 3.
5. I run linux, but I would assume that if you have these paths correct then no matter what os your server runs you should be good to go.
6. Ftp your site and make a backup of the file you are going to replace. It is located in your gallery directory. It should be in /gallery2/modules/ffmpeg/classes/ . After you have backed up the file proceed.
7. Overwrite the new file onto your server.
8. Your done.

I hope you guys like the mod, and please let me know if you encounter any problems. You should be aware of the following limitations. The height, width and length of the movie are still generated by ffmpeg but I havent noticed any problems so far on that side of the house. Since mime types are registered with gallery2 via the install, if it is a file type that ffmpegg doesnt recognize at all then I would assume that this mod wont work at all. I made this mod to work on wmv9, and since ffmpeg recognizes wmv1 it therfore recognizes the extention .wmv, thus allthough it cant decode wmv9's to make the thumb, it still allows this backdoor method of thumnail creation. So without any further ado here's the file.

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Mon, 2005-11-28 02:25

I know I was long winded in the previous post but nevertheless I forgot somethings I needed/wanted to say.

Since the new gallery website no longer shows the amount of times an attachment is downloaded, if you download the file could you please post a comment so that I will have some idea of the demand for the mplayer module.

If it wasnt obvious you need both ffmpeg and mplayer to be installed on your server. I am not an expert on that so if you can not figure out how to install them then you will need to contact your host.

Valiant
I know you would have propably prefered I hadnt just hacked the module, but I figured if there was at least something out there for people to create thumbs for wmv9s, it might hold them off until a fully functional module is created, as well as make them happy.

Ok I think Im done writing. Enjoy.

Mattyb

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-11-28 10:30

mattyb
ya, we'll definitely want a mplayer module.
i see that this mod was a lot easier than replacing the other ffmpeg calls too.

btw: you current mod calls mplayer on every operation, not only when ffmpeg fails... if you wanted that it only calls mplayer if ffmpeg fails, you'd have to add a if ($ret->isError()) { your 3 lines here } instead of just "your 3 lines here".

 
fryfrog

Joined: 2002-10-30
Posts: 3236
Posted: Mon, 2005-11-28 17:33

I started to have a go at some of this, looking at the output of mplayer commands, comparing them to ffmpeg ones and so I've made a few inches of progress.

Does anyone else plan on working on this? I'm not doing to well, mainly due to not being a great programmer nor very good with the G2 framework... :)
_________________________________
Support & Documentation || Donate to Gallery || My Website

 
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Tue, 2005-11-29 02:51

Work on it no but I'd be more than willing to test it out and run it through the loops. Just upload your incremental changes and I'll test right along with the development. I have not yet looked at mattyb's latest contribution (I will later tonight) but is the expected design to use ffmpeg as the primary tool for all movie files and automatically failover to mplayer in the case of WMV9 or any movie that it cannot read correctly? Administrative option to use mplayer for all movies?
Guess it might depend on thumbnail output quality.?
Output 5 or 10 thumbnails which displays them and gives you the option of choosing which one to use. Err, perhaps I'm thinking too far ahead, too much coding required, and how many folks would actually like (use) it.
As to the jpeg:outdir=, I assume this applies to whereis/your/g2data/tmp directory.
For me this would be /var/www/localhost/g2data/tmp.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-29 03:27
Quote:
but is the expected design to use ffmpeg as the primary tool for all movie files and automatically failover to mplayer in the case of WMV9 or any movie that it cannot read correctly? Administrative option to use mplayer for all movies?

no.
the goal is a second movie toolkit module additional to ffmpeg. just as imagemagick, gd, netpbm are all image toolkit, we'll have ffmpeg and mplayer as movie toolkit.
and we'll probably introduce a toolkit priority for movies too.

Quote:
Output 5 or 10 thumbnails which displays them and gives you the option of choosing which one to use.

no, at least not first.
fist we'll just allow a time offset for mplayer just as for ffmpeg.
later we can add a feature that lists a thumbnail for every 5 / x minutes or so. similar to video.google.com

@details of the module implementation:
i've described all necessary mplayer commands, operations etc. since my own queue is huge, i'd like to see someone create that mplayer module and i could just answer all questions and give a little guidance.

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Tue, 2005-11-29 03:57

Hello all

Swordfish

The new module will only use mplayer. We will be slowing creating a completely new module using the ffmpeg module as a guide. A whole new module is needed for many reasons. The main one that I see is the fact that when the module is activated the module registers which mime types are to be handled by that module. With mplayer it handles more than what ffmpeg handles. The only reason this mod works in the first place is because of the fact that ffmpeg handles .wmv . It just cant decode wmv9's. With the new module, whatever mplayer can handle will work. If you are willing to do some testing, that's great. Often times I could use another set of eyes to help see what Im doing wrong. What usually takes me the most time is trying to figure out my syntax problems, not the programming direction, so any help would be greatly appreciated.

That being said, Valiant, if you don't have any problems with it I will begin on changing over ffmpegtoolkit over to mplayertoolkit. I have looked at it so much over the past few days, that I think i have a pretty good idea, along with your suggestions, on what to do with it. I realize that when a new module is created from scratch, you basically have to create the whole thing, get it to install and then go from there. If I took that approach I don't think I would ever finish. What I plan on doing is just slowly converting ffmpegtoolkit and ffmpegtoolkithelper over to mplayer versions. Sound good?

Valiant you just posted as I am writing this and I see that you are looking to offer a whole lot of advice. Just from looking at the inc files I know that I will need a whole lot of help on those.

Ok so here is where I need help right now, as I couldnt figure it out when I made this hack and it is something that needs figuring out for the module.

1. In the g1 Mod i was able to use variables in the arguments of mplayer. I could not get it to work with this g2 hack. I asssume because rather than passing the value of the variable it was sending the variable itself. I am assuming it was because in g1 I used $gallery->use_mplayer,(which I am assuming is a function of G1) and in this mod I used the Php function exec. Am I correct? If so how do I work around for this? Here is why I need a workaround. jpeg:outdir=$tmpFiledir needs to be all one word no spaces. To use variables in my args of the G2 hack i used array_merge. If I use array_merge like this array_merge('jpeg:outdir=', $tmpFiledir); I would end up with something like jpeg:outdir= /home/yourname/g2data/tmp , and with that space it doesnt work. So like I said I need some suggestions.

Anyways I'll start on it, and shut up. I have a tendency to write too much.

Laterz

Mattyb

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Tue, 2005-11-29 04:15

would something like this work?
$test = array('jpeg:outdir=', $tmpFiledir);
$jpegoutdir = implode("", $test);

 
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Tue, 2005-11-29 05:14

Thanks for the details guys!
Mattyb,
I tried out your latest FfmpegToolkit on a WMV9 video and it worked great for me :-). Afterward, I then attempted to change the thumbnail by increasing the time offset to 15 seconds. I got an error,

Warning: rename(/var/www/localhost/g2data/tmp/00000002.jpg,/var/www/localhost/g2data/tmp/fmpg_ye6FEe): No such file or directory in /var/www/localhost/htdocs/gallery2/modules/core/classes/GalleryPlatform.class on line 485

which then I get a blank thumbnail. Change the offset to 3 seconds and no errors occured.
The 00000001.jpg is left in the tmp dir. What's wierd is that time offsets from 0 - 13 seconds work but 14 or more seconds produces the above error.

Anyways, you've already made me happy!

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Tue, 2005-11-29 05:39

Swordfish
Thats got me stumped. I don't see why the time would make any difference. I have tried up to 800 seconds and it worked on my server. Oh well, I guess its not perfect. At least you can go to 13 seconds though. I didn't bother to get rid of the 00000001.jpg. I have changed this in the new module though. Glad it works for you though, and im workin on getting the new module goin.

Mattyb

 
mattyb

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

ok here is the first step done. This file is set up to be used with the mplayer module not the ffpmeg module. You would have to rename it and change a few references within the file to make it work in the ffmpeg module. Valiant take a look and let me know what you think. I must be getting better as this only took a couple of hours to do and to troubleshoot. I have tested it and it works.

Mattyb

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-11-29 13:26

mattyb,

cool :)

@$args:
cool, you've understood / successfully mimicked how to speciy arguments for our exec call :) looks good.

@$tmpFilename stuff:
it's ok if it works for now, but we'll have to change this a little since it's not yet multi-user complicant. with your current code, 2 users that upload a movie at the same time would both use the same 000001 0000002 0000003 jpegs in the g2data/tmp dir.
what we'll have to do instead is:
replace
$tmpDir = $gallery->getConfig('data.gallery.tmp');
with

	$platform = $gallery->getPlatform();
	$slash = $platform->getDirectorySeparator();
	$tmpDir = $platform->tempnam($gallery->getConfig('data.gallery.tmp'), 'mplr_');
	list ($success) = GalleryUtilities::guaranteeDirExists($tmpDir);
	if (!$success) {
	    return array(GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__), null, null);
	}

this will create a subdirectory in g2data/tmp with a random name, e.g. g2data/tmp/mplr_3836/
this way user x will create his 000001-0000003 jpgs in this tmp folder and another user will create them in another folder.

@cleanup:
before the last line of performOperation (before return array(......);), add:

/* Remove our tmp dir with all files in it */
if (!$platform->recursiveRmdir($tmpDir)) {
	    return array(GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__), null, null);
}

@_getMovieDimensions:
if (preg_match("/Unknown format/", $resultLine, $regs)) {
won't work for mplayer. i just tested this with my mplayer binary and it doesn't output something special if you feed it with something it can't handle.
you can remove this if case, just use your other if's (length, width, height).
the ffmpeg module doesn't use $unknownFormat anyway, weird. just forget this $unknownFormat.

@function _mplayer:
right now you use this function for 'convert-to-image/jpeg' which expects an output image and for 'dimensions-and-duration' which doesn't have any output.
the problem right now is that you return a $success if mplayer worked but didn't produce any output jpg.
maybe add a 4th param to function _mplayer $requireOutputFile and then do something like:

	if (file_exists($tmpjpegfilename3)) {
		$platform->rename($tmpjpegfilename3, $tmpFilename);
		unlink($tmpjpegfilename2);
		unlink($tmpjpegfilename);
	}else if (file_exists($tmpjpegfilename2)) {
		$platform->rename($tmpjpegfilename2, $tmpFilename);
		unlink($tmpjpegfilename);
	}else if (file_exists($tmpjpegfilename)) {
		$platform->rename($tmpjpegfilename, $tmpFilename);
	} else if (!empty($requireOutputFile)) {
                $success = false;
        }

good work!

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Wed, 2005-11-30 00:42

Ok
I didnt see any of that except for the unknown format which I forgot to ask you about. I have impimented all except the last line of code. It all makes sense why we needed to to do it, I just didn't think of it. I have not tested the changes yet but will probably do that later tonight. I have gone over module.inc. Other than a few changes, like only checking for mplayer and commenting out the part about watermarks I think it is done but I cant test it until mplayertoolkithelper.class is done. Same with adminmplayer.inc and adminmplayer.tpl. What do we do about the language packs? Do we just delete them? So I need to finish up mplayertoolkit.class and then I can continue on mplayertoolkithelper.class which I will need some help on.

Going back to mplayertoolkit
maybe I dont understand why we need to worry about "dim and duration" producing an output? The original ffmpegtoolkit didnt worry about it other than the following line of code in the function _getMovieDimensions

if ($ret->isError() && !($ret->getErrorCode() & ERROR_TOOLKIT_FAILURE)) {
	    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
	}

we currently have this in it's place

if ($ret->isError()) {
	    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
	}

should we and will it fix what youre talking about if we just do that?

also in thinking about this I thought of something else. I will assume the following are possible outcomes of the function _mplayer
1. The function is called to produce the thumbs. mplayer works and the thumbs are generated. --- we are set up to handle this.
2. The function is called to produce thumbs. mplayer works but the thumbs are not generated for what ever reason. ----- currently we will get a broken link, I have placed the old(G1) standard movie thumb in the images folder. Should we assign this instead of allowing a broken link in function _mplayer through the nested ifs?
3. The function is called for dim and duration. Mplayer works and the results are returned ( i still see no need for an object to be created. --- We are set up to handle this.
4. The function is called for either reason and mplayer fails --- we are set up to handle this, but should we assign the generic thumb in this case as well?

Anyways let me know your thoughts.

Mattyb

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-30 01:03

@language packs:
yeah, you can delete the po/locale dirs.

i guess you're referring to:

	/*
	 * Ffmpeg 0.4.6 demands an output file and we're not providing one, so we'll always get a toolkit
	 * failure here.  :-/  Ignore it for now, but fail if we don't get the output we want.
	 */
	if ($ret->isError() && !($ret->getErrorCode() & ERROR_TOOLKIT_FAILURE)) {
	    return array($ret->wrap(__FILE__, __LINE__), null, null, null);
	}

yeah, in mplayer, we don0t have to deal with that. your fix is correct!

@2.
we already have a default thumbnail for movies if the thumbnail module is installed.
better use this default movie thumbnail instead of of a file that you add in your module.
but this shouldn't be solved by your module. we should solve this for all toolkits.
if toolkit fails, use the ThumbnailToolkit.
bottom line: you don't have to handle this stuff and it should be implemented in the core framework.

@3.
yes. we don't need to generate any file here. that's fine

@4.
see @2.

you can file a feature request on http://sf.net/projects/gallery/ to request a change such that we fall back to the default thumbnails from the thumbnail (manager) module if a toolkit fails. please do that :)

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Wed, 2005-11-30 02:50

Here is the mplayertoolkit.class for your review. I believe this is the final version. Let me know if you see anything hinky.

I will go ahead and add that feature request, but first I am going to start on the gallerytoolkithelper.

Mattyb

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Wed, 2005-11-30 03:50

im stuck
if im correct the only time mplayertoolkithelper is called is when the module is installed, so I was trying to install the module but I cant get any error messages that are helpful to me.

Also am I correct in saying that the only change that should be done to the module.inc, adminmplayer.inc and adminmplayer.tpl files are changing ffmpeg to mplayer

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-30 06:01

review:

the following code doesn't make a lot of sense:

	$tmpDir = $platform->tempnam($gallery->getConfig('data.gallery.tmp'), 'mplr_');
	$platform->unlink($tmpDir);       
	$platform->mkdir($tmpDir);
	list ($success) = GalleryUtilities::guaranteeDirExists($tmpDir);
	if (!$success) {
	    return array(GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__), null, null);	
	}
	$tmpFilename = $platform->tempnam($tmpDir, 'mplr_');
	if (empty($tmpFilename)) {
	    /* This can happen if the $tmpDir path is bad */
	    return array(GalleryStatus::error(ERROR_BAD_PATH, __FILE__, __LINE__), null, null);
	}

the unlink isn't required. why did you add it? and guaranteeDirExists includes a mkdir. the code i posted in my last messages was complete...
and you don't have to assume that the tmpDir was bad...no need to check empty($tmpFilename).
it should be:

	$tmpDir = $platform->tempnam($gallery->getConfig('data.gallery.tmp'), 'mplr_');
	list ($success) = GalleryUtilities::guaranteeDirExists($tmpDir);
	if (!$success) {
	    return array(GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__), null, null);	
	}
	$tmpFilename = $platform->tempnam($tmpDir, 'mplr_');
	}
$jpegoutdir = "jpeg:outdir=";
	    $jpegoutdir .= $tmpDir;

i'm quite pedantic right now, but that's just the easiest way to teach our coding guidelines. for variables, we use camel-case. so it should be:

$jpegOutDir = "jpeg:outdir=";
	    $jpegOutDir .= $tmpDir;

:)

and please add:

	/* Remove our tmp dir with all files in it */
$platform->recursiveRmdir($tmpDir);
	}

before each return ...; in function performOperation.
purpose: when we encounter an error, we should first try to clean up (and ignore if the cleaning failed, since we're already dealing with another error).

in function _mplayer:
you're still not checking if any file has been generated at all. i discussed this in a prior post.
after

if (file_exists($tmpjpegfilename3)) {
		$platform->rename($tmpjpegfilename3, $tmpFilename);
		unlink($tmpjpegfilename2);
		unlink($tmpjpegfilename);
	}else if (file_exists($tmpjpegfilename2)) {
		$platform->rename($tmpjpegfilename2, $tmpFilename);
		unlink($tmpjpegfilename);
	}else if (file_exists($tmpjpegfilename)) {
		$platform->rename($tmpjpegfilename, $tmpFilename);
	}

there should be a else if ($outputFileExpected) {
$success = false;
}[/code]
change function _mplayer(..., ..., ...) to function _mplayer(..., ..., ..., $outputFileExpected) {
case. and you should call $this->_mplayer(...., ..., ..., true); when calling it to generate thumbnails.
and call it with ... ,..., ..., false when calling it to get the dimensions and length.

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Wed, 2005-11-30 06:29

first part
it didnt work. I tried it exactly as you had typed it and it would not create a directory. I was getting errors and no directory created, just a temp file. I did research on us2.php.net and found that there was no way to generate a directory with tempnam. There is an example there that I borrowed the relevent parts $platform->unlink($tmpDir); $platform->mkdir($tmpDir); to make it work, which it then did.

next
i can change the cappitalization, not a problem.

next
i thought you only meant right before the last return. I should add that line another four times then, correct?

next
i understand what you mean now by sending outputfileexpected. I thought that it was the nested ifs that checked for the file creation. I though that we had decided that it was unimportant to check wether an object had been created, since the original ffmpeg module did not. I dont see why this is important. I am confused.

Mattyb

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-30 12:32

@guaranteedirexists:
we're already using the exact same pattern in modules/zipcart/classes/ZipCartHelper.class so it's known to work. no mkdir/unlink required.
that's the code that is used there:

$zipBase = $platform->tempnam($gallery->getConfig('data.gallery.tmp'), 'zip_');
	$zipDir = $zipBase . '.dir';
	$zipFile = $zipBase . '.zip';
	list ($success) = GalleryUtilities::guaranteeDirExists($zipDir);

maybe you need to change to a mpl_ prefix (4 letter instead of 5). the .dir shouldn't be necessary. that's added in zipcart for another reason.
what's the error you get? it must have another reason.

@cleanup:
before the last return with error checking (as you have it right now.
additionally before every other return in function performOperation without error checking (a single line).

@outputCheckExpected:
no, i mant something else when we discussed whether is important if an output file is generated. i was referring to operations as get dimensions.
well, of course it's important. if we are told to generate a thumbnail and we don't generate a thumb, then:
1. the function that calls _mplayer still expects a tempfile / a thumbnail and it tries to rename it to the dest filename
2. if we don't tell the caller that we failed, noone knows that there's no real thumbnail for this item.
so let me second this: we must return an error in case mplayer did not even generate a single thumbnail.

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Wed, 2005-11-30 22:56

Valiant
I put all the changes you specified and looked through the code and did some cleanup
I put the guaranteedirexests back in and again and it still didnt work, so i inserted the code for zip base.
The directory is created but the temp file remains. the directory has the .dir on the end of it for its name.
I think the problem that we are haveing is that the file exists when the directory is attempted to be made. This
causes it to fail as you cant put something there with the same name. If I unlink $tmpDir before the $guaranteedirexist
it works. This is how I will leave it.

Take a look.

Mattyb

 
mattyb

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

Well im stuck
As long as you dont have any further problems with mplayertoolkit it is done. As far as I can tell the module.inc
, adminmplayer.inc, and adminmplayer.tpl are more gallery specific in their operations than mplayer specific. They just call functions
and set paths and so forth. The big change within them is to change ffmpeg to mplayer. This has been done.
The mplayertoolkithelper.class file needed to be changed only as far as changing ffmpeg to mplayer and to change the mime type detection.
so the top part where parameters are set is done. The bottom part where offset detection appears to work the same as with ffmpeg, so it
is done. Now for the mime detection. Looking at the original code it appeared, at least to me, that the third if statement would do
basically what we wanted to do with the output of mplayer -vc help. I dont fully understand all of the expressions so I could be wrong
I changed the preg_match search term and deleted the first 2 if sections. I would assume that the module would then be done, but I cant
install it. There are a ton of errors, but I cant figure it out. Here is the error codes I get. Can you help? Here is the module so far.

Error Detail - 
Error (ERROR_BAD_PARAMETER) : /var/www/html/gallery2/modules/core/classes/helpers/../../../../modules/Mplayer/module.inc
in modules/core/classes/helpers/GalleryPluginHelper_simple.class at line 105 (gallerystatus::error) 
in modules/core/classes/helpers/GalleryPluginHelper_simple.class at line 99 (gallerypluginhelper_simple::loadplugin) 
in modules/core/classes/GalleryCoreApi.class at line 187 (gallerypluginhelper_simple::loadplugin) 
in modules/core/AdminModules.inc at line 55 (gallerycoreapi::loadplugin) 
in main.php at line 174 (adminmodulescontroller::handlerequest) 
in main.php at line 87
in modules/core/classes/GalleryEmbed.class at line 153
in /var/www/html/components/com_gallery2/pages/main.php at line 65 (galleryembed::handlerequest) 
in /var/www/html/components/com_gallery2/gallery2.php at line 39
in /var/www/html/index.php at line 182

Mattyb

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-12-01 01:34
I put the guaranteedirexests back in and again and it still didnt work, so i inserted the code for zip base.
The directory is created but the temp file remains. the directory has the .dir on the end of it for its name.
I think the problem that we are haveing is that the file exists when the directory is attempted to be made. This
causes it to fail as you cant put something there with the same name. If I unlink $tmpDir before the $guaranteedirexist
it works. This is how I will leave it./code]
doesn't make sense at all, but you can leave it for now. i'll fix that when i do a final code review and add unit tests.
please just add a comment around these lines, makes it easier to remember...


[code]Now for the mime detection. Looking at the original code it appeared, at least to me, that the third if statement would do
basically what we wanted to do with the output of mplayer -vc help. I dont fully understand all of the expressions so I could be wrong
I changed the preg_match search term and deleted the first 2 if sections. I would assume that the module would then be done, but I cant
install it. There are a ton of errors, but I cant figure it out. Here is the error codes I get. Can you help? Here is the module so far.

no, you'll have to use mplayer -demuxer help, since -vc help just returns the supported codecs, but not the supported filetypes.
mplayer -demuxer help only works with the current cvs version of mplayer. i compiled it on my server and it works...

alternatively, you can use -vc help if you can map codecs to mimeTypes. how would you do that? codecs (wmv3, h263, divx, xvid,..) don't define mimetypes. containers (avi, wmv, mpg, ...) define the mimeType. basically: the container usually determines the the file extension / mimetype, not the codec. you won't deal with video with .xvid extensions. xvid can be used as a codec in .avi files.

so how would you map the output of "mplayer -vc help" to mimetypes? maybe we can assume things... but i don't think there's a strict way.

mplayer -demuxer help on the other hand would be exactly what we want.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-12-01 01:37

Error (ERROR_BAD_PARAMETER) : /var/www/html/gallery2/modules/core/classes/helpers/../../../../modules/Mplayer/module.inc

all module folder names must be lower case
all pluginId must be lower case.

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-12-01 02:11

ok
i fixed the inc files and got it to install without problems other than the mime types, but now I will be able to troubleshoot. Thanks I will start on that now.

Mattyb

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-12-01 04:28

well I really didnt want to upgrade mplayer as I had a helluva time doing it last time. My host had to get
involved because of permissions and it took their slow butts about 2 weeks to accomplish the install. They were
reluctant to change the permissions and do the install as well. I decided to try and install the latest version anyway.
I go to the site and download the tar but everyone I download appears to be corrupted. I cant untar on my server or
my home pc. Do you have a good tar that you could send me? Thanks

Mattyb

 
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Thu, 2005-12-01 04:47

Are you using IE??? Use Firefox to download.

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-12-01 05:44

that didn't work

Mattyb

 
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Thu, 2005-12-01 07:02

Wierd. I just downloaded with no problems. How about FTP.
ftp://download.sourceforge.net/pub/sourceforge/g/ga/gallery
gallery-2.0.2-full.tar.gz

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-12-01 07:12

swordfish
not gallery, mplayer

Mattyb

 
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Thu, 2005-12-01 07:27

Doh! Sorry about that. Let me see what I can find. You lookin for binary, source, either?

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-12-01 07:46

kinda lookin for the newest source to compile on my server.
Valiant wants me to use a new argument only in the newest mplayer.
mplayer -demuxer help

The more I think about it the more I think checking for mime
types is stupid as we already know it handles all five or so that gallery even allows you to have.
mpeg, avi, asf, mov, wmv. In fact what we check mplayer against is a hardcoded list of those five. I think if I
can figure out how to hardcode assign those mimetypes to mplayer i wont even need the new version of mplayer.

Thanks

Mattyb

 
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Thu, 2005-12-01 08:10

mattyb,
I sent you a PM if you still want the latest Mplayer src.

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Thu, 2005-12-01 09:00

Valiant
I started thinking really hard, yeah I know it' bad for me. Anyways I have come to a couple of conclusions.
The mimetype module is it's own module and is unaffected by the mplayer module. currently ther are only eight mimetypes that are video. They are mpeg, asf, avi, mov, mxu, mj2, movie and wmv. With the ffmpeg module they only cared about avi, wmv, mpeg, mov, and asf. These were hardcoded in. The ffmpeg module registered those types so that their thumbs would be handled by ffmpeg. The part of the code that did this was basically nothing more than a whole lot of preg matchs (basically they searched the output of ffmpeg -formats for the following terms, avi, mpeg, asf, wmv1, and mov) If they came across those terms the registered the corresponding mimetype in gallery. I am assuming they did this whole process because earlier versions of ffmpeg didnt support all five. That being said mplayer does support all five and probably all eight. I see no need to do an ellaborate amount of code to check since we know beforehand that these work. Maybe if the search terms(types) had been dynamic I could understand it but since they are not I see no reason to do so. I have coded MplayerToolkitHelper to register those types without checking.
So here is the newly born mplayer module for you to critique and offer suggestions. It is tested and works. I realize that it probably is not up to your standards so I look forward to your suggestions on improvement. You had faith in me while I did not. You were right. Thanks

Mattyb

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-12-01 11:47
Quote:
The more I think about it the more I think checking for mime
types is stupid as we already know it handles all five or so that gallery even allows you to have.
mpeg, avi, asf, mov, wmv. In fact what we check mplayer against is a hardcoded list of those five. I think if I
can figure out how to hardcode assign those mimetypes to mplayer i wont even need the new version of mplayer.

if mplayer can handle more than those 5, we can enlarge the list in modules/core/CoreModuleExtras.inc
e.g. we could add ogg, matroska, ...

Quote:
he ffmpeg module registered those types so that their thumbs would be handled by ffmpeg. The part of the code that did this was basically nothing more than a whole lot of preg matchs (basically they searched the output of ffmpeg -formats for the following terms, avi, mpeg, asf, wmv1, and mov) If they came across those terms the registered the corresponding mimetype in gallery. I am assuming they did this whole process because earlier versions of ffmpeg didnt support all five. That being said mplayer does support all five and probably all eight. I see no need to do an ellaborate amount of code to check since we know beforehand that these work. Maybe if the search terms(types) had been dynamic I could understand it but since they are not I see no reason to do so. I have coded MplayerToolkitHelper to register those types without checking.

wrong. ffmpeg and mplayer depend both quite a large list of containers / codecs, mplayer more than ffmpeg.
but mplayer on server X supports not the same codecs / containers than mplayer on server Y. it's the same for ffmpeg.
the final features and suppported containers / codoecs of mplayer and ffmpeg depend on compile options and on available libraries on the server where the binary is compiled and on shared libraries that are available on the server where the binary is run.

Quote:
So here is the newly born mplayer module for you to critique and offer suggestions. It is tested and works. I realize that it probably is not up to your standards so I look forward to your suggestions on improvement. You had faith in me while I did not. You were right. Thanks

that's great!
i guess from here on it's me who should clean up some little things to make it ready for primetime.
meanwhile, it's already good enough for most users. can you add the module to the user contributed module list on http://codex.gallery2.org -> user conributions?
you just need to sign up on codex, then you can edit pretty much every page on the codex.

what i'll do is:
- check the code for our coding guidelines and correct it
- maybe try to find out if we can deduct from the supported codecs to supported containers, or something like that
- add unit tests
- maybe update some things

 
NBrady

Joined: 2005-10-07
Posts: 77
Posted: Fri, 2005-12-02 06:21

do u need ffampeg for this thing to work?

if not

how do u go about adding the videos?

my host does not allow the ffmpeg

 
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Fri, 2005-12-02 07:32

Sweet!! Nice work! No issues on installing and the error I originally reported with WMV9 video is now gone :-).

 
swordfish
swordfish's picture

Joined: 2004-10-01
Posts: 388
Posted: Fri, 2005-12-02 07:39
NBrady wrote:
do u need ffampeg for this thing to work?

if not

how do u go about adding the videos?

my host does not allow the ffmpeg

You do not need ffmpeg but your host will need the mplayer binary.
Change the Toolkit Priority in Site Admin.
You simply add videos the same as you would add photo's.
Mplayer does the same function as ffmpeg. The difference is that mplayer supports video's encoded with WMV9 codec whereas ffmpeg does not.

 
NBrady

Joined: 2005-10-07
Posts: 77
Posted: Fri, 2005-12-02 17:52

the mplayer toolkit doesnt show up in the toolkit priority tree

what the deal

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-12-02 18:16

yep, only if you have ffmpeg AND mplayer installed, only then you'll see them in the toolkit priority view.

 
NBrady

Joined: 2005-10-07
Posts: 77
Posted: Sat, 2005-12-03 06:25

i cant install ffmpeg because my server does not have it which is why this mplayer thing looks so apealing

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Sun, 2005-12-04 00:24

I would think that if your server wont install ffmpegg for you then they probably wont install mplayer either.

 
NBrady

Joined: 2005-10-07
Posts: 77
Posted: Sun, 2005-12-04 01:52

so to confirm, you need one to have the other?

 
mattyb

Joined: 2005-07-04
Posts: 82
Posted: Sun, 2005-12-04 03:38

no they ar two complete independant modules that both do the same job.
If you use the ffmpeg module you need ffmpeg. If you use the mplayer module you need to have mplayer.
The mplayer module just supports more codecs, specifically the wmv9 codec. They both do the same thing, create thumbnails
for video files. What I was syaing is that if your webhost wont allow you to install ffmpeg then the odds are that they wont
allow you to install mplayer either. Hope this helps you understand.

Mattyb