rendered paste body<?phperror_reporting( E_ALL | E_STRICT );putenv( "HOME=/home/cyleriggs" );putenv( "PATH=/home/cyleriggs/bin:/bin:/usr/bin/:/usr/local/bin/" );putenv( "LD_LIBRARY_PATH=/home/cyleriggs/lib" );$cols = 100;$chdir_target = "/home/cyleriggs/riggsfamilyweb.net/www/html/";if( !chdir($chdir_target) ) { die( "ERROR: Could not change to directory {$chdir_target}" );}$movieFiles = rglob("gallery","*.{avi,mov,mpg,AVI,MOV,MPG}", GLOB_BRACE );foreach( $movieFiles as $movieFile ) { print( str_pad("",80,"=") . "\n" ); $pathinfo = pathinfo( $movieFile ); $thumbDir = $chdir_target . $pathinfo['dirname'] . '/thumbs/'; $flvFile = $thumbDir . $pathinfo['basename'] . ".flv"; print( "PROCESSING FILE \"" . $movieFile . "\"\n" ); if( !file_exists($thumbDir) ) { if( !mkdir($thumbDir) ) { die( "ERROR making '$thumbDir'\n" ); } else { chmod( $thumbDir, 0777 ); } } //Create a preview jpeg makePreviewPic( $movieFile, $thumbDir . $pathinfo['basename'] . ".small.jpg", "150x112" ); makePreviewPic( $movieFile, $thumbDir . $pathinfo['basename'] . ".200.jpg", "200x150" ); makePreviewPic( $movieFile, $thumbDir . $pathinfo['basename'] . ".medium.jpg", "640x480" ); //Create preview vid makePreviewVid( $movieFile, $thumbDir . $pathinfo['basename'] . ".small.flv", "150x112" ); makePreviewVid( $movieFile, $thumbDir . $pathinfo['basename'] . ".200.flv", "200x150" ); makePreviewVid( $movieFile, $thumbDir . $pathinfo['basename'] . ".medium.flv", "640x480" );}/************************ UTILITY FUNCTIONS *************************//** * Recursive version of glob * * @return array containing all pattern-matched files. * * @param string $sDir Directory to start with. * @param string $sPattern Pattern to glob for. * @param int $nFlags Flags sent to glob. */function rglob($sDir, $sPattern, $nFlags = NULL) { $aFiles = glob("$sDir/$sPattern", $nFlags); foreach (glob("$sDir/*", GLOB_ONLYDIR) as $sSubDir) { $aSubFiles = rglob($sSubDir, $sPattern, $nFlags); $aFiles = array_merge($aFiles, $aSubFiles); } return $aFiles;}function makePreviewPic( $inputFile, $file, $resolution ) { $tmpFile = "/tmp/vidconv_pic_" . sha1($file) . "_" . mt_rand() . ".jpg"; if( !file_exists($file) ) { //Run ffmpeg on the video to convert it $retCode = null; $inputFile = escapeshellarg( $inputFile ); $outputFile = escapeshellarg( $tmpFile ); $resolution = escapeshellarg( $resolution ); $shellCmd = "ffmpeg -y -t 0.001 -i {$inputFile} -s {$resolution} -f mjpeg {$outputFile}"; print( "EXEC: $shellCmd\n" ); $retVal = system( $shellCmd, $retCode ); if( $retVal === false || $retCode != 0 ) { die( "ERROR: Could not create preview file: " . $file . "\n" ); return; } $oldFile = escapeshellarg($tmpFile); $newFile = escapeshellarg($file); $shellCmd = "mv {$oldFile} {$newFile}"; $retVal = system( $shellCmd, $retCode ); if( $retVal === false || $retCode != 0 ) { die( "ERROR: Could not move file" ); } else { chmod( $file, 0666 ); } }}function makePreviewVid( $movieFile, $file, $resolution ) { $tmpFile = "/tmp/vidconv_vid_" . sha1($file) . "_" . mt_rand() . ".flv"; if( !file_exists($file) ) { //Run ffmpeg on the video to convert it $retCode = null; $inputFile = escapeshellarg( $movieFile ); $outputFile = escapeshellarg( $tmpFile ); $resolution = escapeshellarg( $resolution ); $vBitrate = escapeshellarg( '600k' ); $aBitrate = escapeshellarg( '64' ); $aRate = escapeshellarg( '22050' ); $aChannels = escapeshellarg( '1' ); $vFrameRate = escapeshellarg( '24' ); $shellCmd = "ffmpeg -y -i {$inputFile} -b {$vBitrate} -s {$resolution} -acodec mp3 -ar {$aRate} -ab {$aBitrate} -ac {$aChannels} -r {$vFrameRate} {$outputFile}"; print( "EXEC: $shellCmd\n" ); $retVal = system( $shellCmd, $retCode ); if( $retVal === false || $retCode != 0 ) { die( "ERROR: Could not convert video file: " . $inputFile . "\n" ); return; } $oldFile = escapeshellarg($tmpFile); $newFile = escapeshellarg($file); $shellCmd = "mv {$oldFile} {$newFile}"; $retVal = system( $shellCmd, $retCode ); if( $retVal === false || $retCode != 0 ) { die( "ERROR: Could not move file" ); } else { chmod( $file, 0666 ); } }}?>