--- video_thumbnailer_or.module	Wed Apr 02 23:05:28 2008
+++ video_thumbnailer.module	Thu Nov 27 00:44:11 2008
@@ -32,13 +32,15 @@ function video_thumbnailer_nodeapi(&$nod
   }
   
   // add vtid to nodes
-  $enabled_types = variable_get('vtm_content_types', array());
-  if ($op == 'load' && $enabled_types[$node->type]) {
+  //Deleted, because vtm_content_types not saved anywhere, and the load process never called
+  //$enabled_types = variable_get('vtm_content_types', array());
+  //if ($op == 'load' && $enabled_types[$node->type]) {
+  if ($op == 'load') {
     $vtid = db_result(db_query('SELECT vtid FROM {video_thumbnailer_node} WHERE nid = %d', $node->nid));
     if ($vtid) {
       return array('video_thumb_choice' => $vtid);
     }        
-  }
+  }    
   
 }
 
@@ -134,7 +136,8 @@ function video_thumbnailer_config($confi
       '#collapsed' => false,
     );
   
-    $frame_sizes = mm_ffmpeg_frame_sizes();
+    $frame_sizes = ffmpeg_wrapper_frame_sizes();    
+
     $frame_sizes['other'] = t('Other');
     $form['video_thumbnailer']['thumbnailer_size'] = array(
       '#type' => 'select',
@@ -309,15 +312,26 @@ function video_thumbnailer_process($file
     }
    
     // make sure there aren't error conditions 
-    if ($new_thumb) { 
+    if ($new_thumb) {
+      // store this thumb in our db
+      //video_thumbnailer_save_thumb($file, $new_thumb);
+      $vtid = video_thumbnailer_save_thumb($file, $new_thumb);
+      //Should we save the first thumbnail as the selected thumbnail by default?
+      if (! $firstfilename) {
+        db_query('INSERT INTO {video_thumbnailer_node} (nid, vtid) VALUES (%d, %d)', $file['nid'], $vtid);
+      }
+
       // is this the first output file, save to $file array
-      if (! $file['process_file']) {
+      //Removed, because Media Mover set this in media_mover_api_run_config_verb_file function
+      /*if (! $file['process_file']) {
         $file['process_file'] = $new_thumb;
+      }      
+      */
+      //We save only the first filename
+      if (! $firstfilename) {
+        $firstfilename = $new_thumb;
       }
-     
-      // store this thumb in our db
-      video_thumbnailer_save_thumb($file, $new_thumb);
-     
+    
       // advance our position
       $position = $position + $interval;
      
@@ -328,7 +342,10 @@ function video_thumbnailer_process($file
   }
   $file['status'] = MMA_FILE_STATUS_PROCESS_COMPLETE;
   watchdog('media_mover', t('Created video thumbnails for @node', array('@node' => $file['nid']), WATCHDOG_NOTICE, l($file['nid'], 'node/'. $file['nid'] .'/edit')));
-  return $file;
+  
+  //Return only the filename
+  //return $file;
+  return $firstfilename;
 }
 
 /**
@@ -368,20 +385,26 @@ function video_thumbnailer_create_thumb(
   }
 
   // get input file
-  $options[] = '-i \''. $file .'\'';
+  //$options[] = '-i \''. $file .'\'';
+  $options[] = "-i ". escapeshellarg($file);      
   // set frame time
   //$options[] = '-vframes 1 -ss \''. $interval  .'\' -an';
   $options[] = "-y -ss $interval -vframes 1";  
   // set codec
   //$options[] = '-vcodec mjpeg -f rawvideo -s \''. $size .'\'';
-  $options[] = '-f mjpeg -s \''. $size .'\'';
+  //$options[] = '-f mjpeg -s \''. $size .'\'';
+  $options[] = '-f mjpeg';
+  //Only add size if the user specified it
+  if ($size != '0')
+    $options[] = '-s \''. $size .'\'';  
   // add output file
-  $options[] = '\''. $output_file .'\'';
+  //$options[] = '\''. $output_file .'\'';
+  $options[] = escapeshellarg($output_file);    
 
   $command = implode(" ", $options);
 
   $output = ffmpeg_wrapper_run_command($command);
-
+  
   // check and see if any errors were reported
   // but we'll handle error checking here
   if (! ffmpeg_wrapper_error_check($output, $file, $command, true)) { return false; }
@@ -442,10 +465,10 @@ function video_thumbnailer_delete($item,
  * implementation of hook_form_alter
  */
 function video_thumbnailer_form_alter($form_id, &$form) {
-  //variable_set('vtm_content_types', array('upload_content' => true));
-  $enabled_types = variable_get('vtm_content_types', array());
-  if ($enabled_types[$form['#node']->type]) {
-
+  //Deleted, because vtm_content_types not saved anywhere, and the alter process never called
+  ////variable_set('vtm_content_types', array('upload_content' => true));
+  //$enabled_types = variable_get('vtm_content_types', array());
+  //if ($enabled_types[$form['#node']->type]) {  
     // check if there are any video thumbs for this node
     if ($form['#node']->media_mover) {
       if ($files = video_thumbnailer_get_nid_thumbs($form['#node']->nid)) {
@@ -478,8 +501,9 @@ function video_thumbnailer_form_alter($f
         );
       }
     }
-  }
+  //}
 }
+//END
 
 
 /* *************************************************** */
@@ -494,6 +518,7 @@ function video_thumbnailer_form_alter($f
 function video_thumbnailer_save_thumb($item, $thumb_path) {
   $id = db_next_id('video_thumbnailer');
   db_query('INSERT INTO {video_thumbnailer} (mmfid, vtid, nid, path) VALUES (%d, %d, %d, "%s")', $item['mmfid'], $id, $item['nid'], $thumb_path);
+  return $id;
 }
 
 /**
