--- sites/all/modules/ffmpeg_wrapper/ffmpeg_wrapper.module	2009-04-06 18:14:15.000000000 -0400
+++ sites/all/modules/ffmpeg_wrapper/ffmpeg_wrapperNew.module	2009-04-10 09:43:00.000000000 -0400
@@ -230,7 +230,7 @@ function ffmpeg_wrapper_admin_validate($
 
 
 /* ************************************************ */
-/* Interactions with ffmpeg                         */
+/* Interactions with ffmpeg                         */ 
 /* ************************************************ */
 
 /**
@@ -328,7 +328,8 @@ function ffmpeg_wrapper_vhook_list($path
 
 
 /**
- * Check an incoming file path extension to see if it can be decoded.
+ * Check an incoming file to see if it can be decoded by comparing the file's codec 
+ * and format against the list of decode formats in FFMPEG. 
  *
  * @param $file
  *   A full system filepath.
@@ -336,19 +337,56 @@ function ffmpeg_wrapper_vhook_list($path
  *   TRUE if file is in the list of decodeable files.
  */
 function ffmpeg_wrapper_can_decode($path) {
-  // get the kind of files
+  // get the file formats supported by ffmpeg
   $file_types = ffmpeg_wrapper_get_file_formats('decode');
 
-  // get the data on this file
+  // get the format and codec information on this file
   $file_data = ffmpeg_wrapper_file_data($path);
 
-  // some files have multiple formats attached to them
-  foreach(explode(',', $file_data['video']['codec']) as $type) {
-    // is this type in the array of items that we can decode?
-    if (in_array($type, $file_types)) {
-      return true;
+   // if the file has multiple formats, all formats
+   // must be in $file_types Otherwise, it is 
+   // not supported by ffmpeg.
+  foreach(explode(',', $file_data['format']) as $type) {
+    if (!in_array($type, $file_types)) {
+	return false;
     }
   }
+
+  // At this point, we've verified that the file format can be decoded. 
+  $can_file_format_decode = true;
+
+  // check to see if audio and video codecs can be decoded. 
+   
+  $codecs = ffmpeg_wrapper_get_codecs('decode');
+  
+  if ($file_types) {
+  
+    foreach ($codecs as $codec) { 
+
+      if  ($codec == $file_data["audio"]["codec"] || $file_data["audio"]["codec"] == 'na' ) {
+	$can_audio_decode = true;
+      }
+
+      if ($codec == $file_data["video"]["codec"] || $file_data["video"]["codec"] == 'na') {
+        $can_video_decode = true;
+      }
+
+      if ($can_audio_decode && $can_video_decode && $can_file_format_decode) {
+    
+	// if we have na values for the audio and video codecs, there's nothing to do.
+        if ($file_data["audio"]["codec"] == 'na' && $file_data["video"]["codec"] == 'na') {
+		  return false;
+        }
+        else {
+	      return true;
+        } 
+    
+       }
+	  
+    }
+
+  }
+
   return false;
 }
 
@@ -551,7 +589,7 @@ function ffmpeg_wrapper_get_file_formats
   $cache_id = 'ffmpeg_wrapper_file_formats';
   $cache = cache_get($cache_id, 'cache');
   // do we have cached data?
-  if (! isset($cache->data)) {
+  if (!isset($cache->data)) {
     // if we can't get formats, do not bother
     if (! $formats = ffmpeg_wrapper_run_command('-formats') ) {
       return;
@@ -567,9 +605,10 @@ function ffmpeg_wrapper_get_file_formats
     $encode_formats = array();
 
     $rows = array();
+
     foreach (explode("\n", $formats) as $format) {
       // match the decode, encode, format, description
-      $pattern ='/[ ]*([D ])([E ])[ ]*([a-zA-Z0-9_,]*)[ ]*([a-zA-Z0-9,_ ]*)/';
+      $pattern ='/[ ]*([D ])([E ])[ ]*([a-zA-Z0-9_,]*)[ ]*([^\$]*)/';
       preg_match($pattern, $format, $matches);
 
       $a_format['type'] = $matches[3];
@@ -579,9 +618,9 @@ function ffmpeg_wrapper_get_file_formats
       if ($matches[1] == 'D') {
         $a_format['decode'] = t('yes');
         // we can have multiple types per format
-        $types = explode(',', $a_format['name']);
+        $types = explode(',', $a_format['type']);
         foreach ($types as $type) {
-          $decode_formats[] = $a_format['type'];
+          $decode_formats[] = $type;
         }
       }
       else {
@@ -592,9 +631,9 @@ function ffmpeg_wrapper_get_file_formats
       if ($matches[2] == 'E') {
         $a_format['encode'] = t('yes');
         // we can have multiple types per format
-        $types = explode(',', $a_format['name']);
+        $types = explode(',', $a_format['type']);
         foreach ($types as $type) {
-          $encode_formats[] = $a_format['type'];
+          $encode_formats[] = $type;
         }
       }
       else {
@@ -611,6 +650,7 @@ function ffmpeg_wrapper_get_file_formats
     $output['encode'] = $encode_formats;
     $output['decode'] = $decode_formats;
     $output['row'] = $rows;
+    
     cache_set($cache_id, $output, 'cache', CACHE_TEMPORARY);
   }
   else {
@@ -637,7 +677,8 @@ function ffmpeg_wrapper_file_duration($p
   // do we have any output from ffmpeg already?
   if (! $output) {
     // get duration from ffmpeg
-    $output = ffmpeg_wrapper_run_command("-i $path");
+    // need quotes around the path parameter in case filename has spaces. 
+    $output = ffmpeg_wrapper_run_command("-i \"$path\"");
   }
 
   // parse the output looking for "Duration: 00:02:12"
@@ -674,7 +715,8 @@ function ffmpeg_wrapper_file_duration($p
 function ffmpeg_wrapper_file_data($path = null) {
   if (file_exists($path)) {
     // get duration from ffmpeg
-    $output = ffmpeg_wrapper_run_command("-i $path");
+    // need quotes around the path parameter in case filename has spaces. 
+    $output = ffmpeg_wrapper_run_command("-i \"$path\"");
 
     // get file format
     $pattern = '/Input #0, (.*),/';
@@ -1240,4 +1282,4 @@ function ffmpeg_wrapper_configuration_fo
   );
 
   return $form;
-}
\ No newline at end of file
+}
