Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Have Mercy - Video Uploader with ffmpeg


Go to End


8 Posts   1161 Views

Avatar
Pix

Community Member, 158 Posts

13 February 2013 at 12:05pm

I'm trying to build a custom video uploader in SS3, I found this really cool tutorial but it is for SS2:

http://www.sslearn.info/sslearn/creating-flash-video-object-on-silverstripe/

Anyway, usually I am able to figure out the differences but not here, no way, no how. I get big old bomb:
[Warning] Missing argument 3 for FlashVideo::getThumbnail(), called in /Applications/MAMP/htdocs/SS310/framework/forms/UploadField.php on line 298 and defined

and the source is:

	function generateCMSThumbnail() {
		if(!file_exists($this->getCMSThumbFilePath())) {
			$this->getThumbnail($this->stat("cms_thumbnail_width"), $this->stat("cms_thumbnail_height"), $this->getCMSThumbFilePath());
		}
		
		return "<div style=\"text-align:center;width: 100px;\"><a target=\"_blank\" href=\"$this->URL\" title=\"Download: $this->URL\"><img src=\"".$this->getCMSThumbFileName()."\" alt=\"".$this->getCMSThumbFileName()."\" /></a><br /><br /><a style=\"color: #0074C6;\"target=\"_blank\" href=\"$this->URL\" title=\"Download: $this->URL\">Download</a></div>";
	}
	
	function getThumbnail($width, $height, $filedest){
		$videoFile = BASE_PATH."/".$this->Filename;
		if(file_exists($videoFile)){
			$execthumb = FFMPEG_BIN." -i ".$videoFile." -r 1 -s ".$width."x".$height." -f image2pipe -vframes 1 -ss 00:00:01 ".$filedest;
			exec($execthumb);
		}
	}

This is a cool and useful bit of code if there is some SS genius that can figure it out. I don't know if my problem has to do with that I am running on MAMP and SS is having trouble with the assets path, or if it has to do with some SS3 diference I can't spot, or my mmpeg install is not right (but I can run from terminal), or perhaps my brain is just plain fried and I should give this all up, move to the mountains, herd goats and make cheese for a living. I'm leaning towards the goat thing. Have mercy on me pleeeeeeeeeease I've been at this all day :0(

Any ideas?

Avatar
lx

Community Member, 83 Posts

14 February 2013 at 3:10am

For a ss2.4 project we decided not to encode the videos on our server but use www.zencoder.com
And i think this was a very good idea. Of course it depends how many videos you have, because zencoder is not for free.
We use them for encoding videos, but they also offer generating thumbnails.

Avatar
Pix

Community Member, 158 Posts

14 February 2013 at 6:14am

Hi lx,

OK that's interesting, I've never really looked into it but I will check it out. Thanks for the link!

Avatar
Pix

Community Member, 158 Posts

14 February 2013 at 12:46pm

Edited: 14/02/2013 12:47pm

OK, so I had to fix my ffmpeg path and is working nicely with MAMP and SilverStripe. In fact, I even downloaded SS2.4.9 and built out the video uploader from the tutorial and it works GREAT! So then back to SS3 and I can upload videos, they ARE converted, and shown on template! GREAT GREAT GREAT except.......the custom thumbnail still crashes in CMS and I am at my wits end figuring out why, I still get:

Missing argument 3 for FlashVideo::getThumbnail(), called in /Applications/MAMP/htdocs/SS310/framework/forms/UploadField.php on line 298 and defined

So SS3 has problem with the custom thumbnail in the CMS. Can please anyone see why, here is the code for generating the custom thumbnail:

public function CMSThumbnail() {
	return $this->generateCMSThumbnail();
}

function generateCMSThumbnail() {
		if(!file_exists($this->getCMSThumbFilePath())) {
			$this->getThumbnail($this->stat("cms_thumbnail_width"), $this->stat("cms_thumbnail_height"), $this->getCMSThumbFilePath());
		}
		
		return "<div style=\"text-align:center;width: 100px;\"><a target=\"_blank\" href=\"$this->URL\" title=\"Download: $this->URL\"><img src=\"".$this->getCMSThumbFileName()."\" alt=\"".$this->getCMSThumbFileName()."\" /></a><br /><br /><a style=\"color: #0074C6;\"target=\"_blank\" href=\"$this->URL\" title=\"Download: $this->URL\">Download</a></div>";
}

function getCMSThumbFilePath(){
	return VIDEO_PATH."/_thumbnail/CMSthumb_".strtolower($this->Name).".png";
}

function getCMSThumbFileName(){
	return VIDEO_DIR."/_thumbnail/CMSthumb_".strtolower($this->Name).".png";
}

function getThumbnail($width, $height, $filedest){
		$videoFile = BASE_PATH."/".$this->Filename;
		if(file_exists($videoFile)){
			$execthumb = FFMPEG_BIN." -i ".$videoFile." -r 1 -s ".$width."x".$height." -f image2pipe -vframes 1 -ss 00:00:01 ".$filedest;
			shell_exec($execthumb);

		}
}

Like I said, this works fine in 2.4.9, and in SS3 I can upload and convert the videos, but I can't figure out the problem with the custom thumbnail in the CMS. Any ideas?

Avatar
Pix

Community Member, 158 Posts

15 February 2013 at 6:24am

Edited: 15/02/2013 6:25am

Anyone? It's just the custom thumbnail that is supposed to be supplied to the CMS, everything else works. I can't tell why the thumbnail works in SS2.4.9 and not SS3. I don't notice anything that is deprecated, maybe something else?

btw if anyone else has trouble with ffmpeg on MAMP, you probably need to comment out the following lines in MAMP/Library/bin/envars:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

Avatar
Pix

Community Member, 158 Posts

15 February 2013 at 7:20am

Edited: 15/02/2013 7:20am

So for some reason, unless it is something totally different of course, it looks like $this->getCMSThumbFilePath() is not working in the CMS, but in forTemplate it works just fine, there is no complaint. Why would this cause an error in the CMS (and only on SS3), but not in forTemplate? I know there are SS geniuses lurking around here, any ideas at all?!

Avatar
Pix

Community Member, 158 Posts

15 February 2013 at 12:53pm

Edited: 21/02/2013 10:58am

so the following code is causing a problem in the CMS :

VIDEO_PATH."/_thumbnail/CMSthumb_".strtolower($this->Name).".png";

It is all that is returned from "getCMSThumbFileName". Any ideas why this is a problem?

It works just fine in 2.4.9. I can't find anything that is deprecated in the custom file class, really reaching here.....

Avatar
Pix

Community Member, 158 Posts

21 February 2013 at 11:00am

Edited: 21/02/2013 11:04am

So for some reason only a SilverStripe God would know, SS3 did not like 'getThumbnail' function, maybe something is not being properly overridden not that you could tell by that whacky error. So then I change the function name to "makeThumbnail", forgetting about trying to add a custom thumbnail to the CMS and it does not blow up the CMS. At least I am able to generate a custom thumbnail for the front end this way......sigh