--- sites/all/modules/ffmpeg_wrapper/ffmpeg_wrapper.module	2009-03-16 09:10:02.000000000 -0400
+++ sites/all/modules/ffmpeg_wrapper/ffmpeg_wrapperNew.module	2009-03-21 21:57:29.000000000 -0400
@@ -324,7 +324,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.
@@ -334,23 +335,51 @@ function ffmpeg_wrapper_vhook_list($path
 function ffmpeg_wrapper_can_decode($path) {
   $file_types = ffmpeg_wrapper_get_file_formats('decode');
   $path_parts = pathinfo($path);
+  
+  // gets codec and format information about the file. 
+  $file_data = ffmpeg_wrapper_file_data($path); 
 
-  // exception handling
-  // WMVs are sometimes asf files
-  $exception = '';
-  if (preg_match('/wmv/i', $path_parts['extension'])) {
-    $exception = 'asf';
-  }
-
+  // if the file matches a valid format code, or the movie is in a quicktime format, 
+  // it passes since it's a format supported by ffmpeg.
   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;
-        }
+      if (stristr($file_type, $file_data['format']) || $file_data['format'] == 'mov,mp4,m4a,3gp,3g2,mj2') {
+	    $can_file_format_decode = true;
+		break;
       }
     }
   }
+  
+   // check to see if 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 ($file_data["audio"]["codec"] == 'na' && $file_data["video"]["codec"] == 'na') {
+		  return false;
+        }
+        else {
+	      return true;
+        } 
+    
+	  }
+	  
+    }
+  }
+
   return false;
 }
 
@@ -670,7 +699,7 @@ function ffmpeg_wrapper_file_duration($p
 function ffmpeg_wrapper_file_data($path = null) {
   if ($path) {
     // get duration from ffmpeg
-    $output = ffmpeg_wrapper_run_command("-i $path");
+    $output = ffmpeg_wrapper_run_command("-i \"$path\"");
 
     // get file format
     $pattern = '/Input #0, (.*),/';
@@ -702,15 +731,53 @@ function ffmpeg_wrapper_file_data($path 
     $file['audio']['ab'] = !empty($matches[1]) ? $matches[1] : 'na';
 
     // get video settings
-    // format is: codec, filetype?, frame size, kb/s
     // Everything after frame size is optional, as it isn't always there.
-    $pattern = "/Video: ([^, ]*), ([^, ]*), ([0-9x]*)( \[.*\], ([0-9]*))?/";
-    preg_match($pattern, $output, $matches);
-    $file['video']['codec'] = !empty($matches[1]) ? $matches[1] : 'na';
-    // $file['video']['type'] = $matches[2];
-    $file['video']['s'] = !empty($matches[3]) ? $matches[3] : 'na';
-    $file['video']['br'] = !empty($matches[5]) ? $matches[5] : 'na';
-
+    // $pattern = "/Video: ([^, ]*), ([^, ]*), ([0-9x]*)( \[.*\], ([0-9]*))?/";
+    // $pattern = "/Video: ([^,]+), ([^,]+), ([0-9x ]*)[^,]*, ([0-9]*.*[\/s]*|[A-Za-z]+[^,]*), ([0-9\.]*)/";
+	
+	// try pattern that takes into account a codec's color space (example: yuv420p)
+	// eg: Video: mpeg1video, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 990 kb/s, 30.00 tb(r)
+	// the above is: codec, color space, frame size, bitrate, frame rate
+	$pattern = "/Video: ([^,]+), ([^,]+), ([0-9x]+)[^,]*, ([0-9]*.*\/s|[A-Za-z]+[^,]*), ([0-9\.]*)/";
+	$successPattern = preg_match($pattern, $output, $matches);
+	
+	// pattern that omits video bitrate but not color space. 
+	// eg: Video: mpeg4, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 23.98 tb(r)
+	// the above is: codec, color space, frame size, frame rate
+	$pattern2 = "/Video: ([^,]+), ([^0-9][^,]*), ([0-9x]+)[^,]*, ([0-9\.]*)/";
+	
+	// pattern that omits a codec's color space and video bitrate
+	// eg: Video: mpeg4, 640x480, 29.97 tb(r)
+	// the above is: codec, frame size, frame rate
+	$pattern3 = "/Video: ([^,]+), ([0-9x]+)[^,]*, ([0-9\.]*)/";
+	     
+	if (!$successPattern) {
+	
+	  $successPattern2 = preg_match($pattern2, $output, $matches);
+	  
+	    if (!$successPattern2) {
+		
+			  $successPattern3 = preg_match($pattern3, $output, $matches);
+              $file['video']['codec'] = !empty($matches[1]) ? $matches[1] : 'na';
+              $file['video']['s'] = !empty($matches[2]) ? $matches[2] : 'na';
+              $file['video']['br'] = 'na';	
+		}
+		else {
+              $file['video']['codec'] = !empty($matches[1]) ? $matches[1] : 'na';
+              $file['video']['s'] = !empty($matches[3]) ? $matches[3] : 'na';
+              $file['video']['br'] = 'na';	
+		}
+	    
+	} 
+	else {
+	
+      $file['video']['codec'] = !empty($matches[1]) ? $matches[1] : 'na';
+      // $file['video']['type'] = $matches[2];
+      $file['video']['s'] = !empty($matches[3]) ? $matches[3] : 'na';
+      $file['video']['br'] = !empty($matches[4]) ? $matches[4] : 'na';
+	
+	}
+	
     return $file;
   }
 }
