Automatic video thumbnail creation (Requires ffmpeg) - Page 3 Automatic video thumbnail creation (Requires ffmpeg) - Page 3
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Automatic video thumbnail creation (Requires ffmpeg)

Started by Abbas Ali, November 24, 2006, 11:56:30 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

worenklein

I think I got it!


Index: util.php
===================================================================
--- util.php    (revision 4455)
+++ util.php    (working copy)
@@ -246,6 +246,22 @@
                 $thumb = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['thumb_pfx'] . $row['filename'];

                 if ($updatetype == 0 || $updatetype == 2){
+      if (is_movie($image)) {
+       preg_match("/(.+)\.(.*?)\Z/", $row['filename'], $matches);
+       $thumb = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['thumb_pfx'] . $matches[1].".jpg";
+       $videoThumb = create_movie_thumb($image);
+       if ($videoThumb) {
+         if (resize_image($videoThumb, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])) {
+           echo "$thumb {$lang_util_php['updated_succesfully']} !<br />";
+           my_flush();
+         } else {
+           echo "{$lang_util_php['error_create']} : $thumb<br />";
+           my_flush();
+         }
+       }
+       @unlink($videoThumb);
+       $imagesize = getimagesize($thumb);
+      } else {
                         if (resize_image($image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])){
                                 echo "$thumb {$lang_util_php['updated_succesfully']} !<br />";
                                 my_flush();
@@ -254,6 +270,7 @@
                                 my_flush();
                         }
                 }
+    }

                 if ($updatetype == 1 || $updatetype == 2){
David C Worenklein

SolidSnake2003

I tried this out, but when I tried to add videos using the batch add, it wouldnt add the videos, and gave me an error of not being able to load ffmpeg (125)

Abbas Ali

That means either ffmpeg is not properly installed or you gave the incorrect path to its executable.
Chief Geek at Ranium Systems

dildo

Quote from: lifter on September 06, 2007, 11:21:04 PM
When I try to implement this mod, video uploads seize to work.

When I upload the file it says:

Successful Uploads
1 uploads were successful.

Please click 'Continue' to add the files to albums.

But after continuing and selecting an album and pressing continue again it says

"The previous file could not be placed.

You have successfully placed all the files."

Quote@lifter : PM me the admin un/pass, url of your gallery along with a link to this topic. If that doesn't help then i might ask for ftp access too (if you are happy to provide that).

hi,

How did you solve his problem ?  I got the same...

Abbas Ali

@dildo: Can't remember. I don't even remember if he ever sent me the login info :)
Chief Geek at Ranium Systems

dildo

ok it's all right I am going to manage in another way thank you sir

Ghost rider

Hi Ali,
I'm writting you, if you can help  me to solve the trouble about how to create automatic video thumbnail. I tried to intregated the script that you posted in past about this matter is no working. I did managed to install ffmpeg. The script below is uploading the video files in directory but it's no creating thumbnail in directory folder(thumb).Thank in advance

<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="500000" /> 
          <table width="400" cellpadding="3" >
            <tr>
              <td colspan="3"> </td>
            </tr>
            <tr>
              <td width="10" rowspan="2"> </td>
              <td width="120"><strong>Choose a file to upload:</strong></td>
              <td width="242"><input type="file" name="uploaded_file" /></td>
            </tr>
            <tr>
              <td> </td>
              <td> </td>
            </tr>
            <tr>
              <td> </td>
              <td> </td>
              <td><input type="submit" name="sendForm" value="Upload File" />
                <br /></td>
            </tr>
            <tr>
              <td colspan="3"> </td>
            </tr>
          </table>
</form>
<?php 
  
  
// C:\wamp\www\scriptDir\uploads\ ;
 
  
$idir "C:/wamp/www/Testvideo/videos/";   // Path To Images Directory 
  
$tdir "C:/wamp/www/Testvideo/ThumbVideos/";   // Path To Thumbnails Directory 
  
$twidth "200";   // Maximum Width For Thumbnail Images 
  
$theight "150";   // Maximum Height For Thumbnail Images 

  
error_reporting(E_ALL E_NOTICE); // Show all major errors. 

  // Check to see if the button has been pressed 
  
if (!empty($_REQUEST['sendForm'])) 
  { 
    
// Assign the name to a variable 
    
$name $_FILES['uploaded_file']['name']; 
    
// Assign the tmp_name to a variable 
    
$tmp_name $_FILES['uploaded_file']['tmp_name']; 
    
// Assign the error to a variable 
    
$error $_FILES['uploaded_file']['error']; 
    
// Assign the size to a variable 
    
$size $_FILES['uploaded_file']['size'];
    
// No trailing slash 
    
$uploadFilesTo 'videos'
    
// Create safe filename 
    
$name ereg_replace('[^A-Za-z0-9.]''-'$name); 
    
// Disallowed file extensions 
    //what files you don't want upoad... leave this alone and you should be fine but you could add more 
    
$naughtyFileExtension = array("php""php3""asp""inc""txt""wma","js""exe""jsp""map""obj"" """"html""mp3""mpu""wav""cur""ani");    // Returns an array that includes the extension 
   
    //Allowable file Mime Types. Add more mime types if you want 
    
$FILE_MIMES = array('video/mpg','video/avi','video/mpeg','video/wmv'); 
    
//Allowable file ext. names. you may add more extension names. 
    
$FILE_EXTS = array('.avi','.mpg','.mpeg','.asf','.wmv','.3gpp');
    
$file_ext strtolower(substr($name,strrpos($name,".")));  
    
// to check the extensio
    
if (!in_array($file_type$FILE_MIMES) && !in_array($file_ext,$FILE_EXTS) ) 
    
$message "Sorry, $file_name($file_type) is not allowed to be uploaded.";  
 
    
$fileInfo pathinfo($name); 
    
// Check extension 
    
if (!in_array($fileInfo['extension'], $naughtyFileExtension)) 
    { 
      
// Get filename 
      
$name getNonExistingFilename($uploadFilesTo$name); 
      
// Upload the file 
      
if (move_uploaded_file($tmp_name$uploadFilesTo.'/'.$name))  
      { 
          
// Show success message 
          
echo '<center><p>Your Video File has uploaded successfully<br />'.$uploadFilesTo.'/'.$name.'</p></center>'
      } 
      else 
      { 
          
// Show failure message 
          
echo '<center><p>File failed to upload to /'.$name.'</p></center>'
      } 
    } 
    else 
    { 
        
// Bad File type 
        
echo '<center><p>The file uses an extension we don\'t allow.</p></center>'
    } 
  } 
  
  
// Functions do not need to be inline with the rest of the code 
  
function getNonExistingFilename($uploadFilesTo$name
  { 
      if (!
file_exists($uploadFilesTo '/' $name)) 
          return 
$name
      
      return 
getNonExistingFilename($uploadFilesTorand(100200) . '_' $name); 
  } 
  
  
  
/**
 * Function to create video thumbnail using ffmpeg
   http://forum.coppermine-gallery.net/index.php?topic=38774.0
 */
function create_movie_thumb($src_file)
{
    global 
$CONFIG$ERROR;

    
$CONFIG['ffmpeg_path'] = 'C:/wamp/bin/'// Change the path according to your server.

    
$src_file $src_file;
    
$dest_file $CONFIG['fullpath']."edit/".md5(uniqid(time()))."%d.jpg";

    if (
preg_match("#[A-Z]:|\\\\#Ai"__FILE__)) {
        
// get the basedir, remove '/include'
        
$cur_dir substr(dirname(__FILE__), 0, -8);
        
$src_file '"' $cur_dir '\\' strtr($src_file'/''\\') . '"';
        
$ff_dest_file '"' $cur_dir '\\' strtr($dest_file'/''\\') . '"';
    } else {
        
$src_file escapeshellarg($src_file);
        
$ff_dest_file escapeshellarg($dest_file);
    }

    
$output = array();

    if (
eregi("win",$_ENV['OS'])) {
        
// Command to create video thumb
        
$cmd "\"".str_replace("\\","/"$CONFIG['ffmpeg_path'])."ffmpeg\" -i ".str_replace("\\","/" ,$src_file )." -an -ss 00:00:05 -r 1 -vframes 1 -y ".str_replace("\\","/" ,$ff_dest_file);
        
exec ("\"$cmd\""$output$retval);
    } else {
        
// Command to create video thumb
        
$cmd "{$CONFIG['ffmpeg_path']}ffmpeg -i $src_file -an -ss 00:00:05 -r 1 -vframes 1 -y $ff_dest_file";
        
exec ($cmd$output$retval);
    }


    if (
$retval) {
        
$ERROR "Error executing FFmpeg - Return value: $retval";
        if (
$CONFIG['debug_mode']) {
            
// Re-execute the command with the backtick operator in order to get all outputs
            // will not work if safe mode is enabled
            
$output = `$cmd 2>&1`;
            
$ERROR .= "<br /><br /><div align=\"left\">Cmd line : <br /><span style=\"font-size:120%\">" nl2br(htmlspecialchars($cmd)) . "</span></div>";
            
$ERROR .= "<br /><br /><div align=\"left\">The ffmpeg program said:<br /><span style=\"font-size:120%\">";
            
$ERROR .= nl2br(htmlspecialchars($output));
            
$ERROR .= "</span></div>";
        }
        @
unlink($dest_file);
        return 
false;
    }

    
$return str_replace("%d""1"$dest_file);
    @
chmod($returnoctdec($CONFIG['default_file_mode'])); //silence the output in case chmod is disabled
    
return $return;
}


?>
 

Abbas Ali

Are you using the thumbnail creation functions outsite of coppermine?
Chief Geek at Ranium Systems

Ghost rider

hi Ali,
thank for your reply. No I'm not using a function outside the coppermine and may be I didn't use all the functions illustrating in coppermine site. Please if you can check my script and give some direction. Thanks for your time.

Ghost rider

Abba Ali,
Ignorant my last message. I think I get confusion using your  function because I tried to mix up with some of my script. I want to get this right.OK

1-I don't think I got complete the script or function.
2-I tried to run the function below.

<?php
/**
 * Function to create video thumbnail using ffmpeg
  from http://forum.coppermine-gallery.net/index.php?topic=38774.0
 */
function create_movie_thumb($src_file)
{
    global 
$CONFIG$ERROR;

    
$CONFIG['ffmpeg_path'] = '/usr/local/bin/'// Change the path according to your server.

    
$src_file $src_file;
    
$dest_file $CONFIG['fullpath']."edit/".md5(uniqid(time()))."%d.jpg";

    if (
preg_match("#[A-Z]:|\\\\#Ai"__FILE__)) {
        
// get the basedir, remove '/include'
        
$cur_dir substr(dirname(__FILE__), 0, -8);
        
$src_file '"' $cur_dir '\\' strtr($src_file'/''\\') . '"';
        
$ff_dest_file '"' $cur_dir '\\' strtr($dest_file'/''\\') . '"';
    } else {
        
$src_file escapeshellarg($src_file);
        
$ff_dest_file escapeshellarg($dest_file);
    }

    
$output = array();

    if (
eregi("win",$_ENV['OS'])) {
        
// Command to create video thumb
        
$cmd "\"".str_replace("\\","/"$CONFIG['ffmpeg_path'])."ffmpeg\" -i ".str_replace("\\","/" ,$src_file )." -an -ss 00:00:05 -r 1 -vframes 1 -y ".str_replace("\\","/" ,$ff_dest_file);
        
exec ("\"$cmd\""$output$retval);
    } else {
        
// Command to create video thumb
        
$cmd "{$CONFIG['ffmpeg_path']}ffmpeg -i $src_file -an -ss 00:00:05 -r 1 -vframes 1 -y $ff_dest_file";
        
exec ($cmd$output$retval);
    }


    if (
$retval) {
        
$ERROR "Error executing FFmpeg - Return value: $retval";
        if (
$CONFIG['debug_mode']) {
            
// Re-execute the command with the backtick operator in order to get all outputs
            // will not work if safe mode is enabled
            
$output = `$cmd 2>&1`;
            
$ERROR .= "<br /><br /><div align=\"left\">Cmd line : <br /><span style=\"font-size:120%\">" nl2br(htmlspecialchars($cmd)) . "</span></div>";
            
$ERROR .= "<br /><br /><div align=\"left\">The ffmpeg program said:<br /><span style=\"font-size:120%\">";
            
$ERROR .= nl2br(htmlspecialchars($output));
            
$ERROR .= "</span></div>";
        }
        @
unlink($dest_file);
        return 
false;
    }

    
$return str_replace("%d""1"$dest_file);
    @
chmod($returnoctdec($CONFIG['default_file_mode'])); //silence the output in case chmod is disabled
    
return $return;
}

// Add a picture to an album
function add_picture($aid$filepath$filename$position 0$title ''$caption ''$keywords ''$user1 ''$user2 ''$user3 ''$user4 ''$category 0$raw_ip ''$hdr_ip ''$iwidth 0$iheight 0)

 } elseif (
is_movie($image)) {
      
preg_match("/(.+)\.(.*?)\Z/"$filename$matches);
      
$thumb $CONFIG['fullpath'] . $filepath $CONFIG['thumb_pfx'] . $matches[1].".jpg";
      
$videoThumb create_movie_thumb($image);
      if (
$videoThumb) {
        if (!
resize_image($videoThumb$thumb$CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])) {
          return 
false;
        }
        @
unlink($videoThumb);
        
$imagesize getimagesize($thumb);
      } else {
        return 
false;
      }

 } else {
        
$imagesize[0] = $iwidth;
        
$imagesize[1] = $iheight;
    }
?>
 


I'm getting this error:
Parse error: syntax error, unexpected '}', expecting '{' in C:\wamp\www\Testvideo\videoFunction.php on line 61

4-Please if you can you send me complete script and function or illustrate how can I create video thumbnail! I'm using WAMP server. Thank you so much.

Abbas Ali

The code you posted above is not correct and few lines (from original code) are missing from it and hence it is giving parse error. I am sorry but providing support for creating a custom script, not belonging to coppermine, is out of the scope of this board.
Chief Geek at Ranium Systems

Ghost rider

Thank for your reply. If you could at least give some directions to help me solve the problem. Thank in advance

Joachim Müller

We can not do that, it's beyond the scope of support on this forum. Please do not clutter announcement threads with your individual issues.

Ghost rider

Ok thanks. I'm a new user in forum. Could you please help me to find where the tab to process new topics on this forum? I can't find it! Thanks in advance

Joachim Müller

I told you to stop cluttering this announcement thread, yet you still clutter it! You're now banned from posting for three days because you haven't dpone as suggested and because you're lazy. You can of course not start a new thread here on this very sub-board, as this sub-board contains actual mod announcements and not support requests. You'd have to go to a sub-board where you actually can start new threads related to support: visit the corresponding sub-board of the support branch. You can only do so after your three day ban has expired.