No subject
Mon Sep 11 11:14:39 PDT 2006
$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 amazons 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 Drupals database so that it knows about
all these good things that weve done. Ive 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. Its 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, weve 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
More information about the imc-video
mailing list