[IMC-Video] flash player recipe
mark burdett
mark at indymedia.org
Tue Sep 12 02:49:07 PDT 2006
and, boot up an amazon ec2 to handle the video conversion... ;)
flash is apparently user-friendly for a lot of folks, i'd be happy as
long as there was a "download the original" link.
i wouldn't put indymedia stuff online @ s3, given the potential for
copyright/other legal issues. maybe it could work with a local backup.
--mark
On Tue, 12 Sep 2006 00:59:25 -0700, lotu5 at resist.ca wrote:
> We reall, really need to do something like this for video.indymedia.org
> using nimiq or whatever its next incarnation is:
>
> http://www.tunaspecial.com/?p=162
>
> also, some other great featuers of youtube that make people use it a lot are:
>
> - user accounts
> - rss feeds and subscriptions
> - comments
> - messaging
> - tags, allowing "related videos"
>
> here's the full posting from arthur's blog post, found on
> indyblogs.protest.net:
>
> A Drupal youtube Site Recipe
>
> Overview
> This describes a Drupal project to create a youtube style video sharing
> site. There are two major pieces that this project dealt with that stretch
> the project:
> # converting users? uploaded files into a multi-platform format (flv flash
> videos)
> # hosting the uploaded content with amazon?s s3 services
>
> The project ended up breaking the upload process apart from the conversion
> and media hosting processes. Since Drupal already does a good job of
> getting media on to a machine, what seemed an appropriate way to conserve
> hardware cycles was to break the conversion process out in a separate
> script. This script uses the Drupal database to find out what files it
> needs to process, processes them, then moves them, pushes them over to the
> s3 servers, and then updates the Drupal database with urls to the media.
>
> Why not the Drupal video module?
> Given that there is a preexisting Drupal video module which does a nice
> job of embedding media in the page, why go the route of writing custom
> script?
>
> Well there are several reasons for this, one of the primary reasons is
> that the Drupal file system management isn?t yet up to the task of
> integrating to an off site server easily.
>
> Secondly, I wanted to break the processing side out from the uploading, so
> that in the event of large numbers of simultaneous uploads, the strain on
> the server could be moderated. While ffmpeg doesn?t hit the server that
> hard, it?s isn?t hard to imagine that a few uploads and a few conversions
> happening concurrently could really load up a machine.
>
> Why use CCK?
> Part of the thinking behind this project is an attempt to stay as ?in the
> box? as possible- instead of writing large numbers of custom modules to
> handle the specifics of things, I figured we could use CCK, use a few
> tricks (like the form_alter and nodeapi hooks) to make the upload process
> function more elegantly.
>
> Secondly, CCK offers greater flexibility for integration with views,
> increasing the amount of data collected in the future, and so on.
>
> Let?s get started
> Let?s assume you?ve got Drupal all setup and a CCK content type created
> for your videos. There are two things you?re going to need to add to that
> content type:
> # a amazon url
> # a thumbnail path
>
> I created a custom module which uses the form alter hook to hide these
> when the user creates their video, but you don?t need to do this.
>
> So now we?ve got some information about how to start finding out files we
> need to process- because no newly uploaded file will have an amazon url,
> we know that we can use this as a point of reference for what needs to get
> processed. Obviously, this is an assumption that holds true in my system-
> you need to make sure that when you?re getting your list of files that you
> choose an appropriate way to select them.
>
> $query = "SELECT files.filepath, files.nid FROM files " .
> "LEFT JOIN ". $drupal_cck_content_table . " ON files.nid = ".
> $drupal_cck_content_table . ".nid " .
> "LEFT JOIN node ON node.vid = ". $drupal_cck_content_table . ".vid " .
> "WHERE ". $drupal_cck_content_table . "." . $drupal_cck_amazon_url_field
> ." = ''";
>
> >From here, I?ve got files and nids that I can use to my heart?s content.
> My next step is to process these files. We can do this fairly simply:
>
> $command = "$path_to_ffmpeg -i $file_path -acodec mp3 -ar 22050 -ab 32
> -vcodec flv -s " . $output_width . "X" . $output_height ." $flv_output";
> exec($command, $data );
>
> Note that you should have the ?enable-mp3lame and ?enable-faad support
> compiled into ffmpeg to be able to convert avi and mov files into flash.
>
> We should also create a thumbnail for this video:
> $command = "$path_to_ffmpeg -y -i $file_path -vframes 1 -ss $thumb_time
> -an -vcodec mjpeg -f rawvideo -s " . $thumb_width . "X" . $thumb_height ."
> $thumb_path";
> exec($command, $data);
>
> You may want to move the file to a different location at this point- I
> move my source files to an archive so that if media needs to be
> reconverted, that can happen.
>
> Now we need to move the flv file to amazon?s s3. I used the storage3
> library which made this straight forward:
>
> $s3=new storage3($myAccessKeyId, $mySecretAccessKey, $url);
> // put file on amazon
> $s3->putFile($file_path, $bucket, $file_name);
> // set the ACL
> $s3->setACL($bucket, $file_name);
> return "http://s3.amazonaws.com/" . $bucket . "/" . $file_name;
>
> At this point, we need to update Drupal?s database so that it knows about
> all these good things that we?ve done. I?ve stored output from the various
> functions so far in $files.
>
> // update files directory with the new path
> $query = "UPDATE files SET filepath = '". $file['archived_file'] . "'
> WHERE nid = '". $file['nid'] . "'";
> query_db($query);
> $query = "UPDATE $drupal_cck_content_table SET
> $drupal_cck_amazon_url_field = '" . $file['amazon_url'] . " WHERE nid =
> '". $file['nid'] . "'";
> query_db($query);
> $query = "UPDATE $drupal_cck_content_table SET
> $drupal_cck_thumbnailpath_field = '". $file['thumb']."' WHERE nid = '".
> $file['nid'] . "'";
> query_db($query);
> $query = "UPDATE node SET status = 1 WHERE nid='". $file['nid'] . "'";
> query_db($query);
> $query = "TRUNCATE cache";
> query_db($query);
>
> Note that here I publish the node (by default, the node does not publish
> when the user uploads), and I truncate the cache table. It?s unfortunate
> to do this, however, I was running into problems with cached node data,
> and the brute force approach seemed to do the job.
>
> I have this script running off cron, so it will batch process if
> necessary. Obviously there is much missing here- I will publish my script
> once I have it cleaned up and presentable. I just wanted to share one
> approach to doing this.
>
> Finally, we?ve got to theme the video node. I made a specific template for
> my node and used the following:
>
> $the_path_to_player = base_path() . path_to_theme() .
> "/flash_flv_player/flvplayer.swf";
> $the_movie = "$the_path_to_player?file=".
> $node->field_amazon_flv_file_url[0][value] . "&autostart=trueℑ=" .
> base_path() . file_directory_path() . "/" .
> $node->field_thumbnail_path[0][value];
>
> $params = array(
> "allowScriptAccess" => "sameDomain",
> "quality" => "high",
> "height" => "240",
> "width" => "320",
> "movie" => "$the_movie" ,
> );
>
> drupal_add_js(drupal_get_path('module','swfobject') . "/swfobject.js");
> print swfobject_create($the_movie, $params);
>
> Once you stitch all this together, you get a pretty nice system.
>
> Drupal modules
> # CCK
> # Views
> # Voting API
> # UserReview
> # swfObject
> # upload
> # a custom module that modifies the cck fields for uploading
>
> References
> # ffmpeg : http://ffmpeg.mplayerhq.hu/
> # php s3 library : http://blog.apokalyptik.com/Storage3/
> # flash flv player : http://tunaspecial.com/?feed=rss2
> # Video Blogging using Django and Flash(tm) Video (FLV) :
> http://blog.go4teams.com/?p=56
>
>
>
>
> _______________________________________________
> imc-video mailing list
> imc-video at lists.indymedia.org
> http://lists.indymedia.org/mailman/listinfo/imc-video
More information about the imc-video
mailing list