Index: ffmpeg_wrapper.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ffmpeg_wrapper/ffmpeg_wrapper.module,v
retrieving revision 1.1.2.15
diff -u -p -r1.1.2.15 ffmpeg_wrapper.module
--- ffmpeg_wrapper.module	3 Sep 2008 14:28:33 -0000	1.1.2.15
+++ ffmpeg_wrapper.module	15 Sep 2008 16:25:44 -0000
@@ -1,10 +1,12 @@
 <?php
 
-/* $Id: ffmpeg_wrapper.module,v 1.1.2.15 2008/09/03 14:28:33 arthuregg Exp $ */
-
-// This implements a wrapper for FFmpeg so that we don't have to reinvent the 
-// the wheel everytime we want to do soemthing with video, audio, or images
+// $Id: ffmpeg_wrapper.module,v 1.1.2.15 2008/09/03 14:28:33 arthuregg Exp $
 
+/**
+ * @file
+ * This implements a wrapper for FFmpeg so that we don't have to reinvent the 
+ * the wheel everytime we want to do soemthing with video, audio, or images
+ */
 
 /* ************************************************ */
 /* DRUPAL HOOKS */
@@ -12,8 +14,6 @@
 
 /**
  * Implementation of hook_menu().
- * @param boolean $may_cache
- * @return array of menu items
  */
 function ffmpeg_wrapper_menu($may_cache) {
   $items = array();
@@ -29,16 +29,16 @@ function ffmpeg_wrapper_menu($may_cache)
     $items[] = array(
       'path' => 'ffmpeg_wrapper/output',
       'title' => t('FFmpeg Wrapper'),
-      'callback' => 'ffmpeg_wrapper_output_display',    
+      'callback' => 'ffmpeg_wrapper_output_display',
       'access' => user_access('access content'),
-    );    
+    );
   }
   return $items;
 }
 
 
 /**
- * implementation of hook_perm()
+ * Implementation of hook_perm().
  */
 function ffmpeg_wrapper_perm() {
   return array('administer ffmpeg wrapper');
@@ -46,8 +46,7 @@ function ffmpeg_wrapper_perm() {
 
 
 /**
- * builds the admin form
- * @return drupal form array
+ * Build the admin form.
  */
 function ffmpeg_wrapper_admin() {
 
@@ -69,9 +68,9 @@ function ffmpeg_wrapper_admin() {
     '#default_value' => variable_get('ffmpeg_wrapper_vhook', '/usr/local/lib/vhook'),
     '#description' => t('Absolute path to the FFmpeg vhook directory. No trailing slash. Leave blank if you do not need this'),
   );
-  
+
   // configuration options
-  // only display if we can reach the binary 
+  // only display if we can reach the binary
   if (ffmpeg_wrapper_run_command('')) {
     $form['ffmpeg_wrapper']['mm_ffmpeg_about'] = array(
       '#type' => 'fieldset',
@@ -79,29 +78,29 @@ function ffmpeg_wrapper_admin() {
       '#collapsible' => true,
       '#collapsed' => true,
     );
-    
+
     $form['ffmpeg_wrapper']['mm_ffmpeg_about']['mm_ffmpeg_version'] = array(
       '#type' => 'item',
       '#title' => t('FFmpeg version'),
       '#value' =>  '<blockquote>'. ffmpeg_wrapper_run_command(' -v') .'</blockquote>',
       '#description' => t('Version of FFmpeg running on your system'),
-    ); 
-    
+    );
+
     $form['ffmpeg_wrapper']['mm_ffmpeg_about']['mm_ffmpeg_formats'] = array(
       '#type' => 'item',
       '#title' => t('Supported file formats'),
       '#value' =>  ffmpeg_wrapper_formats_data_display(),
       '#description' => t('File formats that the installed version of FFmpeg supports.'),
-    ); 
-    
+    );
+
     $form['ffmpeg_wrapper']['mm_ffmpeg_about']['mm_ffmpeg_codecs'] = array(
       '#type' => 'item',
       '#title' => t('Installed codecs'),
       '#value' => ffmpeg_wrapper_get_codecs_display(),
       '#description' => t('FFmpeg was either compiled with these codecs, or these are the codecs available on your system'),
-    ); 
+    );
   }
-  
+
   // get a list of the vhooks in the system
   if (ffmpeg_wrapper_vhook_list()) {
     $form['ffmpeg_wrapper']['mm_ffmpeg_vhooks'] = array(
@@ -115,24 +114,21 @@ function ffmpeg_wrapper_admin() {
       '#title' => t('vhook files'),
       '#value' =>  implode('<br />', ffmpeg_wrapper_vhook_list()),
       '#description' => t('List of all the Vhook files found.'),
-    ); 
+    );
   }
   return system_settings_form($form);
 }
 
 
 /**
- * validate the options on the ffmpeg form
- *
- * @param int $form_id
- * @param array $form_values
+ * Validate the options on the ffmpeg form.
  */
 function ffmpeg_wrapper_admin_validate($form_id, $form_values) {
   // make sure we've got the path to the ffmpeg binary
   if (! ffmpeg_wrapper_run_command(null, false, $form_values['ffmpeg_wrapper_path']) && $form_values['ffmpeg_wrapper_path']) {
     form_set_error('ffmpeg_wrapper_path', t('FFmpeg binary was not found on the path you specified. Maybe try a different path?'));
   }
-  
+
   // check and see if we can find the vhook directory
   if (! is_dir($form_values['ffmpeg_wrapper_vhook']) && $form_values['ffmpeg_wrapper_vhook']) {
     form_set_error('ffmpeg_wrapper_vhook', t('The vhook directory was not found on the path you specified. Maybe try a different path?'));
@@ -145,138 +141,152 @@ function ffmpeg_wrapper_admin_validate($
 
 
 /**
- * gets data from ffmpeg
- * @param string $options are the options to run ffmpeg with
- * @param boolean $error_check runs error checking on the output
- * @param string $path overrides the system settings
- * @return output of the command
+ * Get data from ffmpeg.
+ * 
+ * @param $options
+ *   The options to run ffmpeg with.
+ * @param $error_check
+ *   If TRUE, runs error checking on the output.
+ * @param $path 
+ *   Overrides the system settings.
+ * @return
+ *   Output of the command.
  */
 function ffmpeg_wrapper_run_command($options, $error_check = true, $path) {
   if (! $path) {
     $path = variable_get('ffmpeg_wrapper_path', '/usr/bin/ffmpeg');
   }
-  
-  $command =  $path .' '. $options; 
-  
+
+  $command =  $path .' '. $options;
+
   // does binary exist?
   if (! file_exists($path)) {
     return false;
   }
- 
+
   ob_start();
     passthru($command ." 2>&1", $command_return);
     $command_output = ob_get_contents();
   ob_end_clean();
- 
+
   // do error handling if requested
   if ($error_check) {
-    if (! ffmpeg_wrapper_error_check($command_output, $command, true)){
+    if (! ffmpeg_wrapper_error_check($command_output, $command, true)) {
       return false;
     }
   }
 
-  return $command_output; 
+  return $command_output;
 }
 
 /**
- * builds a list of the ffmpeg vhook options installed on this machine
+ * Build a list of the ffmpeg vhook options installed on this machine.
  *
- * @param string $path
- * @return array
+ * @param $path
+ *   Overrides the system settings.
+ * @return
+ *   Array of options.
  */
 function ffmpeg_wrapper_vhook_list($path) {
   static $files;
-  
+
   // if we have a list already
-  if ($files) { 
+  if ($files) {
      return $files;
   }
-  
+
   // build the path
   if (! $path) {
-    $path = variable_get('ffmpeg_wrapper_vhook', '/usr/local/lib/vhook');    
+    $path = variable_get('ffmpeg_wrapper_vhook', '/usr/local/lib/vhook');
   }
-  
+
   // check to see if the directory is correct
   if (is_dir($path)) {
     // open the directory
     if ($dir = opendir($path)) {
       while (($file = readdir($dir)) !== false) {
         // do not this or parrent directory
-        if ($file != "." && $file != "..") { 
-          $files[] = $path .'/'. $file;        
+        if ($file != "." && $file != "..") {
+          $files[] = $path .'/'. $file;
         }
       }
       closedir($dir);
     }
     if (count($files)) {
       return $files;
-    }   
+    }
   }
 }
 
 
 
 /**
- * checks an incoming file path extension to
- * see if it can be decoded 
- * @param $file is a full system filepath
- * @return true if file is in the list of decodeable files
+ * Check an incoming file path extension to see if it can be decoded.
+ * 
+ * @param $file
+ *   A full system filepath.
+ * @return
+ *   TRUE if file is in the list of decodeable files.
  */
-function ffmpeg_wrapper_can_decode($path){
-  $file_types = ffmpeg_wrapper_get_file_formats('decode');  
+function ffmpeg_wrapper_can_decode($path) {
+  $file_types = ffmpeg_wrapper_get_file_formats('decode');
   $path_parts = pathinfo($path);
-  
-  // exception handling  
+
+  // exception handling
   // WMVs are sometimes asf files
-  if (preg_match('/wmv/i', $path_parts['extension'])) {$exception = 'asf';}
-  
-  if ($file_types) { 
+  if (preg_match('/wmv/i', $path_parts['extension'])) {
+    $exception = 'asf';
+  }
+
+  if ($file_types) {
     foreach ($file_types as $file_type) {
       if ($path_parts['extension']) {
         if (stristr($file_type, $path_parts['extension']) || stristr($file_type, $exception) ) {
           return true;
-        } 
+        }
       }
     }
   }
-  return false;  
+  return false;
 }
 
 
 /**
- * gets an array of codec types usable on this system
- * this should probably be smoothed out so that it doesn't rely on
- * text so much
+ * Get an array of codec types usable on this system.
+ * This should probably be smoothed out so that it doesn't rely on text so
+ * much.
  * @ TODO this needs to be rethought to pass params right
- * @param string $ret determins hand back of encode/decode
- * @return is array of codecs or specific encode/decode options
+ * 
+ * @param $ret
+ *   Determins hand back of encode/decode.
+ * @return
+ *   Array of codecs or specific encode/decode options.
  */
-function ffmpeg_wrapper_get_codecs($ret = null) { 
-  
+function ffmpeg_wrapper_get_codecs($ret = null) {
+
   // get formats from ffmpeg
   $output = ffmpeg_wrapper_run_command('-formats');
- 
-  // parse the list 
+
+  // parse the list
   // we know where the codecs are by looking at the output of ffmpeg -formats
   $codecs_formats_pos = strpos($output, "Codecs:");
-  $codecs_formats_pos_end = strpos($output, "Supported file protocols:");  
-  $codecs = substr($output, $codecs_formats_pos, ($codecs_formats_pos_end - $codecs_formats_pos));  
+  $codecs_formats_pos_end = strpos($output, "Supported file protocols:");
+  $codecs = substr($output, $codecs_formats_pos, ($codecs_formats_pos_end - $codecs_formats_pos));
   // remove the extra text
   $codecs = str_replace('Codecs:', '', $codecs);
   // convert to array
   $codecs = explode("\n", $codecs);
 
   foreach ($codecs as $codec) {
-   
-    // match the decode, encode, type, S|D|T options (see: http://lists.mplayerhq.hu/pipermail/ffmpeg-user/2006-January/002003.html) 
+
+    // match the decode, encode, type, S|D|T options (see: http://lists.mplayerhq.hu/pipermail/ffmpeg-user/2006-January/002003.html)
     // name
     $pattern ='/[ ]*([D ])([E ])([ VA])([S ])([ D])([ T])[ ]*([a-zA-Z0-9_,]*)[ ]*([a-zA-Z0-9,_ ]*)/';
     preg_match($pattern, $codec, $matches);
 
     // codec names
     $a_format['name'] = $matches[7];
-    
+
     // get the codec type
     if ($matches[3] == 'A') {
       $a_format['type'] = t('audio');
@@ -285,31 +295,31 @@ function ffmpeg_wrapper_get_codecs($ret 
     else {
       $a_format['type'] = t('video');
     }
-    
+
     // get the decode value
     if ($matches[1] == 'D') {
       $a_format['decode'] = t('yes');
       $decode_formats[] = $a_format['name'];
     }
     else {
-      $a_format['decode'] = t('no');       
+      $a_format['decode'] = t('no');
     }
-   
+
     // get the encode value
     if ($matches[2] == 'E') {
       $a_format['encode'] = t('yes');
       $encode_formats[] = $a_format['name'];
     }
     else {
-      $a_format['encode'] = t('no');          
+      $a_format['encode'] = t('no');
     }
-   
-    if ($a_format['name']) {     
+
+    if ($a_format['name']) {
       $rows[] = $a_format;
     }
-    $a_format = null;    
-  }  
-  
+    $a_format = null;
+  }
+
   switch ($ret) {
     case 'encode':
       return $encode_formats;
@@ -320,14 +330,17 @@ function ffmpeg_wrapper_get_codecs($ret 
     default:
       return $rows;
     break;
-  } 
+  }
 }
 
 
 /**
- * returns a list of codecs in key value form
- * @param string $type audio or video
- * @return array 
+ * Get a list of codecs in key value form.
+ * 
+ * @param $type
+ *   Audio or video.
+ * @return 
+ *   Array of codec names.
  */
 function ffmpeg_wrapper_return_codecs($type) {
   static $codecs;
@@ -340,7 +353,7 @@ function ffmpeg_wrapper_return_codecs($t
   $vcodecs = array();
   if ($codec_list) {
     foreach ($codec_list as $codec) {
-      if ($codec['encode'] == "yes" && $codec['type'] == $type) { 
+      if ($codec['encode'] == "yes" && $codec['type'] == $type) {
         $codecs[$type][$codec['name']] = $codec['name'];
       }
     }
@@ -350,57 +363,61 @@ function ffmpeg_wrapper_return_codecs($t
 
 
 /**
- * helper function to build the list of output formats 
- * on the system
+ * Helper function to build the list of output formats on the system.
  *
- * @return array of key values
+ * @return
+ *   Array of key values
  */
 function ffmpeg_wrapper_output_formats() {
-	static $formats;
-	if (! $formats) {
-		// get all the encoding options		
+  static $formats;
+  if (! $formats) {
+    // get all the encoding options
     $outputs = ffmpeg_wrapper_get_file_formats('encode');
     // rebuild as a select array
     $formats[0] = t('Please select');
-    foreach ($outputs as $output){
-      $formats[$output] = $output;      
+    foreach ($outputs as $output) {
+      $formats[$output] = $output;
     }
-	}
+  }
   return $formats;
 }
 
 /**
- * builds the output rates for each type of bit rate that 
- * ffmpeg offers
+ * Build the output rates for each type of bit rate that ffmpeg offers.
  *
- * @param string $type
- * @return array of key values
+ * @param $type
+ *   Type of bit rate: "ab", "ar", "fps" or "br".
+ * @return
+ *   Array of key values.
  */
 function ffmpeg_wrapper_output_rates($type) {
-	static $rates;	
-	if (! $rates) {
-		$rates = array (		
-	   'ab'  => array(8 => 8, 16 => 16, 32 => 32, 64 => t('64k (default)'), 128 => 128, 192 => 192, 256 => 256),
-	   'ar' => array('11025' => t('11khz'), '22050' => t('22khz'), '32000' => t('32khz'), '44100' => t('44.1khz (default)') ),
-     'fps' => array(10 =>10, 15 => 15, 20 => 20, 25 => t('25 (default)'), 29.97 => 29.97),
-     'br' => array('50k' => t('50kps'), '100k' => t('100kps'), '150k' => t('150kps'), '200k' => t('200kps'), '250k' => t('250kps'), '300k' => t('300kps'), '500k' => t('500kps'), '750k' => t('750kps'), '1000k' => t('1000kps'), '1250k' => t('1250kps'), '1500k' => t('1500kps'), '2000k' => t('2000kps')),
- 		);
-	}	
-	return $rates[$type];	
+  static $rates;
+  if (! $rates) {
+    $rates = array(
+      'ab'  => array(8 => 8, 16 => 16, 32 => 32, 64 => t('64k (default)'), 128 => 128, 192 => 192, 256 => 256),
+      'ar' => array('11025' => t('11khz'), '22050' => t('22khz'), '32000' => t('32khz'), '44100' => t('44.1khz (default)') ),
+      'fps' => array(10 => 10, 15 => 15, 20 => 20, 25 => t('25 (default)'), 29.97 => 29.97),
+      'br' => array('50k' => t('50kps'), '100k' => t('100kps'), '150k' => t('150kps'), '200k' => t('200kps'), '250k' => t('250kps'), '300k' => t('300kps'), '500k' => t('500kps'), '750k' => t('750kps'), '1000k' => t('1000kps'), '1250k' => t('1250kps'), '1500k' => t('1500kps'), '2000k' => t('2000kps')),
+    );
+  }
+  return $rates[$type];
 }
 
 
 /**
- * gets an array of format types usable on this system
- * this should probably be smoothed out so that it doesn't rely on
- * text so much
- * @param string $ret determins what to hand back (encode/decode)
- * @return array of options
+ * Get an array of format types usable on this system.
+ * This should probably be smoothed out so that it doesn't rely on text so
+ * much.
+ * 
+ * @param $ret
+ *   Determins what to hand back (encode/decode).
+ * @return
+ *   Array of options.
  */
-function ffmpeg_wrapper_get_file_formats($ret = null) { 
+function ffmpeg_wrapper_get_file_formats($ret = null) {
   static $rows, $encode_formats, $decode_formats;
- 
-  // only parse if this hasn't been set 
+
+  // only parse if this hasn't been set
   if (! is_array($rows)) {
     $formats =  ffmpeg_wrapper_run_command('-formats');
 
@@ -408,46 +425,46 @@ function ffmpeg_wrapper_get_file_formats
     $startpos = strpos($formats, 'File formats:');
     $endpos = strpos($formats, 'Codecs:');
     $formats = substr($formats, $startpos, $endpos - $startpos);
-    
+
     //remove the header
     $formats = str_replace('File formats:', '', $formats);
-    
+
     $formats = explode("\n", $formats);
- 
+
     $decode_formats = array();
     $encode_formats = array();
 
     foreach ($formats as $format) {
-      
+
       // match the decode, encode, format, description
       $pattern ='/[ ]*([D ])([E ])[ ]*([a-zA-Z0-9_,]*)[ ]*([a-zA-Z0-9,_ ]*)/';
       preg_match($pattern, $format, $matches);
-      
+
       $a_format['type'] = $matches[3];
       $a_format['name'] = $matches[4];
-        
+
       if ($matches[1] == 'D') {
         $a_format['decode'] = t('yes');
         $decode_formats[] = $a_format['type'];
       }
       else {
-        $a_format['decode'] = t('no');       
+        $a_format['decode'] = t('no');
       }
-       
+
       if ($matches[2] == 'E') {
         $a_format['encode'] = t('yes');
         $encode_formats[] = $a_format['type'];
       }
       else {
-        $a_format['encode'] = t('no');          
+        $a_format['encode'] = t('no');
       }
-       
+
       $a_format['description'] = $matches[4];
       if ($a_format['description']) {
         $rows[] = $a_format;
-      }       
-      
-    }  
+      }
+
+    }
   }
 
   switch ($ret) {
@@ -465,10 +482,14 @@ function ffmpeg_wrapper_get_file_formats
 
 
 /**
- * this gets the duration of a video
- * @param string $path is the path to file
- * @param boolean $timecode return time code or seconds
- * @return int is the duration in seconds or timecode as string
+ * Get the duration of a video.
+ * 
+ * @param $path
+ *   The path to file.
+ * @param $timecode
+ *   If TRUE, return time code, otherwise return seconds.
+ * @return
+ *   Duration in seconds as an integer or timecode as string.
  */
 function ffmpeg_wrapper_file_duration($path, $timecode) {
   // get duration from ffmpeg
@@ -479,12 +500,12 @@ function ffmpeg_wrapper_file_duration($p
   preg_match($pattern, $output, $matches);
 
   $time = $matches[1];
-  
-  if (! $timecode) { 
+
+  if (! $timecode) {
     // now we need to convert the time code to seconds
     // get the time into an array
     $time = explode(':', $time);
-    
+
     if ($time[1] != '00') {
       $seconds = $seconds + ($time[0] * 60);
     }
@@ -492,7 +513,7 @@ function ffmpeg_wrapper_file_duration($p
       $seconds = $seconds + ($time[1] * (60*60));
     }
     $seconds = $seconds + $time[2];
-    
+
     $time = $seconds;
   }
 
@@ -501,19 +522,24 @@ function ffmpeg_wrapper_file_duration($p
 
 
 /**
- * checks to make sure that FFmpeg is in the path
- * @return boolean
+ * Check to make sure that FFmpeg is in the path.
+ * 
+ * @return
+ *   TRUE if FFmpeg can be executed, FALSE otherwise.
  */
-function ffmpeg_wrapper_executable(){
+function ffmpeg_wrapper_executable() {
   if (! ffmpeg_wrapper_run_command('')) {
-    return false;     
+    return false;
   }
   return true;
 }
 
 
 /**
- * displays a table of the supported ffmpeg file formats
+ * Display a table of the supported ffmpeg file formats.
+ * 
+ * @return
+ *   The themed HTML form.
  */
 function ffmpeg_wrapper_formats_data_display() {
   $header = array(t('name'), t('type'), t('decode'), t('encode'), t('description') );
@@ -523,7 +549,10 @@ function ffmpeg_wrapper_formats_data_dis
 
 
 /**
- * displays a table of the ffmpeg encoding and decoding options
+ * Display a table of the ffmpeg encoding and decoding options.
+ * 
+ * @return
+ *   The themed HTML form.
  */
 function ffmpeg_wrapper_get_codecs_display() {
   $header = array(t('codec'), t('codec type'), t('decode'), t('encode'));
@@ -533,16 +562,17 @@ function ffmpeg_wrapper_get_codecs_displ
 
 
 /**
- * checks ffmpeg's output for errors and tries to handle them some way
- * @param string $output 
- *   is the output from a shell command
- * @param string $command
- *   the command run
- * @param boolean $watchdog
- *   log errors to drupal's watchdog
- * @return boolean 
- *   true if no errors, false if errors
+ * Check FFmpeg's output for errors and try to handle them some way.
  * 
+ * @param $output
+ *   The output from a shell command.
+ * @param $command
+ *   The command run.
+ * @param $watchdog
+ *   If TRUE, log errors to Drupal's watchdog.
+ * @return
+ *   TRUE if no errors, FALSE if errors.
+ *
  **/
 function ffmpeg_wrapper_error_check($output, $command, $watchdog = true) {
 
@@ -559,9 +589,9 @@ function ffmpeg_wrapper_error_check($out
     '/sh: [0-9a-zA-Z\/]*: not found/i',
   );
 
-  // check for error conditions    
+  // check for error conditions
   foreach ($errors as $error) {
-  	preg_match($error, $output, $matches);
+    preg_match($error, $output, $matches);
     if ($matches[0]) {
       ffmpeg_wrapper_error_log($command, $matches[0], $watchdog);
       return false;
@@ -572,19 +602,19 @@ function ffmpeg_wrapper_error_check($out
 
 
 /**
- * takes error conditions from the conversion process and deals
- * with them according to the admin configuration
- * 
- * @param string $output 
- *   is the command line output
- * @param string $error 
- *   is the problem being reported
- * @param boolean $watchdog 
- *   should we log this?
+ * Take error conditions from the conversion process and deal
+ * with them according to the admin configuration.
+ *
+ * @param $output
+ *   The command line output.
+ * @param $error
+ *   The problem being reported.
+ * @param $watchdog
+ *   If TRUE, log errors to Drupal's watchdog.
  */
-function ffmpeg_wrapper_error_log($command, $error, $watchdog){
+function ffmpeg_wrapper_error_log($command, $error, $watchdog) {
   // create an error log
-  $message = t('FFmpeg failed to convert a file. FFmpeg said: @error Command was: ffmpeg @command', array('@error' => $error, '@command' => $command));  
+  $message = t('FFmpeg failed to convert a file. FFmpeg said: @error Command was: ffmpeg @command', array('@error' => $error, '@command' => $command));
   if ($watchdog) {
     watchdog('FFmpeg', $message, 'WATCHDOG_ERROR');
   }
@@ -592,14 +622,17 @@ function ffmpeg_wrapper_error_log($comma
 
 
 /**
- * creates a path to the called vhook library
- * @param string $name
- * @return full path
+ * Create a path to the called vhook library.
+ * 
+ * @param $name
+ *   The name of the vhook library.
+ * @return
+ *   A full path.
  */
 function ffmpeg_wrapper_path_to_vhook($name) {
-	if ($path = file_exists(variable_get('ffmpeg_wrapper_vhook', '/usr/local/lib/vhook/') . $name)) {
-		return $path;
-	}	
+  if ($path = file_exists(variable_get('ffmpeg_wrapper_vhook', '/usr/local/lib/vhook/') . $name)) {
+    return $path;
+  }
 }
 
 /* ************************************************** */
@@ -607,56 +640,57 @@ function ffmpeg_wrapper_path_to_vhook($n
 /* ************************************************** */
 
 /**
- * takes an output format, returns an array of configuration
- * options. This is a hand built list. Will return default options
- * below to preserver form integrity while switching things
- * @param string $output
- *   this is an output type (eg: flv, avi, mp4, etc)
- * @return string
- */ 
+ * Take an output format and return an array of configuration options.
+ * This is a hand built list. Will return default options below to preserve
+ * form integrity while switching things.
+ * 
+ * @param $output
+ *   An output type (eg: flv, avi, mp4, etc).
+ * @return
+ *   Array of configuration options.
+ */
 function ffmpeg_wrapper_output_rules($output) {
-	// check to see if we have a configuration for this
-	$path = drupal_get_path('module', 'ffmpeg_wrapper');
-	if (file_exists($path .'/conf/'. $output .'.conf')) {
-		require_once($path .'/conf/'. $output .'.conf');
-		return $configuration;
-	}
-
-	// we don't have a configuration setting, load up the defaults
-	// for any thing that we don't have data for. First check 
-	// and see if we have a cache
-	//$cache = cache_get('ffmpeg_wrapper_default_output', 'cache');
-	if (unserialize($cache->data)) {
-	  return unserialize($cache->data);
-	}
-	
-	// no cache, build out the default options
-	$default['audio'] = array(
-	  'ab' => ffmpeg_wrapper_output_rates('ab'),
-	  'ar' => ffmpeg_wrapper_output_rates('ar'),
-	  'acodec' => ffmpeg_wrapper_return_codecs('audio'),
-	);
-	$default['video'] = array(
-	  'fps' => ffmpeg_wrapper_output_rates('fps'),
-	  'br' =>  ffmpeg_wrapper_output_rates('br'),
-	  'vcodec' => ffmpeg_wrapper_return_codecs('video'),
-	);
-	$default['default'] = 'default';
-	
-	cache_set('ffmpeg_wrapper_default_output', 'cache', serialize($default), CACHE_TEMPORARY);
-	
-	return $default;	
+  // Check to see if we have a configuration for this.
+  $path = drupal_get_path('module', 'ffmpeg_wrapper');
+  if (file_exists($path .'/conf/'. $output .'.conf')) {
+    require_once($path .'/conf/'. $output .'.conf');
+    return $configuration;
+  }
+
+  // We don't have a configuration setting, load up the defaults
+  // for any thing that we don't have data for. First check
+  // and see if we have a cache.
+  //$cache = cache_get('ffmpeg_wrapper_default_output', 'cache');
+  if (unserialize($cache->data)) {
+    return unserialize($cache->data);
+  }
+
+  // No cache, build out the default options.
+  $default['audio'] = array(
+    'ab' => ffmpeg_wrapper_output_rates('ab'),
+    'ar' => ffmpeg_wrapper_output_rates('ar'),
+    'acodec' => ffmpeg_wrapper_return_codecs('audio'),
+  );
+  $default['video'] = array(
+    'fps' => ffmpeg_wrapper_output_rates('fps'),
+    'br' =>  ffmpeg_wrapper_output_rates('br'),
+    'vcodec' => ffmpeg_wrapper_return_codecs('video'),
+  );
+  $default['default'] = 'default';
+
+  cache_set('ffmpeg_wrapper_default_output', 'cache', serialize($default), CACHE_TEMPORARY);
+
+  return $default;
 }
 
 /**
- * this displays the output rules as json 
- * 
- * @param string $output
- *   this is an output type (eg: flv, avi, mp4, etc)
- * @return json
+ * Display the output rules as json.
+ *
+ * @param $output
+ *   An output type (eg: flv, avi, mp4, etc).
  */
 function ffmpeg_wrapper_output_display($output) {
-  // get the output rules for this 
+  // get the output rules for this
   if ($rules = ffmpeg_wrapper_output_rules($output)) {
     // now build the JSON out
     print(drupal_to_js($rules));
@@ -666,28 +700,29 @@ function ffmpeg_wrapper_output_display($
 
 
 /**
- * load the js. This is a wrapper function just so other
- * modules can use this
- * @param string $prefix is the standard prefix to the elements that will be modified
- * @param string $bind_element is the name of the element (minus the prefix) that will be modifed
- * @return javascript to head of page
+ * Load the js. This is a wrapper function just so other modules can use this.
+ * 
+ * @param $prefix
+ *   The standard prefix to the elements that will be modified.
+ * @param $bind_element
+ *   The name of the element (minus the prefix) that will be modifed.
  */
 function ffmpeg_wrapper_enable($prefix, $bind_element = '') {
   // because of the way drupal handles form element ids, we have to transform
   // underscores in string to dashes
   $bind_element = str_replace('_', '-', $bind_element);
   $prefix = str_replace('_', '-', $prefix);
-  
+
   drupal_add_js('
     $(document).ready(function () {
       $(\'#'. $prefix . $bind_element .'\').bind("change", function () {ffmpeg_wrapper_update_options("'. $prefix .'", "'. $bind_element .'"); });
-    });',  
+    });',
     'inline');
-	drupal_add_js(array('ffmpeg_wrapper' => array(
-	  'ffmpeg_wrapper_output_url' => url('ffmpeg_wrapper/output/'),
-	  'default_string' => t('default'),
-	  )), 'setting');
-	drupal_add_js(drupal_get_path('module', 'ffmpeg_wrapper') .'/ffmpeg_wrapper.js');
+  drupal_add_js(array('ffmpeg_wrapper' => array(
+    'ffmpeg_wrapper_output_url' => url('ffmpeg_wrapper/output/'),
+    'default_string' => t('default'),
+    )), 'setting');
+  drupal_add_js(drupal_get_path('module', 'ffmpeg_wrapper') .'/ffmpeg_wrapper.js');
 }
 
 
@@ -696,41 +731,40 @@ function ffmpeg_wrapper_enable($prefix, 
 /* ************************************************** */
 
 /**
- * This builds a generic form for any module to implement 
- * ffmpeg configuration. This will give any module the ajax 
- * form configuration updates. Validation and submission need
- * to be handled by the calling module- this only builds the form
- * call this form inside your form function
- * 
- * @param array $configuration 
- *   is configuration data- could be $form_values
- * @param string $prefix 
- *   is a prefix for the form elelements, needed for javascript activation on 
- *   complex forms (eg: media mover)
- * @return array 
- *   drupal form array
+ * Build a generic form for any module to implementm ffmpeg configuration.
+ * This will give any module the ajax form configuration updates. 
+ * Validation and submission need to be handled by the calling module - this 
+ * only builds the form call this form inside your form function.
+ *
+ * @param $configuration
+ *   An array of configuration data - could be $form_values.
+ * @param $prefix
+ *   A prefix for the form elelements, needed for javascript activation on
+ *   complex forms (eg: media mover).
+ * @return array
+ *   A Drupal form array.
  */
 function ffmpeg_wrapper_configuration_form($configuration, $form_prefix = '' ) {
-	        
+
   // enable the javascript configuration options on the output type to use AJAX
   // to update the allowed values
   ffmpeg_wrapper_enable($form_prefix, 'ffmpeg_output_type');
-    
+
   $form['ffmpeg_wrapper'] = array(
     '#type' => 'fieldset',
     '#title' => t("FFmpeg video conversion settings"),
     '#collapsed' => false,
   );
-    
+
   // build the output formats
   $form['ffmpeg_wrapper']['ffmpeg_output_type'] = array(
     '#type' => 'select',
     '#title' => t('Output format'),
     '#options' => ffmpeg_wrapper_output_formats(),
     '#default_value' => $configuration['ffmpeg_output_type'],
-    '#description' => t('Select the output format. Note, some formats may require setting audio or video codecs.'),   
+    '#description' => t('Select the output format. Note, some formats may require setting audio or video codecs.'),
   );
-  
+
   // ---------------------------------------------
   // Audio options
   $form['ffmpeg_wrapper']['audio'] = array(
@@ -744,7 +778,7 @@ function ffmpeg_wrapper_configuration_fo
     '#title' => t('Use advanced settings'),
     '#description' => t('Use the advanced audio encoding options. If this is off, FFmpeg will encode at a rate similar to the source material.'),
     '#default_value' => $configuration['ffmpeg_audio_advanced'],
-  );  
+  );
   $form['ffmpeg_wrapper']['audio']["ffmpeg_audio_ab"] = array(
     '#type' => 'select',
     '#title' => t('Audio bit rate'),
@@ -758,16 +792,16 @@ function ffmpeg_wrapper_configuration_fo
     '#options' => ffmpeg_wrapper_output_rates('ar'),
     '#default_value' => $configuration['ffmpeg_audio_ar'] ? $configuration['ffmpeg_audio_ar'] : 44100,
     '#description' => t('Audio sample rate for conversion.'),
-  );  
+  );
   // set the audio codec in use
   $form['ffmpeg_wrapper']['audio']["ffmpeg_audio_acodec"] = array(
     '#type' => 'select',
     '#title' => t('Audio codec'),
     '#options' => ffmpeg_wrapper_return_codecs('audio'),
     '#default_value' => $configuration['ffmpeg_audio_acodec'] ? $configuration['ffmpeg_audio_acodec'] : null ,
-    '#description' => t('Select the codec for the output format. Please note, you may need to pick an appropriate video codec for the transcoding. WARNING the codec support right now is experimental. Things may not work as expected.'),   
+    '#description' => t('Select the codec for the output format. Please note, you may need to pick an appropriate video codec for the transcoding. WARNING the codec support right now is experimental. Things may not work as expected.'),
   );
-  
+
   // -------------------------------------------
   // Video options
   $form['ffmpeg_wrapper']['video'] = array(
@@ -781,7 +815,7 @@ function ffmpeg_wrapper_configuration_fo
     '#title' => t('Use advanced settings'),
     '#description' => t('Use the advanced video encoding options. If this is off, FFmpeg will encode flv at 200 kb/s, 128x96, 25fps.'),
     '#default_value' => $configuration['ffmpeg_video_advanced'],
-  );    
+  );
   // video frame size
   $frame_size = mm_ffmpeg_frame_sizes();
   $frame_size['other'] = t('Other');
@@ -810,23 +844,23 @@ function ffmpeg_wrapper_configuration_fo
     '#options' => ffmpeg_wrapper_output_rates('fps'),
     '#default_value' => $configuration['ffmpeg_video_fps'] ? $configuration['ffmpeg_video_fps'] : 25,
     '#description' => t("Sets the frames per second of the converted video."),
-  );    
+  );
   $form['ffmpeg_wrapper']['video']['ffmpeg_video_br'] = array(
     '#type' => 'select',
     '#title' => t('Video bit rate'),
     '#options' => ffmpeg_wrapper_output_rates('br'),
     '#default_value' => $configuration['ffmpeg_video_br'],
     '#description' => t('Target the output video to this bit rate.'),
-  );    
+  );
   $form['ffmpeg_wrapper']['video']['ffmpeg_video_vcodec'] = array(
     '#type' => 'select',
     '#title' => t('Video codec'),
     '#options' => ffmpeg_wrapper_return_codecs('video'),
     '#default_value' => $configuration['ffmpeg_video_vcodec'],
-    '#description' => t('Select the codec for the output format. Please note, you may need to pick an appropriate audio codec for the transcoding.'),   
-  );  
-  
-  
+    '#description' => t('Select the codec for the output format. Please note, you may need to pick an appropriate audio codec for the transcoding.'),
+  );
+
+
   $form['ffmpeg_wrapper']['time'] = array(
     '#type' => 'fieldset',
     '#title' => t('Video duration'),
@@ -847,7 +881,7 @@ function ffmpeg_wrapper_configuration_fo
     '#default_value' => $configuration['ffmpeg_time'],
     '#description' => t("Set the max video length time."),
   );
-  
+
   // FFmpeg custom command
   $form['ffmpeg_wrapper']['custom'] = array(
     '#type' => 'fieldset',
@@ -867,10 +901,10 @@ function ffmpeg_wrapper_configuration_fo
     '#description' => t('You can craft your own FFmpeg command. Please see the FFmpeg documentation for correct syntax. The command will replace <em>%in_file</em> and <em>%out_file</em> with the generated files. Please note, you can not use | or > in your commands.'),
     '#default_value' => $configuration['ffmpeg_video_custom_command'] ? $configuration['ffmpeg_video_custom_command'] : '-i %in_file %out_file',
   );
-    
+
   // Watermarking options
   // only display if we have access to the watermarking files
-  if (ffmpeg_wrapper_path_to_vhook('watermark.so')) {    
+  if (ffmpeg_wrapper_path_to_vhook('watermark.so')) {
     $form['ffmpeg_wrapper']['watermark'] = array(
       '#type' => 'fieldset',
       '#title' => t('Video watermark settings'),
@@ -892,7 +926,7 @@ function ffmpeg_wrapper_configuration_fo
     );
   }
 
-  // file chmod settings, maybe legacy..... 
+  // file chmod settings, maybe legacy.....
   $form['ffmpeg_wrapper']['file'] = array(
     '#type' => 'fieldset',
     '#title' => t('File settings'),
