Thumb folder limitation

Discuss of AVS script, custom modifications or anything related to this video script

Thumb folder limitation

Postby nuevolab » Sat Dec 25, 2010 3:59 pm

There is is a lot of complains on thumbs folder limitation when it reaches 32.000 thumb subdirectories.
It can be avoided by changing some linux settings, but strongly suggested is to change thumbs storage structure against any future complication.

Unfortunately changing thumbs storage structure is not so simple in AVS script. It requires many changes in AVS php functions and templates. Also very important is storage structure. It should be simple, easy to understand for webmaster, also easy to implement on templates.

Here's our solution that forces AVS system to create next an next subdirectory for each 1 thousand videos thumb dir. We thought of this solution, so it could allow for really minimum change in thumb image src path.

Before you try it you should consider some important things:

1. Are you enough PHP/Smarty experienced to make changes described below?
2. ALWAYS backup php or tpl file before you edit it.
3. ALL CHANGES YOU DO IS ON YOUR OWN RISK


Ok, let's start...

First thing to do is to create new structure for your thumb images.
Before making live new method for thumbs structure we strongly suggest not to remove or rename original "/media/videos/tmb" directory.
Instead we suggest to create new directory "tmb2" in "/media/videos/"
Next create subdirecties like "1","2","3" for each 1 thousand thumbs dirs.
Then copy each certain video thumbs directory to one of numeric directories we prepared.

Form 1 to 1000 - to thumbs directory "1"
From 1001 to 2000 - to thumbs directory "2"
From 2001 to 3000 - to thumbs directory "3"
and so on...

A script could be written to fasten copu operation, however for unexperienced people suggested is to do it manually, so it can take time...

Once all thumbs copied to new directories you can proceed with php and tpl files edition.

1. Create empty file "modifier.ceil.php"
===================================

Enter this code:
Code: Select all
<?php
function smarty_modifier_ceil($number)
{
    return ceil($number/1000);
}
?>

Save and upload to "include/smarty/libs/plugins" directory


2. File "include/function_video.php"
===================================
See the post concerning thumbs extraction function below.

3. Some siteadmin php files to change
=======================================

A -siteadmin/modules/videos/add.php

Line:
Code: Select all
$tmb_dir   = $config['BASE_DIR'].'/media/videos/tmb/'.$vid;
@mkdir($tmb_dir);

Change to:
Code: Select all
$subdir = $tmb_dir   = $config['BASE_DIR'].'/media/videos/tmb/'.ceil($vid/1000);
if(!file_exists($subdir.'/')) @mkdir($subdir);
$tmb_dir   = $subdir.'/'.$vid;
@mkdir($tmb_dir);


B. -siteadmin/modules/videos/embed.php


Line:
Code: Select all
$tmb_dir = $config['BASE_DIR'].'/media/videos/tmb/'.$vid;
@mkdir($tmb_dir);

Change:
Code: Select all
$subdir = $tmb_dir   = $config['BASE_DIR'].'/media/videos/tmb/'.ceil($vid/1000);
if(!file_exists($subdir.'/')) @mkdir($subdir);
$tmb_dir   = $subdir.'/'.$vid;

@mkdir($tmb_dir);

3. Edit multiple templates where video thumb may appear.

========================================================

Wherever thumb image "src" parameter appears do like in example from "videos.tpl"
The line is:
Code: Select all
<img src="{$relative}/media/videos/tmb/{$videos[i].VID}/{$videos[i].thumb}.jpg" ....... />

New line will be:
Code: Select all
<img src="{$relative}/media/videos/tmb/{$videos[i].VID|ceil}/{$videos[i].thumb}.jpg" ....... />


Can you see the change?
/{$videos[i]}/ is changed to /{$videos[i]|ceil}/
Really this is minimum change, can't be easier.

Other templates I found to edit:
-------------------------------------

- index.tpl
- video.tpl (1 place)
- user_videos.tpl (1 place)
- user_playlist.tpl
- user_favorite_videos.tpl
- search_videos.tpl

And some siteadmin templates I found to edit:
-----------------------------

- videos.tpl
- videos_feature.tpl
- videos_inappropriate.tpl
- videos_flagged.tpl

Just check (user search function) every place where image "src" appears along with thumb path.

Once you have all done, you can set new thumbs directories structure.

1. Rename original directory "/media/videos/tmb" to eg. "/media/videos/tmb_old"
2. Rename directory we created "/media/videos/tmb2" to "/media/videos/tmb"

Once you check that new structure for thumbs is working correctly, you can remove "/media/videos/tmb_old" directory, but do not do it too soon.

The solution here doesn't require changes for thumbs rotation. It should rotate fine.

FINAL NOTE
I wrote this post based on what I found in AVS code. The solution is as easy as it can be, idea is surely right, however I didn't have time to test it all live enough. We do not have any AVS based website, but have really long experience in programming, especially in video scripts lately. We did hundreds jobs for AVS and Clipshare users, so we really know what we do.
If you do changes to the script and find something not working, you can try to ask us if you provide as much details as possible. But do not expect that we can come to your server and setup everything for you.
All free help is what we post on forums. All further help is not free and is a matter of our programming hourly rates and agreement between user and us.

Good luck.
nuevolab
Site Admin
 
Posts: 99
Joined: Sun Sep 06, 2009 2:32 am

Re: Thumb folder limitation

Postby wazburn » Thu Dec 30, 2010 5:01 am

nice this is a good and big help, I will try this out. But I have some concern:

1. was it need to be a literally 1000 folder inside Folder 1? (a literal count of 1-1000)
2. I check my tmb folder and it starts the count at 11, missing 1-10. Should I put that folder 11-1011to folder 1, then 1012-2012 on folder 2 etc etc. What I mean with this is, am i right to count 1000 folder whatever the count folder is as long as i count 1000 to put in Folder 1,2,3,4,5 etc etc. im asking this because I saw a skip count in my tmb folder for example I have 11-1185 then 10000.
wazburn
 
Posts: 11
Joined: Thu Dec 30, 2010 4:45 am

Re: Thumb folder limitation

Postby nuevolab » Mon Jan 03, 2011 8:19 am

Not count, but number. Video number.

So to subfloder "1" upload thumbs for videos from 1 to 1000 VID number.
Eg. If your videos starts at 17 then there is 998 and next is 1003 :

In directory "1" you will have vids subfolders from video '17' to '998'
and in subfolder '2' vids subfolders from 1003....
nuevolab
Site Admin
 
Posts: 99
Joined: Sun Sep 06, 2009 2:32 am

Re: Thumb folder limitation

Postby wazburn » Tue Jan 04, 2011 8:02 am

nuevolab wrote:3. Edit multiple templates where video thumb may appear.[/b]
========================================================

Wherever thumb image "src" parameter appears do like in example from "videos.tpl"
The line is:
Code: Select all
<img src="{$relative}/media/videos/tmb/{$videos[i].VID}/{$videos[i].thumb}.jpg" ....... />

New line will be:
Code: Select all
<img src="{$relative}/media/videos/tmb/$videos[i].VID|ceil}/{$videos[i].thumb}.jpg" ....... />


Can you see the change?
/{$videos}/ is changed to /{$videos[i]|ceil}/
Really this is minimum change, can't be easier.




Thanks. That clears me on those folders. What I did.
I have structure below, because my thumb sub starts at 11 and some jump counts
11 and 1000 >> to folder 1 >> /media/videos/tmb2/1/
1001 to 1185 >> to folder 2
from 1185 it jumps to "10,000" missing 1186 to 9,999
10,000 >> to folder 10
10,001-11,000 >> to folder 11
11,001-11,858 >> to folder 12


from the above quote you mention:
:idea: /{$videos[i]}/ is changed to /{$videos[i]|ceil}/
Really this is minimum change, can't be easier.

should it be?

:idea: /{$videos[i].VID}/ is changed to /{$videos[i].VID|ceil}/


Also you mention in video function
$subdir = ceil($vide_id/1000);
:arrow: I thought it might be some typo error so I change $vide_id/ to $video_id/ , correct me if im wrong.
$subdir = ceil($video_id/1000);

and some typo, correct me if im wrong
<img src="{$relative}/media/videos/tmb/{$videos[i].VID}/{$videos[i].thumb}.jpg"
a '{' is missing before $videos[i].VID
<img src="{$relative}/media/videos/tmb/$videos[i].VID|ceil}/{$videos[i].thumb}.jpg"

then changing src thumb paths in TPL's
{$relative}/media/videos/tmb/{$viewed_videos[i].VID}/{$viewed_videos[i].thumb}.jpg
to
{$relative}/media/videos/tmb/{$viewed_videos[i].VID|ceil}/{$viewed_videos[i].thumb}.jpg


checked tmb dir and files then uploaded, on refresh the only part that came out is the header the body and footer did not load, video thumbs also do not show in siteadmin. I wonder if where could be the problem, I doubled checked everything and still body do not show up. :?: I did all suggestion above and also tried typo correction still did not load the body.

but

when I change the modifier ceil it loads the page but no thumbs
from
function smarty_modifier_[i]ceal($number)
to this:
function smarty_modifier_ceil($number)
the thumbpath when right clicked is this:
http://www.mydomain.com/media/videos/tmb/10/1.jpg

if im not mistaken that link image should look like
http://www.mydomain.com/media/videos/tmb/1/10/1.jpg

could it be the video function or the modifier ceil?
trying:
:?: $subdir = ceil($number/$video_id/1000);
:?: img src="{$relative}/media/videos/tmb/{$viewed_videos[i].VID|ceil}/{$viewed_videos[i].VID}/{$viewed_videos[i].thumb}.jpg


looks like something is missing.
wazburn
 
Posts: 11
Joined: Thu Dec 30, 2010 4:45 am

Re: Thumb folder limitation

Postby nuevolab » Wed Jan 05, 2011 11:45 pm

Apart of possible typos I made in some lines, there was also missleading name in smarty "ceil" modifier.
Possible it could be an issue for you.
Now all code quoted above was corrected.

Unfortunately I do not have any site based on AVS, just only one for tests and most of what I write is just my ideas, not necessary tested to the end. Only when I'm ordered to do custom programming of course I take care about correct and valid code, test things enough.
nuevolab
Site Admin
 
Posts: 99
Joined: Sun Sep 06, 2009 2:32 am

Re: Thumb folder limitation

Postby wazburn » Sat Jan 08, 2011 8:03 am

Your GUIDE IS GREAT!

My site is now capable of exceeding 32k.

:?: But there's a problem when you upload a video, it does not generate the thumb? the video is there it can be played fine. Also in siteadmin it has no thumb.
wazburn
 
Posts: 11
Joined: Thu Dec 30, 2010 4:45 am

Re: Thumb folder limitation

Postby nuevolab » Sat Jan 08, 2011 9:14 am

Concerning only thumbs generation this is function in file "include/function.video.php"
The function is "extract_video_thumbs" and it should be rebuilt a lot...
Here is my attempt how it should be:
Code: Select all
function extract_video_thumbs($video_path, $video_id)
{
    global $config;
   
    $duration   = get_video_duration($video_path, $video_id);
    if ( $duration > 180 ) {
        $ss     = 60;
        $step   = 5;
    } elseif ( $duration > 120 ) {
        $ss     = 15;
        $step   = 5;
    } elseif ( $duration > 60 ) {
        $ss     = 10;
        $step   = 2;
    } else {
        $ss     = 1;
        $step   = 1;
    }
   
    $i = 0;
    mkdir($config['TMP_DIR']. '/thumbs/' .$video_id);
    $subdir=$config['TMB_DIR']. '/thumbs/' .ceil($video_id/1000);
    if(!file_exists($subdir."/")) mkdir ($subdir);
    mkdir($subdir. '/' .$video_id);
    while($i <= 20 ) {
      $width  = $config['img_max_width'];
      $height = $config['img_max_height'];
      if ($i == 0) {
         $width  = 320;
         $height = 240;
      }
   
        if ( $config['thumbs_tool'] == 'ffmpeg' ) {
            $cmd    = $config['ffmpeg']. ' -i ' .$video_path. ' -f image2 -ss ' .$ss. ' -s ' .$width. 'x' .$height. ' -vframes 2 -y ' .$config['TMP_DIR']. '/thumbs/' .$video_id. '/%08d.jpg';
        } else {
            $cmd    = $config['mplayer']. ' ' .$video_path. ' -ss ' .$ss. ' -nosound -vop scale='.$width.':'.$height.' -vo jpeg:outdir=' .$config['TMP_DIR']. '/thumbs/' .$video_id. ' -frames 2';
        }
       
       // log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', $cmd);
        exec($cmd. ' 2>&1', $output);
        //log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', implode("\n", $output));
       
        if ( file_exists($config['TMP_DIR']. '/thumbs/' .$video_id. '/00000002.jpg') ) {
            $src    = $config['TMP_DIR']. '/thumbs/' .$video_id. '/00000002.jpg';
        } else {
            $src    = $config['TMP_DIR']. '/thumbs/' .$video_id. '/00000001.jpg';
        }
        $dst    = ( $i == 0 ) ? $subdir. '/' .$video_id. '/default.jpg' : $subdir. '/' .$video_id. '/' .$i. '.jpg';
        //log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', $src. "\n" .$dst);
        copy($src, $dst);
       
        $ss = $ss+$step;
        if ( $ss > $duration ) {
            $ss = $ss-$step;
        }
       
        ++$i;
    }
    @unlink($config['TMP_DIR']. '/thumbs/' .$video_id);
}

Suggested is not to log thumbs creation as it can provide to another folders limit problem.
Unfortunately I can't test it enough due to limited time.

Look also at first post and changed code for files:
siteadmin/modules/videos/add.php
siteadmin/modules/videos/embed.php
nuevolab
Site Admin
 
Posts: 99
Joined: Sun Sep 06, 2009 2:32 am

Re: Thumb folder limitation

Postby wazburn » Sun Jan 09, 2011 9:38 am

your guide is still awesome and very helpful even though you do not have time to test it.

Unfortunately the new post on "include/function.video.php" above makes the http://www.mydomain.com/siteadmin/videos.php a blank page. Other pages of siteadmin works just fine.
http://www.mydomain.com/upload/video if a member tries to upload a video gets a blank page also.

could it be we miss something is missing or wrong in the code.

Here is my function.video.php

Code: Select all
<?php
defined('_VALID') or die('Restricted Access!');

function get_video_duration($video_path, $video_id)
{
    global $config;
    $cmd = $config['mplayer']. ' -quiet -nolirc -vo null -ao null -frames 0 -identify "' .$video_path. '"';
    log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', $cmd);
    exec($cmd, $output);
    log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', implode("\n", $output));
    while ( list($k,$v) = each($output) ) {
        if ( $length = strstr($v, 'ID_LENGTH=') ) {
            break;
        }
    }
   
    if ( isset($length) ) {
        $lx = explode('=', $length);
       
        return $lx['1'];
    }
   
    return '0';
}

function extract_video_thumbs($video_path, $video_id)
{
    global $config;
   
      
    $duration   = get_video_duration($video_path, $video_id);
    if ( $duration > 180 ) {
        $ss     = 60;
        $step   = 5;
    } elseif ( $duration > 120 ) {
        $ss     = 15;
        $step   = 5;
    } elseif ( $duration > 60 ) {
        $ss     = 10;
        $step   = 2;
    } else {
        $ss     = 1;
        $step   = 1;
    }
   
    $i = 0;
    mkdir($config['TMP_DIR']. '/thumbs/' .$video_id);
    $subdir=$config['TMB_DIR']. '/thumbs/' .ceil($video_id/1000);
   if (!file_exists($subdir."/")) mkdir $subdir;
   mkdir($subdir. '/' .$video_id);
    while($i <= 20 ) {
      $width  = $config['img_max_width'];
      $height = $config['img_max_height'];
      if ($i == 0) {
         $width  = 320;
         $height = 240;
      }
   
        if ( $config['thumbs_tool'] == 'ffmpeg' ) {
            $cmd    = $config['ffmpeg']. ' -i ' .$video_path. ' -f image2 -ss ' .$ss. ' -s ' .$width. 'x' .$height. ' -vframes 2 -y ' .$config['TMP_DIR']. '/thumbs/' .$video_id. '/%08d.jpg';
        } else {
            $cmd    = $config['mplayer']. ' ' .$video_path. ' -ss ' .$ss. ' -nosound -vop scale='.$width.':'.$height.' -vo jpeg:outdir=' .$config['TMP_DIR']. '/thumbs/' .$video_id. ' -frames 2';
        }
       
        //log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', $cmd);
        exec($cmd. ' 2>&1', $output);
        //log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', implode("\n", $output));
       
        if ( file_exists($config['TMP_DIR']. '/thumbs/' .$video_id. '/00000002.jpg') ) {
            $src    = $config['TMP_DIR']. '/thumbs/' .$video_id. '/00000002.jpg';
        } else {
            $src    = $config['TMP_DIR']. '/thumbs/' .$video_id. '/00000001.jpg';
        }
      
       
   $dst    = ( $i == 0 ) ? $config['TMB_DIR']. '/' .$subdir. "/" .$video_id. '/default.jpg' : $config['TMB_DIR']. '/' .$subdir. "/" .$video_id. '/' .$i. '.jpg';
        //log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', $src. "\n" .$dst);
        copy($src, $dst);
       
        $ss = $ss+$step;
        if ( $ss > $duration ) {
            $ss = $ss-$step;
        }
       
        ++$i;
    }
    @unlink($config['TMP_DIR']. '/thumbs/' .$video_id);
}

function log_conversion($file_path, $text)
{   
    $file_dir = dirname($file_path);
    if( !file_exists($file_dir) or !is_dir($file_dir) or !is_writable($file_dir) ) {
        return false;
    }
                   
    $write_mode = 'w';
    if( file_exists($file_path) && is_file($file_path) && is_writable($file_path) ) {
        $write_mode = 'a';
    }
                               
    if( !$handle = fopen($file_path, $write_mode) ) {
        return false;
    }
                                               
    if( fwrite($handle, $text. "\n") == FALSE ) {
        return false;
    }
                                                           
    @fclose($handle);
}                                                       
?>


:arrow: and I use this correction for the thumb to call the image on the right dir in TPL files.
img src="{$relative}/media/videos/tmb/{$viewed_videos[i].VID|ceil}/{$viewed_videos[i].VID}/{$viewed_videos[i].thumb}
wazburn
 
Posts: 11
Joined: Thu Dec 30, 2010 4:45 am

Re: Thumb folder limitation

Postby nuevolab » Sun Jan 09, 2011 3:20 pm

As I mentioned - I do not run any adult site based on AVS. All I write is like "offline".
But if you really want to play with such script, you need to learn basic things. And basic thing is "DEBUG" mode.
You can switch the script into debug mode, changing "false" to "true" in file "include/debug,php".
Then you will be able to track most of simple php errors like some typos, etc.
Same was with function I posted above, it's easy to find typo error line if in debug mode.
There was a code:
mkdir $subdir;
Should be:
mkdir($subdir);

It's corrected in function above.
nuevolab
Site Admin
 
Posts: 99
Joined: Sun Sep 06, 2009 2:32 am

Re: Thumb folder limitation

Postby wazburn » Sun Jan 09, 2011 7:59 pm

Thank you so much for your support,

Gracias!!!! I got it working now thanks for your awesome guide I did still edit some files but still its RESOLVED!!!

Will run another 32k or more and test the result.

THank you!
Last edited by wazburn on Mon Jan 10, 2011 8:06 pm, edited 3 times in total.
wazburn
 
Posts: 11
Joined: Thu Dec 30, 2010 4:45 am

Next

Return to AVS

Who is online

Users browsing this forum: No registered users and 0 guests