forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Watermarking & image manipulation => Topic started by: Abbas Ali on November 24, 2006, 11:56:30 am

Title: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on November 24, 2006, 11:56:30 am
This mod requires ffmpeg (http://ffmpeg.mplayerhq.hu) pre-installed and working on your server. Please DO NOT ask for support on installing or configuring ffmpeg. If you don't have ffmpeg or can't install ffmpeg on your server then this mod is not meant for you.

What will this mod do?
This mod will create thumbnail from the uploaded video file automatically on the fly. Thumbnails will be placed in the directory where the videos are uploaded/batch added. Though ffmpeg supports many video formats but i am unsure about wmv. File formats which i tested were avi, mpg, asf, flv.

Edit include/picmgmt.inc.php

Add

Code: [Select]
/**
 * Function to create video thumbnail using ffmpeg
 */
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($return, octdec($CONFIG['default_file_mode'])); //silence the output in case chmod is disabled
    return $return;
}

just before

Code: [Select]
// 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)

In above code change $CONFIG['ffmpeg_path'] value to where ffmpeg is installed on your server.

Add

Code: [Select]
    } 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;
      }

just before

Code: [Select]
    } else {
        $imagesize[0] = $iwidth;
        $imagesize[1] = $iheight;
    }

That's it, only one file to be modified.


Few Notes
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: jape on January 09, 2007, 01:13:05 pm
Why not working .flv videos???
Thumnail name is problems...

I trying upload video.FLV

but...

Thumb location is:
/gallery/images/thumb_FLV.jpg


Not Found

The requested URL /galleria/images/thumb_FLV.jpg was not found on this server.

Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: jape on January 09, 2007, 01:26:28 pm
Its working  ;D
But not why...  ;D ;D
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: jape on January 09, 2007, 02:26:40 pm
ahaa....  :D
This don´t working thumbnails: video.FLV
This working: video.flv
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on January 10, 2007, 06:57:07 am
Not sure why that's happening but ffmpeg might not be able to create thumbs with capitalized extension. Better always use lower case extensions.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: adrianbj on January 10, 2007, 07:10:21 am
Hey Abbas,

Fantastic Hack - thanks.

I did notice one thing though. If you want the dimensions of the movie to be properly collected, you need to change

Code: [Select]
    } 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;
      }

to:

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

Note that I have removed your getimagesize line and replaced it further up in the code and changed the variable from $thumb to $videoThumb

The way you had it, it always grabbed the dimensions of the thumbnail, rather than the actual fullsize video.

I also commented out these lines in upload.php:

Code: [Select]
        //Add width and height boxes to the form.
        //$form_array[] = array($lang_admin_php['th_wd'],'movie_wd', 0, 4, 1); //no longer needed since dimensions of movies are grabbed automatically
        //$form_array[] = array($lang_admin_php['th_ht'],'movie_ht', 0, 4, 1); //no longer needed since dimensions of movies are grabbed automatically

because it is no longer necessary for the user to enter the movie dimensions manually.

Thanks again,
Adrian
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: adrianbj on January 10, 2007, 07:11:46 am
I noticed the capitalized extension problem too!
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on January 10, 2007, 08:23:57 am
Thanks adrianbj for enhancing the mod.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: adrianbj on January 11, 2007, 08:31:27 am
No problem,

Here is another addition to ensure that the thumbnail is deleted along with movie if a delete takes place.

In the file delete.php

Add this:

Code: [Select]
//Added by AJ to delete thumb and preview versions for movies
$file_normal = $CONFIG['normal_pfx'] . $file;
$file_thumb = $CONFIG['thumb_pfx'] . $file;

if(is_movie($file)){
$path_parts = pathinfo($file);
$file_ext = '.' . $path_parts['extension'];
$file_normal = str_replace($file_ext, ".jpg", $file_normal);
$file_thumb = str_replace($file_ext, ".jpg", $file_thumb);
}
//

directly after these lines:

Code: [Select]
    $aid = $pic['aid'];
    $dir = $CONFIG['fullpath'] . $pic['filepath'];
    $file = $pic['filename'];


Change this:

Code: [Select]
$files = array($dir . $file, $dir . $CONFIG['normal_pfx'] . $file, $dir . $CONFIG['thumb_pfx'] . $file);

to this:

Code: [Select]
$files = array($dir . $file, $dir . $file_normal, $dir . $file_thumb); // Modified by AJ - changed links to normal and thumb version to grab corrected links for movies and special images etc
That's it!
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: adrianbj on January 16, 2007, 11:01:15 pm
Here's another addition so you get to see the preview thumbnail during the upload process - really useful if you've uploaded several files and you're not sure which is which when you're entering the info about the movie.

In upload.php, add

Code: [Select]
    // Added by AJ for handling preview thumb for movie images
   } elseif(is_movie($file_set[1])) {
   
   
       $CONFIG['ffmpeg_path'] = '/usr/bin/'; // Change the path according to your server.

        // Create preview image file name.

        do {

            // Create a random seed by taking the first 8 characters of an MD5 hash of a concatenation of the current UNIX epoch time and the current server process ID.
            $seed = substr(md5(uniqid("")), 0, 8);

            // Assemble the file path.
$extension="jpg"; //change temp thumbsized preview file to a JPG
            $path_to_preview = './'.$CONFIG['fullpath'].'edit/preview_' . $seed . '%d.' . $extension;

        } while (file_exists($path_to_preview));

        // Create secure preview path.
        $s_preview_path = 'preview_' . $seed . '.' . $extension;

    $output = array();

        // The file is an image, we must resize it for a preview image.
        $cmd = "{$CONFIG['ffmpeg_path']}ffmpeg -i $path_to_image -an -ss 00:00:05 -r 1 -vframes 1 -s sqcif -y $path_to_preview";
        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($path_to_preview);
        //return false;
    }
    // Set mode of uploaded picture
$path_to_preview = str_replace("%d", "1", $path_to_preview);
    @chmod($path_to_preview, octdec($CONFIG['default_file_mode'])); //silence the output in case chmod is disabled
    // We check that the image is valid
    $imginfo = getimagesize($path_to_preview);
    if ($imginfo == null) {
        $ERROR = $lang_errors['resize_failed'];
        @unlink($path_to_preview);
        //return false;
    } else {
        //return true;
    }

just before:

Code: [Select]
} else {

        // The file is not an image, so we will use the non-image thumbs
        // for preview images.

        // We create the path to the preview image.
        $path_to_preview = "images/thumb_{$extension}.jpg";

    }


The -s sqcif does the resizing. Unfortunately I can't work out how to resize proportionally using ffmpeg, so if you have a bunch of videos that are not in the standard aspect ratio, you might want to have ffmpeg create the screenshot at fullsize and then use an imagemagick resize command on it and do -resize 150x which will ensure the aspect ratio is not changed.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: oscar_rocha on February 19, 2007, 12:25:51 pm
You can also overlap a "play this movie" image (jpeg,gif or png) to the videothumb (like in youtube) just adding in picmgmt.inc.php:

After:
Code: [Select]
$return = str_replace("%d", "1", $dest_file);
Add:

Code: [Select]
   
/**************************************/
  $background = imagecreatefromjpeg($return);
  $insert = imagecreatefromgif($image_path);
  imagecolortransparent($insert,imagecolorat($insert,0,0));
  $insert_x = imagesx($insert);
  $insert_y = imagesy($insert);
  imagecopymerge($background,$insert,45,35,0,0,$insert_x,$insert_y,100);
  imagejpeg($background, $return, 100);
    /***************************************/

Where $image_path is the path to the image you want to overlap.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: gldickens3 on August 04, 2007, 12:49:00 am
This is a great thread!

I downloaded ffmpg and got everything listed in this thread working perfectly except for this:

Quote from: oscar_rocha
You can also overlap a "play this movie" image (jpeg,gif or png) to the videothumb (like in youtube) just adding in picmgmt.inc.php:

After:
Code:

$return = str_replace("%d", "1", $dest_file);


Add:

Code:

   
/**************************************/
  $background = imagecreatefromjpeg($return);
  $insert = imagecreatefromgif($image_path);
  imagecolortransparent($insert,imagecolorat($insert,0,0));
  $insert_x = imagesx($insert);
  $insert_y = imagesy($insert);
  imagecopymerge($background,$insert,45,35,0,0,$insert_x,$insert_y,100);
  imagejpeg($background, $return, 100);
    /***************************************/


Where $image_path is the path to the image you want to overlap.

When I put the code into picmgmt.inc.php then I get the following error message when I try to "Batch add files":

Fatal error: Call to undefined function imagecreatefromjpeg() in /home/gajets/public_html/gallery/include/picmgmt.inc.php on line 78

How do I fix this problem so I don't get this undefined function error?  Is there other code that I need to be including?

Thanks,

Gordon Dickens
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Nibbler on August 04, 2007, 06:26:35 am
You need GD with JPEG support enabled. Check your phpinfo page.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: gldickens3 on August 04, 2007, 02:51:34 pm
Hi Nibbler,

Duh....

You hit the nail right on the head!  I had GD on my system but it wasn't included in my Apache compile so I recompiled Apache including GD which fixed the problem.  Thanks!

Now, the thumbnails are being generated, however, the overlay "play button" is not being included. So, my question is about:

Quote from: oscar_rocha
Where $image_path is the path to the image you want to overlap.

Should the file name path be relative to the root directory of the website or relative to the root directory of the coppermine installation?  That is, I put my overlay image in my themes directory.  So, which of the following paths would be correct for the code line: $insert = imagecreatefromgif($image_path);?

$image_path = gallery/themes/gordon_grey/playbutton.gif
or;
$image_path = themes/gordon_grey/playbutton.gif

Thanks,

Gordon
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on August 04, 2007, 05:26:24 pm
$image_path = gallery/themes/gordon_grey/playbutton.gif
or;
$image_path = themes/gordon_grey/playbutton.gif

Play safe and put the absolute path i.e. something like /home/username/public_html/gallery/themes/.... (if you are on linux server).
Btw: relative path from gallery folder should work
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: gldickens3 on August 04, 2007, 11:28:33 pm
Ali and Nibbler,

I've got it working now. I've just got to figure out how to properly center the overlay on my thumbnails.

Thanks for all your help.

Gordon
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: 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."
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on September 07, 2007, 06:47:09 am
First check whether normal video uploading (without the mod) is working or not. If that is working then it means ffmpeg is not working on your server.

Also turn on the debug mode to see the errors (if any).
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: lifter on September 07, 2007, 06:56:40 am
Video uploading works without the mod - it may be that ffmpegshow isnt installed - going to have to check with my host
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on September 07, 2007, 07:30:32 am
it may be that ffmpegshow isnt installed - going to have to check with my host

Thats the first thing to check for as my first post describes.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: lifter on September 07, 2007, 05:37:06 pm
Thats the first thing to check for as my first post describes.

Appears I have it installed - and this mod still doesn't work ;(

Host confirmed that it's installed and I can see that it is because when I use adrianbj's modification to see a thumb preview during the upload process, I do end up seeing the thumb.  When I try to continue and place the movie into an album - it won't go - the movie does however appear via FTP in an uploaded folder
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on September 08, 2007, 02:18:08 pm
Also turn on the debug mode to see the errors (if any).
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: lifter on September 11, 2007, 07:46:44 pm
Code: [Select]
/include/picmgmt.inc.php

    * Notice line 50: Undefined index: OS
    * Warning line 72: unlink(albums/edit/af41288e99ed440c5e145f8529725de1%d.jpg) [function.unlink]: No such file or directory

This is the error that I get - it uploads the file, because it's still on my FTP, but it appears it's not placing it because it can't find the thumb (which doesn't get created..)
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: lifter on September 11, 2007, 07:56:29 pm
extremely weird... using the modification alexbj posted to see the thumbnail preview while you are uploading, I see the thumbnail.... so ffmpeg is installed and working, however when I press 'continue' to place the file into an album, it still says "The file could not be placed" and still gives this error:

Code: [Select]
/include/picmgmt.inc.php

    * Notice line 50: Undefined index: OS
    * Warning line 72: unlink(albums/edit/e0bde2401ccb0498f3e3b4dc66e266ab%d.jpg) [function.unlink]: No such file or directory
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: lifter on September 11, 2007, 08:01:17 pm
Not sure if this helps, but the thumbnail preview comes up as: /albums/edit/preview_5df573cc1.jpg
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on September 25, 2007, 08:52:14 am
@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).
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: sokheng on November 19, 2007, 06:12:11 pm
This mod work perfectly Great! Two Thumbs Up!! If you are able to install ffmpeg, everything will work just fine.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: zendiz on January 14, 2008, 06:19:38 am
Hi, seems a great hack...but... >:(

I have followed all settings (running cpg4.14 on my server with ffmpeg, and installed all hack lines from this thread)
I manually upload 1 file -> 1 uploads were successful.
Shows thumbnail !! and asks me what album to put file in. (so far so good) -> continue

The previous file was placed successfully. You have successfully placed all the files. -> continue

Then this sucks -> Showing album with this standard uggly Mpeg icon from coppermine  ???

What am I doing wrong.



Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: zendiz on January 14, 2008, 06:27:59 am
To add to my post, I just uploaded a movie file with debug mode on, it showed preview of thumbnail as before, no errors during upload.
Still that ridiculous standard coppermine icon when i check the album.  gmmm
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on January 14, 2008, 06:56:02 am
Can't say much without looking at your gallery. Provide a test user account (with upload privileges) and the link to your gallery.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: JPNARF on January 20, 2008, 02:01:09 am
Hi Abbas Ali !!
This is my first post ! Hello to all !!

I have a problem, i copied exactly that you post... but i have this error:

Parse error: parse error, expecting `']'' in C:\Web Server\foto\Coppermine\include\picmgmt.inc.php on line 36

The line 36 is:
    $dest_file = $CONFIG['fullpath']."edit/".md5(uniqid(time()))."%d.jpg";

Any suggestion ?

Regards,
Juan.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Nibbler on January 20, 2008, 02:39:36 am
Zip up and attach the file to your next post.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: JPNARF on January 20, 2008, 02:43:31 am
Hi Nibbler !

Here the picmgmt.inc.php file

Thanks !
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Nibbler on January 20, 2008, 03:04:55 am
You changed the wrong side of the code

Code: [Select]
$CONFIG['ffmpeg_path'] = '/usr/local/bin/'; // Change the path according to your server.
Change the path and leave the variable name alone.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: JPNARF on January 20, 2008, 03:13:44 am
Sorry Nibble... terrible error  :o

now i put:
$CONFIG['ffmpeg_path'] = "C:\ffmpeg\"; // Change the path according to your server.

but other error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\Web Server\foto\Coppermine\include\picmgmt.inc.php on line 36

I Have Windows OS
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Nibbler on January 20, 2008, 03:19:56 am
I Have Windows OS

I know.

Use

Code: [Select]
$CONFIG['ffmpeg_path'] = 'C:\ffmpeg\\'; // Change the path according to your server.

Also reverse where you changed the wrong part in the rest of the code. You only need to set your path once, where instructed to do so.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: JPNARF on January 20, 2008, 03:34:09 am
Yes ! Work !!
Thanks Nibbler.

One more  ::)

I try to add all enhancing, now i am in : overlap a "play this movie" image (jpeg,gif or png) to the videothumb (like in youtube) by oscar_rocha

After:
Code: [Select]
$return = str_replace("%d", "1", $dest_file);
I add the following code:
Code: [Select]
  $image_path = "C:\Web Server\foto\Coppermine\themes\hardwired\images\Play.jpg"
  $background = imagecreatefromjpeg($return);
  $insert = imagecreatefromgif($image_path);
  imagecolortransparent($insert,imagecolorat($insert,0,0));
  $insert_x = imagesx($insert);
  $insert_y = imagesy($insert);
  imagecopymerge($background,$insert,45,35,0,0,$insert_x,$insert_y,100);
  imagejpeg($background, $return, 100);

But i received the message:
"Parse error: parse error in C:\Web Server\foto\Coppermine\include\picmgmt.inc.php on line 80"

Line 80 is:
Code: [Select]
$background = imagecreatefromjpeg($return);
I check phpinfo() and is OK:
gd
GD Support    enabled
GD Version    bundled (2.0.28 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
GIF Read Support    enabled
GIF Create Support    enabled
JPG Support    enabled
PNG Support    enabled
WBMP Support    enabled
XBM Support    enabled
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: JPNARF on January 20, 2008, 03:36:24 am
SORRY AGAIN... is the time 1 AM here  :'(

i forgot
Code: [Select]
$image_path = "C:\Web Server\foto\Coppermine\themes\hardwired\images\Play.jpg"[b];[/b]
 :-[
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: JPNARF on January 30, 2008, 04:51:12 am
Hi All,
I moved my Coppermine to another OS Windows 2003, i configure all again... import data base, etc.

But i have the problem now, when i try to upload videos using this mod (before in Windows 2000 Work !!) display the PB icon.
Using original file picmgmt.inc.php work, but with the mod not  :-\

Here my debug:

Quote
USER:
------------------
Array
(
    [ID] => a298ee8ceb581dab4ac09e99b4f82a3c
    [am] => 1
    [uid] => 1
    [liv] => Array
        (
           
  • => 1049
  • [1] => 1045
                [2] => 1048
                [3] => 1052
                [4] => 1040
            )

       
[lap] => 2
    [lang] => english
)

==========================
USER DATA:
------------------
Array
(
    [user_id] => 1
    [user_name] => foto
    [groups] => Array
        (
           
  • => 1

        )

    [disk_max] => 0
    [disk_min] => 0
    [can_rate_pictures] => 1
    [can_send_ecards] => 1
    [ufc_max] => 2
    [ufc_min] => 2
    [custom_user_upload] => 0
    [num_file_upload] => 0
    [num_URI_upload] => 1
    [can_post_comments] => 1
    [can_upload_pictures] => 1
    [can_create_albums] => 1
    [has_admin_access] => 1
    [pub_upl_need_approval] => 0
    [priv_upl_need_approval] => 0
    [group_name] => Administrators
    [upload_form_config] => 2
    [group_quota] => 0
    [can_see_all_albums] => 1
    [group_id] => 1
)

==========================
Queries:
------------------
Array
(
   
  • => SELECT extension, mime, content, player FROM copp_filetypes; (0.037s)
  • [1] => select * from copp_plugins order by priority asc; (0.002s)
        [2] => delete from `fotos`.copp_sessions where time<1201664782 and remember=0; (0.002s)
        [3] => delete from `fotos`.copp_sessions where time<1200458782; (0.001s)
        [4] => select user_id from `fotos`.copp_sessions where session_id=md5("5500db23b9625a3b2426a6a216a1883228db823b029eabc861ae2fac83e293ee"); (0.001s)
        [5] => select user_id as id, user_password as password from `fotos`.copp_users where user_id=1 (0.004s)
        [6] => SELECT u.user_id AS id, u.user_name AS username, u.user_password AS password, u.user_group+100 AS group_id FROM `fotos`.copp_users AS u INNER JOIN `fotos`.copp_usergroups AS g ON u.user_group=g.group_id WHERE u.user_id='1' (0.006s)
        [7] => SELECT user_group_list FROM `fotos`.copp_users AS u WHERE user_id='1' and user_group_list <> ''; (0.013s)
        [8] => SELECT MAX(group_quota) as disk_max, MIN(group_quota) as disk_min, MAX(can_rate_pictures) as can_rate_pictures, MAX(can_send_ecards) as can_send_ecards, MAX(upload_form_config) as ufc_max, MIN(upload_form_config) as ufc_min, MAX(custom_user_upload) as custom_user_upload, MAX(num_file_upload) as num_file_upload, MAX(num_URI_upload) as num_URI_upload, MAX(can_post_comments) as can_post_comments, MAX(can_upload_pictures) as can_upload_pictures, MAX(can_create_albums) as can_create_albums, MAX(has_admin_access) as has_admin_access, MIN(pub_upl_need_approval) as pub_upl_need_approval, MIN( priv_upl_need_approval) as  priv_upl_need_approval FROM copp_usergroups WHERE group_id in (1) (0.001s)
        [9] => SELECT group_name FROM  copp_usergroups WHERE group_id= 1 (0.002s)
        [10] => update `fotos`.copp_sessions set time='1201668382' where session_id=md5('5500db23b9625a3b2426a6a216a1883228db823b029eabc861ae2fac83e293ee'); (0.002s)
        [11] => SELECT user_favpics FROM copp_favpics WHERE user_id = 1 (0.001s)
        [12] => DELETE FROM copp_banned WHERE expiry < '2008-01-30 01:46:22' (0.002s)
        [13] => SELECT * FROM copp_banned WHERE (ip_addr='10.10.10.1' OR ip_addr='10.10.10.1' OR user_id=1) AND brute_force=0 (0.177s)
        [14] => SELECT aid, title FROM copp_albums WHERE 1 (0.005s)
        [15] => SELECT COUNT(*) FROM copp_pictures WHERE approved = 'NO' (0.001s)
    )

    ==========================
    GET :
    ------------------
    Array
    (
       
[insert] => 1
)

==========================
POST :
------------------
Array
(
    [d0000] => 22
    [pics] => Array
        (
           
  • => i0000
  • [1] => i0001
            )

       
[album_lb_id_i0000] => d0000
    [picfile_i0000] => dXNlcnBpY3MvYS9RdWludGFKSihFbmUtMDgpLmZsdg==
    [album_lb_id_i0001] => d0000
    [picfile_i0001] => dXNlcnBpY3MvYS9TYWtlRHVtYm8ubXBn
    [insert] => Insert selected files
)

==========================
VERSION INFO :
------------------
PHP version: 5.2.5 - OK
------------------
mySQL version: 5.0.45-community-nt
------------------
Coppermine version: 1.4.15(stable)
==========================
Module: GD
------------------
GD Version: bundled (2.0.34 compatible)
FreeType Support: 1
FreeType Linkage: with freetype
T1Lib Support: 1
GIF Read Support: 1
GIF Create Support: 1
JPG Support: 1
PNG Support: 1
WBMP Support: 1
XPM Support:
XBM Support: 1
JIS-mapped Japanese Font Support:

==========================
Module: mysql
------------------
MySQL Supportenabled
Active Persistent Links 0
Active Links 1
Client API version 5.0.45
==========================
Module: zlib
------------------
ZLib Support enabled
Stream Wrapper support compress.zlib://
Stream Filter support zlib.inflate, zlib.deflate
Compiled Version 1.2.3
Linked Version 1.2.3
==========================
Server restrictions (safe mode)?
------------------
Directive | Local Value | Master Value
safe_mode | Off | Off
safe_mode_exec_dir | no value | no value
safe_mode_gid | Off | Off
safe_mode_include_dir | no value | no value
safe_mode_exec_dir | no value | no value
sql.safe_mode | Off | Off
disable_functions | no value | no value
file_uploads | On | On
include_path | .;C:\php5\pear | .;C:\php5\pear
open_basedir | no value | no value
==========================
email
------------------
Directive | Local Value | Master Value
sendmail_from | no value | no value
sendmail_path | no value | no value
SMTP | localhost | localhost
smtp_port | 25 | 25
==========================
Size and Time
------------------
Directive | Local Value | Master Value
max_execution_time | 30 | 30
max_input_time | 60 | 60
upload_max_filesize | 2M | 2M
post_max_size | 8M | 8M
==========================
Page generated in 0.398 seconds - 16 queries in 0.257 seconds - Album set : ; Meta set: ;

Thanks !
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: worenklein on May 20, 2008, 05:43:40 am
What do I need to add to util.php (in the update_thumbs() function)?

My guess is that this is the offending line:

Code: [Select]
$thumb = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['thumb_pfx'] . $row['filename'];

Sorry, I'm not a PHP guy yet (give me a few days -- if I can figure out TCL, I can figure out anything  :D)
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: worenklein on May 20, 2008, 06:33:52 am
I think I got it!

Code: [Select]
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){
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: SolidSnake2003 on June 05, 2008, 02:09:21 am
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)
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on June 05, 2008, 06:41:32 am
That means either ffmpeg is not properly installed or you gave the incorrect path to its executable.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: dildo on April 29, 2009, 09:02:19 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...
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on April 30, 2009, 04:41:41 am
@dildo: Can't remember. I don't even remember if he ever sent me the login info :)
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: dildo on April 30, 2009, 10:46:44 pm
ok it's all right I am going to manage in another way thank you sir
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Ghost rider on August 27, 2009, 03:47:23 pm
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

Code: [Select]
<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;
}


?>
 
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on August 28, 2009, 07:02:31 am
Are you using the thumbnail creation functions outsite of coppermine?
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Ghost rider on August 28, 2009, 12:14:26 pm
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.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Ghost rider on August 28, 2009, 01:43:50 pm
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.

Code: [Select]
<?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:
Code: [Select]
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.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Abbas Ali on August 28, 2009, 02:29:44 pm
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.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Ghost rider on August 28, 2009, 05:44:15 pm
Thank for your reply. If you could at least give some directions to help me solve the problem. Thank in advance
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Joachim Müller on August 30, 2009, 01:34:17 pm
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.
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Ghost rider on September 02, 2009, 04:58:58 pm
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
Title: Re: Automatic video thumbnail creation (Requires ffmpeg)
Post by: Joachim Müller on September 14, 2009, 02:37:16 pm
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.