on the fly server-side video encoding

Where Penguins and Daemons chill together in the warmth of the Sun.

Moderators: SecretSquirrel, notfred

on the fly server-side video encoding

Postposted on Wed Jun 16, 2010 9:23 am

I run a web server for a group of independent film makers. they produce mostly short films and like to share HD video on their personal websites to help promote themselves during festival season. as of now i have to get the films in .mov from the film makers then i use the adobe file converter that came with cs4 to make FLV files on my mac, then transfer the files to the LAMP server. Not an especially elegant solution. I would pre-fer to have an uplaod script on a page where they can uplaod HD .mov files and have them encoded to webM(vp8) in full resolution then made available for viewing on the web.

also, as of now the film listings and information are stored in a MySQL database, and called via php to the pages, but i have been unable to figure out how to dynamically store the movie files in the database, i just store them in a directory and name them so they are easily found, then type the path into the databse. this also seems fairly round-about to arriving at the place where i would like to be. is there an easy why to store large files in the database itself, or should i just code it to automate what is being done now?

so in all i was wondering if there were free and/or simple to use tools for converting uploaded .mov to an open free format that i could easily code into the website without much issue.

any thoughts and comments are appreciated.
Mathematics is not a language, it’s an adventure. Most mathematics is done with a friend over a cup of coffee, with a
diagram scribbled on a napkin. As Gauss once remarked, “What we need are notions, not notations.”
mthguy
Gerbil
 
Posts: 84
Joined: Thu Nov 06, 2008 3:45 pm
Location: Grand Rapids, Michigan, USA

Re: on the fly server-side video encoding

Postposted on Wed Jun 16, 2010 1:10 pm

You are going to need to do some web development but it should be relatively simple:

1) mencoder will convert just about any format to any other format, although if you can't find a pre-cooked command to go between the formats you are looking for you are in for a world of hurt trying to work out all the options.

2) Leave the files out of the database and just store the filename in the database

So now you need an upload webpage that people put the details in (including the file), it fills in the records in the MySQL database and calls mencoder to convert it.
notfred
Grand Gerbil Poohbah
 
Posts: 3731
Joined: Tue Aug 10, 2004 10:10 am
Location: Ottawa, Canada

Re: on the fly server-side video encoding

Postposted on Wed Jun 16, 2010 2:46 pm

ok, sounds like it is do-able. what would be the easiest way to script the commands needed to call the mencode? can php do that? i am still fairly new at web development, i know php and c as well as java. would one be more desirable than another for this application?
Mathematics is not a language, it’s an adventure. Most mathematics is done with a friend over a cup of coffee, with a
diagram scribbled on a napkin. As Gauss once remarked, “What we need are notions, not notations.”
mthguy
Gerbil
 
Posts: 84
Joined: Thu Nov 06, 2008 3:45 pm
Location: Grand Rapids, Michigan, USA

Re: on the fly server-side video encoding

Postposted on Wed Jun 16, 2010 3:48 pm

PHP has an exec() and a system() function
Evaders99
Gerbil First Class
 
Posts: 145
Joined: Fri May 16, 2008 10:48 am

Re: on the fly server-side video encoding

Postposted on Thu Jun 17, 2010 11:13 am

mthguy wrote:as of now i have to get the films in .mov from the film makers

Unless you and your content providers have a very fast connection, you will probably have troubles with HTTP uploads as the upload script will either time out, exceed the max file upload size or exceed the max post size.
features.file-upload.common-pitfalls
You can override these settings globally in the php.ini file, in an .htaccess file or locally using ini_set().
To prevent opening up your entire server, I think that it would be best to use a .htaccess file for your uploads directory.

If you don't want to do this, you will have to use ftp uploads, but now you have the issue of trying to match the meta data to the file uploads.

mthguy wrote:so in all i was wondering if there were free and/or simple to use tools for converting uploaded .mov to an open free format that i could easily code into the website without much issue.

As others have said, use mencoder or ffmpeg, which are basically the same thing. There are many examples on the web and its usage probably warrants its own thread if needed.

At a high level, my workflow be something like this, if using HTTP uploads:
Content provider:
1. (addnew.php) User completes upload form containing the file upload and the meta data (tags), title, director, actors, whatever, etc.
2. (uploadnew.php) Tags are written to the database with a flag showing the video is unprocessed. Now the video is searchable, but not available (coming soon). The mov file is moved to TODO folder for backend processing. Take a look at the $_FILES superglobal and move_uploaded_file().
End

Backend:
The backend will call a php script via cli scheduled as a cron job.
Now you have 2 options, run the job frequently throughout the day checking for new uploads and processing them if not already converting another. Or you set the job to run over night, processing the previous days uploads. The later delays the time to availability, but if you only have one server, the mencoder process will consume a lot of resources potentially impacting its ability to server pages. So running at 3am has less impact on your end users.

(convert.cli.php) First, the script looks for other running instances of itself, if it finds one, it exits. You don't want to try to convert two mov files at the same time.
Then get a dir listing of the files in the TODO folder. Query the db based on the original file names, stuff that into an array.
Start looping.
Call the mencoder command via one of the Program execution Functions (shell_exec or passthru). Parse the output of the mencoder command.
Do error processing if needed.
Otherwise move the original mov file from the TODO folder to the processed folder, write the processed file path and set the processed flag to complete in the db.
End loop
End

mthguy wrote:also, as of now the film listings and information are stored in a MySQL database, and called via php to the pages, but i have been unable to figure out how to dynamically store the movie files in the database, i just store them in a directory and name them so they are easily found, then type the path into the databse. this also seems fairly round-about to arriving at the place where i would like to be. is there an easy why to store large files in the database itself, or should i just code it to automate what is being done now?


I am not sure how much value you would gain from this. It will help with backups, portability and clustering. But how often do you plan on moving the db, or hosting this site from more than one server? For now, stick with file path pointers in your database. But if you are adamant, this should get you started:
http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx.
Cubical 10
I only know enough to be dangerous.

Do ubuntu? pfsense
cubical10
Gerbil First Class
 
Posts: 184
Joined: Fri Mar 03, 2006 2:52 pm
Location: Montreal


Return to Linux, Unix, and Assorted Madness

Who is online

Users browsing this forum: No registered users and 2 guests