Author Topic: Using ffmpeg to generate uploaded video thumbnails  (Read 115938 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 #30 on: February 21, 2007, 11:12:25 PM »
Hi son_gokou & alekseyn1,

i always promise myself that when a forum like this one helps me, which it has, i will do my best to return the favour to others in it. Sorta paying it forward...

i have been on honeymoon and away from my pc (at gunpoint i tell you  :lol:) ... just kidding...

Anyway, alekseyn1... i think i might be able to help you considering i also have that plug-in installed.
In thumbnailer.php, try finding the code
Code: [Select]
if ($is_exists || (($image_info[2] == 1 ||
and ensure the ENTIRE STRING looks like this:
Code: [Select]
if ($is_exists || (($image_info[2] == 1 || $image_info[2] == 2 || $image_info[2] == 3 || $image_info[2] == 15 || (in_array(get_file_extension($media_file), array("asf", "wma", "wmv", "mpg", "mpeg", "avi", "mov", "asx", "mp4", "flv")))) && $create)) {

give that a go... p.s. you can modify the extensions in that list to suit your needs...

Now, son_gokou... remember i am not a php  programmer, so my troubleshooting techniques are by no means correct. whenever i get the
Quote
unexpected '}'
error, i look on the line it complains about and sure enough i see a
Quote
}
on that line. the error often is resolved by adding another
Quote
}
next to it, or removing the one that is there. have you tried these?

Cheers






Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #31 on: February 24, 2007, 02:45:28 AM »
First of all enjoy your honeymoon ;)

Then... when you have time tell me:

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

This is vital I think.

Offline Freak Show

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #32 on: February 24, 2007, 11:18:36 AM »
Wow... this sounds crazy hard. I'm a little overwhelmed with all of the updates & corrections.

 Can we get a step by step for n00bs in one post?

Offline alekseyn1

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • My Project
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #33 on: February 25, 2007, 08:55:25 AM »
Hi son_gokou & alekseyn1,

Anyway, alekseyn1... i think i might be able to help you considering i also have that plug-in installed.

Thanks Wez! It helps a lot! At least this code now hels the thumbnailer.php to see that the thumb is missing... I will have to dig more in my code... mplayer.exe is not working properly for me...

Thanks anyways!

Offline alekseyn1

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • My Project
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #34 on: February 25, 2007, 09:07:52 AM »
Wow... this sounds crazy hard. I'm a little overwhelmed with all of the updates & corrections.

 Can we get a step by step for n00bs in one post?

OK guys... let's try again to put all code modifications in one place:

You should have mplayer.exe installed in "C:/mplayer/mplayer.exe" . You can download this application from here: http://www.mplayerhq.hu/design7/dload.html

Step 1.
In image_utils.php find and modify as follows:

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****
/**************************************************************************
 * 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;
}
//****added to here****

Step2:
in member.php modify as follows:

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 the final advise: If you want to try it then BACKUP YOUR ORIGINALS so you can always roll back the changes.  Hope I helped some of you guys! Good luck!

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #35 on: February 25, 2007, 06:44:49 PM »
I did what you told but... no thumbnail was created...

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #36 on: February 26, 2007, 12:59:36 PM »
I did what you told but... no thumbnail was created...

Hi son_gokou,

do you get any PHP errors on your site when you add a video?

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #37 on: February 26, 2007, 01:00:58 PM »
Hi son_gokou & alekseyn1,

Anyway, alekseyn1... i think i might be able to help you considering i also have that plug-in installed.

Thanks Wez! It helps a lot! At least this code now hels the thumbnailer.php to see that the thumb is missing... I will have to dig more in my code... mplayer.exe is not working properly for me...

Thanks anyways!

Thanks alekseyn1,

Are you up and running, ok?

Cheers

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #38 on: February 26, 2007, 03:04:02 PM »
No php error... just no thumbail created...

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #39 on: February 27, 2007, 07:07:52 PM »
Hi son_gokou,

ok, the first thing you need to do, is get it working in a command window. open a command window and browse to the mplayer directory. place a copy of the video file you want to test with in the directory. run the thumbnail command directly from there and see if you can generate a thumbnail from there?

Cheers

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #40 on: February 28, 2007, 02:57:58 AM »
I put the directory mplayer on c:\mplayer (it has 22 mb right?).
I put amigo.avi on c:\mplayer .

I run cmd on execute and put the command C:\\mplayer\\mplayer.exe \"".$src."\" -ss ".$length." -nosound -vo jpeg:smooth=75 -vop scale=120:80 -frames 1 > imagegenoutput.txt and the following error appears.


Ok, I replace \"".$src."\" into c:\player\amigo.avi to test and appears this:

Offline WeZ

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #41 on: March 01, 2007, 02:42:23 PM »
Hi son_goku

first, nacigate to the directory --> c:\Mplayer

then don't put two \\'s in your command

also, your timescale value is incorrect...

run this command:
Code: [Select]
mplayer c:\mplayer\amigo.avi -ss 00:00:03 -nosound -vo jpeg:smooth=75 -vop scale=120:80 -frames 1 > imagegenoutput.txt

does something get generated now?

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #42 on: March 01, 2007, 02:58:15 PM »
It continues to appear this

arial.ttf ???

imagegenoutput.txt is created

Offline gustav

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #43 on: March 02, 2007, 10:20:39 AM »
can anyone modify the commands so, that the code works with ffmpeg? unfortunately mplayer is no option for me.....

Offline son_gokou

  • Full Member
  • ***
  • Posts: 199
    • View Profile
Re: Using ffmpeg to generate uploaded video thumbnails
« Reply #44 on: March 21, 2007, 02:04:40 AM »
WeZ  doesn´t want to share with us  :twisted: