FFmpeg Integration

Permalink
I realize this may be beyond the capabilities of some websites, but for sites hosted by the c5 team and for people who host there own sites, this would be an absolutely key tool to have.

A company I am working for was using Drupal to as their CMS because there was a collection of modules called File Framework which used FFmpeg to automatically convert video and audio files into a common MIME type.

For example, one use would upload a MOV file. Another user would upload a WMV file. Another user would upload a AVI file... and so on and so forth. No matter what the file type, FFmpeg converted the movie files to FLV files (actually you could specify what MIME type you wanted, they wanted FLV).

This sort of task may be well over my head, but I'm going to give it a shot.

Any help would be greatly appreciated!

ijessup
 
ijessup replied on at Permalink Reply
ijessup
After some research, it turns out, this is a lot more simple than i initially thought.

Basically, you put the ffmpeg file (I'm using ffmpeg.exe because I'm in windows) somewhere in the concrete directory.

And with PHP you invoke the exec() function like this:

<?php
$input = somefile.mov;
$output = somefile.flv;
exec("ffmpeg -i ".$input." -f flv ".output.");
?>

Pretty simple so far. Now to integrate it with the c5's media manager.
ijessup replied on at Permalink Reply
ijessup
So I've been snooping around in the c5 code trying to dissect it and I cant quite figure out what's happening between al.php and al_upload_process_single.php

My thought process was, find the file being uploaded, put it in a temp folder, find out if it is a video file, run FFmpeg, store the flv and thumbnail generated by FFmpeg into the files folder.
ijessup replied on at Permalink Reply
ijessup
Well, I've been playing around with FFmpeg and trying to get it to work with c5 and so far I have altered the al_upload_process_single.php a little bit.

Basically what I have happening is FFmpeg intercepts the uploaded file only if it has the extensions avi, mov, wmv, mpeg, mpg, and mp4. (I'll make a dashboard page so you can alter these later).

Anyways, FFmpeg intercepts the file. Creates a new file in DIR_FILES_UPLOADED.'/temp/'

This new file become the new value of $_FILES['Filedata']['tmp_name']

At least that is how its supposed to work. I'm having some issues with permissions right now, but I'm working on trying to fix this.

But anyways... that's what I have so far.
ijessup replied on at Permalink Reply
ijessup
I got it! Well its not working on my WAMP server, but it's working like a charm on a MAMP. I have yet to try it out on my Linux box because for some reason it doesn't feel like connecting to my network, but I'll don't think there will be any issues there.

Next step is to design a dashboard page to help set parameters and display any errors.
ScottC replied on at Permalink Reply
ScottC
Great now get on IRC every once in a while so we can eat err... pick your brains :)
ijessup replied on at Permalink Reply
ijessup
I wasn't aware there was a c5 IRC channel.

Then again I've never used IRC before... so yeah... lemmie find a client and I'd be glad to share my codes, thoughts and what nots.
frz replied on at Permalink Reply
frz
Http://concrete5.org/community/chat
ijessup replied on at Permalink Reply
ijessup
I'll get MIRC set up. Is there a particular time in which people are usally on?
ijessup replied on at Permalink Reply
ijessup
So that was a silly error on my part, the code worked all a long. I just didn't have FFmpeg installed on my Vista machine right. Yes I said Vista, spare me the flaming, and no I'm not using IIS. I'm using WampServer2.

Right now, the only possible fault I can see is that there may be a problem when more than one person tries to upload and use FFmpeg at the same time. I only say that because during the upload process, FFmpeg makes a file called "output.flv" in a temp folder in the "files" directory.

The problem being more than one person writing to the same file spells bad news.

So I need to set it up so that FFmpeg spits out a file name that is unique. I may just use a check sum of the original file, I dunno yet. We'll see.

You can try it out on my test server.

Check my profile for the link (its the IP address).

Use this login info:
Username: sandbox
Password: sandbox

This user can upload and edit the "Contribute!" page.

Keep in mind, the Add Multiple Files function does not yet have the FFmpeg integration. Only Quick Add does.

Oh yeah, please don't give me any viruses either... :)
ijessup replied on at Permalink Reply 1 Attachment
ijessup
This is the first version of the FFmpeg Integration. I have not tested this on a live site yet. So you shouldn't use this on a commercial site. This is for testing purposes only.

This will not work unless you have FFmpeg installed. Except for Windows servers. I have included an EXE version of FFmpeg to save you a giant headache, however, I have not tested this on a 64bit machine so if you are running 64bit... you are on your own if it doesn't work.

For Linux go here:
http://atrpms.net/install.html

Then run APT-GET or YUM INSTALL FFMPEG in terminal

(This is the exact method I used to get FFmpeg on my Fedora9 server)

For Max OSX:
http://stephenjungels.com/jungels.net/articles/ffmpeg-howto.html...

(I'm not sure how perfect these instructions are. The Max OSX Server I use is managed by someone else, but these are the instructions I gave them and FFMpeg is working.)

Copy and paste the contents of the attached ZIP file into the ../concrete/tools/ folder. Not the "tools" folder in the root directory, but the one in the "concrete" folder. Unfortunately, at the moment you have to replace a core file.

Voila! Quick and dirty FFmpeg Integration.
ijessup replied on at Permalink Reply
ijessup
Through an odd turn of events, Windows is no longer cooperating with me. (Big surprise...)

Because of this, I have decided that, at least for now, I'm not going to support Windows Servers.

The problem may lie in the fact that I am using WAMP Server 2. But honestly, the headache this has caused me is not worth the effort.

After a fully stable version that works on *nix systems is complete, I may attempt to get it working with Windows. But for now... no.

If someone can figure out why exec("ffmpeg", $ouput) is returning $output as an empty array, even though ffmpeg is functioning properly otherwise... please contact me.

And before you ask, no it is NOT a permissions issue.
ijessup replied on at Permalink Reply
ijessup
Well the block is coming along well. All the FFmpeg functions are written as well as a thumbnail generator.

Basically what is happening is you call the upload function from the FFmpeg block and give it 2 arguments ($upfile, $fname). The first would be the temp file and the second is the name you want to give the file (the .flv and .png extensions are added by the function).

I am a bit stuck though...

I want a new page to be made when the block is installed. I want to have a FFmpeg config page in the dashboard and I'm not sure how to do this...

In my contorller.php file I have:
public function install(){
SinglePage::add("blocks/ffmpeg/config.php");
}

However, I get:
Fatal error: Class 'SinglePage' not found in /var/www/html/blocks/ffmpeg/controller.php on line 5

Thoughts?
andrew replied on at Permalink Reply
andrew
Try loading it with

<?php
Loader::model('single_page');
?>
ijessup replied on at Permalink Reply
ijessup
You sir are a genius!

However, I am far from.

I need to make that page a php file from the ffmpeg folder inside the blocks directory. My thought was just use:("blocks/ffmpeg/config.php") but now that I look at the single page model, that doesn't work.

How would I do that?

I'm guessing it would be easier to use just Page::add?
ijessup replied on at Permalink Reply
ijessup
Well this took me a couple of hours to figure out, but I wrote a parser that queries FFmpeg and gets the supported encoders and decoders. Not sure what I'm going to use this for but I'm sure it will be useful.

I also coded a License parser and a version parser that not only gets the currently installed versions but also the latest version.

Surprisingly, all that took almost 150 lines of code and some interesting work-arounds.

I'm a not quite sure how/what to do about the database. I feel like the files should be handled by the current media manager.

I think I'll use the database only as a way to store settings and arguments rather than any information about files.

Any word on the OnUpload function?
andrew replied on at Permalink Reply
andrew
It is not in the current release candidate, but we will try and get it in for the final 5.2 that we release.
elyon replied on at Permalink Reply
elyon
I can see that this post is several months old, but FFMPEG integration would be an awesome feature to add to concrete5 as part of the core or as an add-on.

Although many videos that users have are not in Flash video format, Flash video is great for sharing content on the web. It would be great to be able to let people upload their own videos and have them converted to the FLV format so that they can use them with an FLV player on their site.

How can FFMPEG be executed on a Unix server? Does this need to be installed in the server, or can it be added in the Concrete directory, like on a Windows server?

Many people have video in formats that are not Flash video, b
Fernandos replied on at Permalink Reply
Fernandos
wow, this totally rocks!

Sir Isaac, you're really blessed!
Every post of you is a joy
ijessup replied on at Permalink Reply
ijessup
I haven't worked on this project in some time, but most of what was said should still be of some relevance.