Author Topic: Using ffmpeg to generate uploaded video thumbnails  (Read 115759 times)

0 Members and 1 Guest are viewing this topic.

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #15 on: April 16, 2006, 01:57:22 PM »
V@no, Everything is working great now, that was my only glitch...

thanks for all your invaluable help...

Kind Regards,
WeZ

Offline adizlaja

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #16 on: May 07, 2006, 01:27:10 AM »
How well does this work? Can I test your 4images gallery?

thanks

Offline l1some

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #17 on: June 04, 2006, 01:20:16 AM »
Got this mod working with 4images 1.7.1-inter/with phpnuke 7.4 WORKS GREAT!! :wink:

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #18 on: June 06, 2006, 09:42:43 PM »
how can i use this on a linux server?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #19 on: June 07, 2006, 04:50:39 AM »
The same way, just change the path to ffmpeg executible
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline street2k

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #20 on: September 23, 2006, 04:16:28 AM »
So how do we use ffmpeg to generate an uploaded vid thumbnail.

What folder/files & code and so on?

Offline alekseyn1

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • My Project
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #21 on: December 21, 2006, 12:13:11 PM »
Hello everyone!

I have been following the discussion regarding this issue and trying to modify the code myself.

Here is my result:

I am running of Gallery 1.7 (under runcms 1.5) on WinXP on the intranet.

first of all I had to increase the script timeout in php.ini to more than 30 seconds and memory allocation to more than 8 MB because I had timeout errors when adding 30 and more large images through the control panel (maybe this is irrelevant to the rest of the message, but paybe it will be helpful for some people)

I have modified the image_utils.php in an effort to make the system create the thumbnail from my videos (mostly avi, and wmv - have not tried it with mov yet):

image_utils.php
Code: [Select]
function create_thumbnail($src, $dest, $quality, $dimension, $resize_type) {
  global $convert_options;

  if (file_exists($dest)) {
    @unlink($dest);
  }
  $image_info = (defined("IN_CP")) ? getimagesize($src) : @getimagesize($src);
  if (!$image_info) {
    return false;
  }
  $width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);
  $resize_handle = "resize_image_".$convert_options['convert_tool'];
  if ($resize_handle($src, $dest, $quality, $width_height['width'], $width_height['height'], $image_info)) {
    @chmod($dest, CHMOD_FILES);
    return true;
  }
//****added from here****
  if (in_array(get_file_extension($new_name), array("mpg", "mpeg", "avi", "wmv")) && Generate_VideoThumb($src, $dest.".jpg")) {
    $new_thumb_name = $new_name.".jpg";
}
//****added to here****
  else {
    return false;
  }
}

//****added from here****
function Generate_VideoThumb($src, $dest) {
  global $convert_options;
  $command = "C:\\mplayer\\mplayer.exe \"".$src."\" -ss 00:00:05 -nosound -vo jpeg:smooth=75 -vop scale=120:80 -frames 1 > imagegenoutput.txt";
  system($command);
  //unlink("00000001.jpg");
  unlink("imagegenoutput.txt");
  rename("00000001.jpg",$dest);
  return (file_exists($dest)) ? 1 : 0;
}
//****added to here****

and this is in my member.php
Code: [Select]
// Upload thumb file
      $new_thumb_name = "";
      if (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$uploaderror) {
        $new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $upload_cat, basename($new_name));
        if (!$new_thumb_name) {
          $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['thumb_upload_error'].": ".$new_thumb_name."</b><br />".$site_upload->get_upload_errors();
          @unlink(MEDIA_TEMP_PATH."/".$new_name);
          $uploaderror = 1;
        }
      }
      elseif (check_remote_thumb($remote_thumb_file)) {
        $new_thumb_name = $remote_thumb_file;
      }
      elseif ($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file'.$fileext]['tmp_name']) && $HTTP_POST_FILES['media_file'.$fileext]['tmp_name'] != "none" && !$uploaderror) {
        if ($direct_upload) {
          $src = MEDIA_PATH."/".$cat_id."/".$new_name;
          $dest = THUMB_PATH."/".$cat_id."/".$new_name;
        }
        else {
          $src = MEDIA_TEMP_PATH."/".$new_name;
          $dest = THUMB_TEMP_PATH."/".$new_name;
        }
        $do_create = 0;
        if ($image_info = @getimagesize($src)) {
          if ($image_info[2] == 1 || $image_info[2] == 2 || $image_info[2] == 3) {
            $do_create = 1;
          }
        }
        require_once(ROOT_PATH.'includes/image_utils.php');
        $convert_options = init_convert_options();
        if ($do_create) {
          if (!$convert_options['convert_error']) {
            $dimension = (intval($config['auto_thumbnail_dimension'])) ? intval($config['auto_thumbnail_dimension']) : 100;
            $resize_type = (intval($config['auto_thumbnail_resize_type'])) ? intval($config['auto_thumbnail_resize_type']) : 1;
            $quality = (intval($config['auto_thumbnail_quality']) && intval($config['auto_thumbnail_quality']) <= 100) ? intval($config['auto_thumbnail_quality']) : 100;

            if (create_thumbnail($src, $dest, $quality, $dimension, $resize_type)) {
              $new_thumb_name = $new_name;
            }
            }
          }
        else {
  if (in_array(get_file_extension($new_name), array("mpg", "mpeg", "avi", "wmv")) && Generate_VideoThumb($src, $dest.".jpg")) {
  $new_thumb_name = $new_name.".jpg";
}

        }
    }

And when I add a video from the "upload" button everything works just fine!!!

Autothumbnailer MOD 2.2.1 works great with pictures also.

Now here is the problem/request Autothumbnailer MOD 2.2.1 does not see that in 4images_images table the field image_thumb_file field is emply for everything that is not a picture (jpg). (all other autothumbnailers did not see other file types also)

How do I make the MOD see that there is no thumbnail for videos?

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #22 on: January 10, 2007, 12:46:39 AM »
Hi VAno & the rest who do such a good job...

just FYI - in the last scipt i posted you''ll see i hard coded the number of seconds the thumbnail was generated from... i set this value to 5 seconds and pretty soon realised how many funny little clips i have that just that fall under that number - this caused the thumbnail generation to fail... putting the value shorter to like 2 or 3, left most of the vids still starting and the screenshot was black...

anyway, long story short, this new code will find the length of the file and stream to the middle... you can change the value in the ceil command to suit your needs...

Code: [Select]
/**************************************************************************
 * WeZ - Get Vid Info Code                                                *
 *************************************************************************/
function movie_get_length_in_seconds($src)
{
$cmd = "C:\\mplayer\\mplayer.exe -identify -vo null -ao null -frames 1 \"".$src."\" 2>&1 | grep ID_LENGTH";
$output = exec($cmd);
list(,$length) = explode("=", $output);
$length = ceil($length/2);
return $length;
}


/**************************************************************************
 * WeZ - Get Thumb Code                                                *
 *************************************************************************/
function Generate_VideoThumb($src, $dest) {
  global $convert_options;
  $length = movie_get_length_in_seconds($src);
  $command = "C:\\mplayer\\mplayer.exe \"".$src."\" -ss ".$length." -nosound -vo jpeg:smooth=75 -vop scale=120:80 -frames 1 > imagegenoutput.txt";
  system($command);
  unlink("imagegenoutput.txt");
  rename("00000001.jpg",$dest);
  movie_get_length_in_seconds($src);
  return (file_exists($dest)) ? 1 : 0;
}

remember , i'm not a programmer so dont blast my code!! :-)

hope some1 finds useful...

Ciao
WeZ

Offline alekseyn1

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • My Project
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #23 on: January 15, 2007, 12:57:06 PM »

And when I add a video from the "upload" button everything works just fine!!!

Autothumbnailer MOD 2.2.1 works great with pictures also.

Now here is the problem/request Autothumbnailer MOD 2.2.1 does not see that in 4images_images table the field image_thumb_file field is emply for everything that is not a picture (jpg). (all other autothumbnailers did not see other file types also)

How do I make the MOD see that there is no thumbnail for videos?

let me paraphrase my question:

How do I make this code work from thumbnailer.php (version 2.2.1) in CP? This function does not see that mov,wmv,avi files have no thumbs in Database.... Please help. I have a ton of videos with no preview that I want to add thumbs to...

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #24 on: January 17, 2007, 08:39:14 AM »

And when I add a video from the "upload" button everything works just fine!!!

Autothumbnailer MOD 2.2.1 works great with pictures also.

Now here is the problem/request Autothumbnailer MOD 2.2.1 does not see that in 4images_images table the field image_thumb_file field is emply for everything that is not a picture (jpg). (all other autothumbnailers did not see other file types also)

How do I make the MOD see that there is no thumbnail for videos?

let me paraphrase my question:

How do I make this code work from thumbnailer.php (version 2.2.1) in CP? This function does not see that mov,wmv,avi files have no thumbs in Database.... Please help. I have a ton of videos with no preview that I want to add thumbs to...

Perhaps post this in a thread for "Autothumbnailer MOD 2.2.1"?

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #25 on: February 05, 2007, 01:08:43 AM »
It would be nice that this mod was well organized in order to all people can easily install it :)

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #26 on: February 07, 2007, 03:04:51 AM »
Ok... I'm lost in this MOD!

Offline alekseyn1

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • My Project
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #27 on: February 07, 2007, 03:38:12 AM »
It would be nice that this mod was well organized in order to all people can easily install it :)


Guys, this mod is still not working propertly. If you still want to try it then follow the changes listed in post 21 of this thread. BUT BACKUP YOUR ORIGINALS so you can always roll back the changes.  Good luck!

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #28 on: February 07, 2007, 03:41:16 AM »
V@no, Everything is working great now, that was my only glitch...

thanks for all your invaluable help...

Kind Regards,
WeZ

For wez its working well (at least he says that)

but... in your mod what doesn't work?

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #29 on: February 07, 2007, 04:02:33 AM »
I got this error in your MOD
"
Parse error: syntax error, unexpected '}' in /home/songokou/public_html/aceleras/member.php on line 680
"

Also where I put mplayer.exe ? Could be wmplayer.exe changed to mplayer.exe?