Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
I bought clip bucket but I want to strip it down? Incoding with ffmpeg
Old 07-06-2008, 09:56 PM I bought clip bucket but I want to strip it down? Incoding with ffmpeg
goheadtry's Avatar
Webmaster Talker

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
Okay I want to use this class from a script I bought, but I do NOT want to use the entire script, I want to upload with forms convert using this class write the info to an existing mysql database.


PHP Code:
<?php
/**
 **************************************************************************************************
 Class : FFMpeg
 Don Not Edit This Class , It May cause your script not to run properly
 This source file is subject to the ClipBucket End-User License Agreement, available online at:
 http://www.clip-bucket.com/eula.html
 By using this software, you acknowledge having read this Agreement and agree to be bound thereby.
 **************************************************************************************************
 Copyright (c) 2007 Clip-Bucket.com. All rights reserved.
 **************************************************************************************************
 **/
 
define('ENCODING_LOGGING','yes');
class 
ffmpeg 
{
            
            
//Special Function Used TO get duration
            
function ChangeTime($duration){
                if(
$duration 3600 ){
                
$time date("H:i:s",$duration);
                }else{
                
$time "00:";
                
$time .= date("i:s",$duration);
                }
                return 
$time;
            }
            
                
            
//THIS FUNCTION IS USED TO GENERATE THUMBS
            
            
function AssignGeneratedThumbs($flv,$duration)
            {
            
$filename_minus_ext substr($flv0strrpos($flv'.'));
            
$thumbnail_output_dir BASEDIR.'/files/thumbs';
            
$ffmpeg         FFMPEG_BINARY;
            
$flv_file        BASEDIR.'/files/videos/'.$flv;
            
            if(
$duration 14 ){
                
$duration $duration 5;
                
//Setting oF Thumbs Duration
                
$division $duration 3;
                
$count=1;
                for(
$id=3;$id<=$duration;$id++){
                
$id     $id +$division-1;
                
$time     $this->ChangeTime($id);
                
$command "$ffmpeg -i $flv_file -an -ss $time -an -r 1 -s 120x90 -y -f image2 -vframes 1 $thumbnail_output_dir/$filename_minus_ext-$count.jpg";
                
exec("$command",$output);
                
$count $count+1;
                }
                }else{
                
$command "$ffmpeg -i $flv_file -an -s 120x90 -y -f image2 -vframes 3 $thumbnail_output_dir/$filename_minus_ext-%d.jpg";
                
exec($command,$output);
                }
                
$command2 "$ffmpeg -i $flv_file -an -s 320x240 -y -f image2 -vframes 1 $thumbnail_output_dir/$filename_minus_ext-big.jpg";
                
exec($command2,$output2);
                
             
//debugging
                    
$debug_1 $command "\n";//file line of debug
                    
$debug_1 .= $command2 "\n";//file line of debug
                    
foreach ($output as $outputline) {
                        
$debug_1 $debug_1 $outputline "\n";
                        if (
$debugmodex == 1) {//no debug mode
                            
echo ("$outputline<br>");
                        }
                    }
            if (
ENCODING_LOGGING == "yes") {
                        
//check if file exists
                        
$file_contents 'ClipBucket debug' "\n" $command "\n" $command2 "\n".
                            
'Commands were executed.See rest of log for output details' "\n" .
                            
'=================================================================' "\n";
                        
$log_file BASEDIR."/logs/logfile.txt";
                        if (@
file_exists($log_file)) {//append to log file
                            
$fo = @fopen($log_file'a');
                            @
fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                        else {
                            
$fo = @fopen($log_file'w');//else create new log
                            
@fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                    }    
            }
            
            
//THIS FUNCTION IS USED TO GENERATE DEFAULT THUMBS
            
function AssignDefaultThumb($flv){
            
            
//Minus Extension
            
$filename_minus_ext substr($flv0strrpos($flv'.'));
            
$proccesing_thumb TEMPLATEDIR.'/images/processing.png';
            
$proccesing_thumb_big TEMPLATEDIR.'/images/processing-big.png';
            
copy($proccesing_thumb,BASEDIR.'/files/thumbs/'.$filename_minus_ext.'-1.jpg');
            
copy($proccesing_thumb,BASEDIR.'/files/thumbs/'.$filename_minus_ext.'-2.jpg');
            
copy($proccesing_thumb,BASEDIR.'/files/thumbs/'.$filename_minus_ext.'-3.jpg');    
            
copy($proccesing_thumb_big,BASEDIR.'/files/thumbs/'.$filename_minus_ext.'-big.jpg');
            
            }
            
            
//THIS FUNCTION IS USED TO VALIDATE FILETYPE
            
function ValidateFile($file){
            
$ph substr($filestrrpos($file,'.') + 1);
            
$ph strtolower($ph); // Added line to fix case
            
if($ph!="mp4" && $ph!="mov" && $ph!="asf" && $ph!="flv" && $ph!="mpg" && $ph!="avi" && $ph!="mpeg" && $ph!="wmv" && $ph!="rm" && $ph!="dat"
            {
            return 
false;
            }else{
            return 
true;
            }
            
            }
            
            
//THE REAL ENCODING GOES HERE
            
function ConvertFile($file,$flv){
            
                if(
$this->ValidateFile($file)){
            
                
$mencoder         FFMPEG_MENCODER_BINARY;
                
$mplayer         FFMPEG_MPLAYER_BINARY;
                
$flvtool2         FFMPEG_FLVTOOLS_BINARY;
                
$vbrate         VBRATE;
                
$srate            SRATE;
                
$r_height        R_HEIGHT;
                
$ffmpeg         FFMPEG_BINARY;
                
$r_width        R_WIDTH;
                
$resize            RESIZE;
                
$keep_original    KEEP_ORIGINAL;
                
$max_size        MAX_UPLOAD_SIZE;
                
                
//Check VIdeo File Size
                
$size filesize($file);
                if(
$size $max_size){
                
$status "Failed";
                
$flv_file "failed.flv";
                }else{
                
                
$scale "";
                if(
$resize == 'yes'){    
                        
$scale "scale=".$r_width.":".$r_height;
                        
$f_scale "-s ".$r_width."x".$r_height;
                }
                    
$extension substr($filestrrpos($file,'.') + 1);
                    
                    
$video_file BASEDIR.'/files/temp/'.$file;
                    
$flv_file BASEDIR.'/files/videos/'.$flv;
                
                
//LOG THAT THIS PAGE WAS LOADED (debugging for CLI)
                
if (ENCODING_LOGGING == "yes") {
                    
//check if file exists
                    
$file_contents "\n\n\n\n" 'ClipBucket Conversion debug' "\n" .
                        
'CLI for convertor OK' "\n" $config["date_format"] . "\n" .
                        
'================================================================================' .
                        
"\n";
                    
$log_file BASEDIR."/logs/logfile.txt";
                    if (@
file_exists($log_file)) {//append to log file
                        
$fo = @fopen($log_file'a');
                        @
fwrite($fo$file_contents);
                        @
fclose($fo);
                    }
                    else {
                        
$fo = @fopen($log_file'w');//else create new log
                        
@fwrite($fo$file_contents);
                        @
fclose($fo);
                    }
                }

                    
/////////////////////////////////////////////////////////////
                    //                        STEP 1                           //
                    //                  encode video to flv                    //
                    /////////////////////////////////////////////////////////////
    
                        //This Will Check The Extension of the uploaded video and checks its encoding command against each case
                    
$extension strtolower($extension);
                    switch(
$extension){
                    
                    
//For WMV FILES
                    
case 'wmv';
                    
//For High Quality Video
                    //$command  = "$ffmpeg -i $video_file -ab 64 -ar 44100 -b 300k -r 30 -s 720x480 -sameq $flv_file";
                    
$command "$ffmpeg -i $video_file  -ab 32 -ar $srate $f_scale $flv_file";
                    @
exec("$command",$output);
                    
                    if(!
file_exists($flv_file)){
                    
$command "$ffmpeg -i $video_file -ar $srate -ab 32 -f flv $f_scale  $flv_file";
                    @
exec("$command",$output);
                    }
                     
//debugging
                    
$debug_1 $command "\n";//file line of debug
                    
foreach ($output as $outputline) {
                        
$debug_1 $debug_1 $outputline "\n";
                        if (
$debugmodex == 1) {//no debug mode
                            
echo ("$outputline<br>");
                        }
                    }
                    
                    if (
ENCODING_LOGGING == "yes") {
                        
//check if file exists
                        
$file_contents 'ClipBucket debug' "\n" $command "\n" .
                            
'Command was executed.See rest of log for output details' "\n" .
                            
'=================================================================' "\n";
                        
$log_file BASEDIR."/logs/logfile.txt";
                        if (@
file_exists($log_file)) {//append to log file
                            
$fo = @fopen($log_file'a');
                            @
fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                        else {
                            
$fo = @fopen($log_file'w');//else create new log
                            
@fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                    }
            
                    break;
                    
                    
//For Avi Files
                    
case 'avi';
                    
$command "$ffmpeg -i $video_file  -ab 32 -ar $srate $f_scale $flv_file";
                    @
exec("$command",$output);
                    
                    if(!
file_exists($flv_file)){
                    
$command "$ffmpeg -i $video_file -ar $srate -ab 32 -f flv $f_scale  $flv_file";
                    @
exec("$command",$output);
                    }
                    
                     
//debugging
                    
$debug_1 $command "\n";//file line of debug
                    
foreach ($output as $outputline) {
                        
$debug_1 $debug_1 $outputline "\n";
                        if (
$debugmodex == 1) {//no debug mode
                            
echo ("$outputline<br>");
                        }
                    }
                    
                    if (
ENCODING_LOGGING == "yes") {
                        
//check if file exists
                        
$file_contents 'ClipBucket debug' "\n" $command "\n" .
                            
'Command was executed.See rest of log for output details' "\n" .
                            
'=================================================================' "\n";
                        
$log_file BASEDIR."/logs/logfile.txt";
                        if (@
file_exists($log_file)) {//append to log file
                            
$fo = @fopen($log_file'a');
                            @
fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                        else {
                            
$fo = @fopen($log_file'w');//else create new log
                            
@fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                    }
                    
                    break;
                    
                    
//For FLV Files
                    
case 'flv';
                    
copy($video_file,$flv_file);
                    break;
                    
                    
                    default:
                    
//the following can be changed (vbitrate, vop scale, SRATE)
                    
                    
                    
$command "$mencoder $video_file -o $flv_file -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts     vcodec=flv:vbitrate=$vbrate:mbd=2:mv0:trell:v4mv:keyint=10:cbp:last_pred=3 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -vf $scale -srate $srate";
                    @
exec("$command",$output);
    
       
                    
//If no flv was created. Attempt to convert with -vop swicth and not -vf
                    
if(!file_exists($flv_file)){
                    
$command "$mencoder $video_file -o $flv_file -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=$vbrate:mbd=2:mv0:trell:v4mv:keyint=10:cbp:last_pred=3 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -vop $scale -srate $srate";
                     @
exec("$command",$output);
                    }
    
                      
//If no flv was created. Attempt to convert with no -lavcopts i_certify_etc_etc
                    
if(!file_exists($flv_file)){
                    
$command "$mencoder $video_file -o $flv_file -of lavf -oac mp3lame -lameopts abr:br=56 -ovc lavc -lavcopts vcodec=flv:vbitrate=$vbrate:mbd=2:mv0:trell:v4mv:keyint=10:cbp:last_pred=3 -vf $scale -srate $srate";
                    @
exec("$command",$output);
                    }
                    }
                    
                     
//debugging
                    
$debug_1 $command "\n";//file line of debug
                    
foreach ($output as $outputline) {
                        
$debug_1 $debug_1 $outputline "\n";
                        if (
$debugmodex == 1) {//no debug mode
                            
echo ("$outputline<br>");
                        }
                    }
                    
                    if (
ENCODING_LOGGING == "yes") {
                        
//check if file exists
                        
$file_contents 'ClipBucket debug' "\n" $command "\n" .
                            
'Command was executed.See rest of log for output details' "\n" .
                            
'=================================================================' "\n";
                        
$log_file BASEDIR."/logs/logfile.txt";
                        if (@
file_exists($log_file)) {//append to log file
                            
$fo = @fopen($log_file'a');
                            @
fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                        else {
                            
$fo = @fopen($log_file'w');//else create new log
                            
@fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                    }
                    
                    
/////////////////////////////////////////////////////////////
                    //                        STEP 2                           //
                    //                  FLVTOOL2 INJECTION                     //
                    /////////////////////////////////////////////////////////////;
                    
$flv_cmd "$flvtool2 -U $flv_file";
                    @
exec("$flv_cmd 2>&1"$output);
                
                    
//debugging
                    
$debug_2 $flv_cmd "\n";//file line of debug
                    
foreach ($output as $outputline) {
                        
$debug_2 $debug_2 $outputline "\n";
                
                        if (
$debugmodex == 1) {//no debug mode
                            
echo ("$outputline<br>");
                        }
                    }
                    
                    if (
ENCODING_LOGGING== "yes") {
                        
//check if file exists
                        
$file_contents 'ClipBucket debug' "\n" $flv_cmd "\n" .
                            
'Command was executed.See rest of log for output details' "\n" .
                            
'================================================================================' .
                            
"\n";
                        
$log_file BASEDIR."/logs/logfile.txt";
                        if (@
file_exists($log_file)) {//append to log file
                            
$fo = @fopen($log_file'a');
                            @
fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                        else {
                            
$fo = @fopen($log_file'w');//else create new log
                            
@fwrite($fo$file_contents);
                            @
fclose($fo);
                        }
                    }
                    
                
/////////////////////////////////////////////////////////////
                //                        STEP 3                           //
                //                  get video duration                      //
                /////////////////////////////////////////////////////////////
                //Try and read the time from the output files
/*                $shell_output = $debug_1 . $debug_2;//get as much sheel out put as possible to run search for duration
                if (@preg_match('/Video stream:.*bytes..(.*?).sec/', $shell_output, $regs)) {
                    $sec = $regs[1];
                    $duration = $sec;//covert to 00:00:00 i.e. hrs:min:sec
                    $sec = date("s", strtotime($duration));//change back to seconds for use in getting middle of video
                }
                else {
                    $sec = "";
                    $duration = $sec;
                }
            
                //check if duration has been picked up...if not try second method  (ffmpeg -i video.flv)
                if ($sec == "" || !is_numeric($sec)) {
                    $check_duration = $ffmpeg . ' -i ' . $flv_file;
                    $durationfile = "";
                    @exec("$check_duration 2>&1", $durationoutput);
            
                    foreach ($durationoutput as $outputline) {
                        $durationfile = $durationfile . $outputline . "\n";
            
                    }
            
                    if (preg_match('/uration:.(.*?)\./', $durationfile, $regs)) {
                        $duration = $regs[1];//duration already in 00:00:00 format
                        $sec = date("s", strtotime($duration));//change back to seconds for use in getting middle of video
                        $duration = $sec ;
                    }
            
                }*/
                
                //The Final Step, If Duration Still has not been picked up
                
if ($sec == "" || !is_numeric($sec) || $sec == "00") {
                        
exec("$mplayer -vo null -ao null -frames 0 -identify $flv_file"$p);
                        while(list(
$k,$v)=each($p))
                            {
                            if(
$length=strstr($v,'ID_LENGTH='))
                            break;
                            }
                        
$lx explode("=",$length);
                        
$duration round($lx[1]);
                        
$sec $duration ;
                }
            
                
//LOG THAT STEP 3 was ok
                
if (ENCODING_LOGGING == "yes") {
                
$main_duration  $duration;
                    
//check if file exists
                    
$file_contents 'ClipBucket debug' "\n" .
                        
'FFMPEG-PHP - check - Video Duration = ' $sec"\n" .
                        
'================================================================================' .
                        
"\n";
                    
$log_file BASEDIR."/logs/logfile.txt";
                    if (@
file_exists($log_file)) {//append to log file
                        
$fo = @fopen($log_file'a');
                        @
fwrite($fo$file_contents);
                        @
fclose($fo);
                    }
                    else {
                        
$fo = @fopen($log_file'w');//else create new log
                        
@fwrite($fo$file_contents);
                        @
fclose($fo);
                    }
                }
            
            
                        if(
$keep_original == 1){
                        
$original_file BASEDIR.'/files/original/'.$file;
                        
copy($video_file,$original_file);
                        }
    
                        
$status "Successful";
                
                        
                        
//If MAX SIZE CONDITION ENDs    
                        
mysql_query("INSERT INTO video_detail(flv,status,duration,original) VALUES ('".$flv."','".$status."','".$sec."','".$file."')");
                        
mysql_query("UPDATE video SET duration='".$sec."' , status='".$status."' WHERE flv = '".$flv."'");
                        
                        
unlink($video_file);
                        
//$this->AssignDefaultThumb($flv);
                        
$this->AssignGeneratedThumbs($flv,$sec);
                    }
                    }
                    
                        if(!
file_exists($flv_file)){
                        
$status "Failed";
                        
$this->AssignDefaultThumb($flv);                        
                        
mysql_query("UPDATE video_detail SET status='".$status."' WHERE flv = '".$flv."'");
                        
mysql_query("UPDATE video SET active='no'  AND status='".$status."' WHERE flv = '".$flv."'");
                        }
                }
                
}
                 
/*
$ffmpeg = new ffmpeg();
$file = "920657135.WMV";
$flv = "920657135.flv";
$ffmpeg->ConvertFile($file,$flv);
*/

?>
Here is an example of how the sql needs to work
Code:
-- phpMyAdmin SQL Dump
-- version 2.11.6
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 06, 2008 at 09:26 PM
-- Server version: 4.1.22
-- PHP Version: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `forbushj_onetest`
--

-- --------------------------------------------------------

--
-- Table structure for table `video`
--

CREATE TABLE IF NOT EXISTS `video` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(75) NOT NULL default '',
  `descr` text NOT NULL,
  `pic` varchar(30) NOT NULL default '',
  `locat` varchar(40) NOT NULL default '',
  `src` varchar(35) NOT NULL default '',
  `public` char(1) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `title` (`title`),
  FULLTEXT KEY `title_2` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ;

--
-- Dumping data for table `video`
--

INSERT INTO `video` (`id`, `title`, `descr`, `pic`, `locat`, `src`, `public`) VALUES
(1, 'Crazy Glue Trick ...By [KX3]', 'This is a crazy experiment with crazy glue that is kind of funny two people getting stuck together by crazy glue.', '1.jpg', '1.flv', 'http://kx3.technologyforever.com', '1'),
(2, 'Ring of Fire:: Take 2', 'Staring Mikhael Corsi Ring of Fire is exactly what it sounds like it is indeed a Ring of fire ', '2.jpg', '2.flv', 'http://www.TechnologyForever.com', '1'),
(3, 'Emo Kids with Pepper Spray Take 2', 'Staring Nate & Andy from [KX3] these guys are funny in this video Nate & Andy do an activity that usually no one wants to do not even the police they test pepper spray on each other.', '3.jpg', '3.flv', 'http://kx3.technologyforever.com/', '1'),
(4, 'Emo Kid Donkey Punch!!', 'Staring Nate from [KX3] these guys are funny in this video Nate and Andy demonstrate the donkey punch in this funny video', '4.jpg', '4.flv', 'http://kx3.technologyforever.com/', '1'),
(5, 'Ian Erix- "CONFESSIONS OF A KILLER"(VERSION 2)', 'This is the MUSIC VIDEO Confessions Of A Killer by Ian Erix and is second version of this music video.', '5.jpg', '5.flv', 'http://www.ianerix.com', '1');
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
View Public Profile Visit goheadtry's homepage!
 
 
Register now for full access!
Old 07-07-2008, 07:46 PM Re: I bought clip bucket but I want to strip it down? Incoding with ffmpeg
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Ok, so what is the question?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
View Public Profile
 
Old 07-08-2008, 02:28 PM Re: I bought clip bucket but I want to strip it down? Incoding with ffmpeg
goheadtry's Avatar
Webmaster Talker

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
I need to make it so I can upload a video that is 100 meg limit then use that script to convert it then right the information to mysql.


So {upload}-> {Convert} ->{write to mysql.}
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
View Public Profile Visit goheadtry's homepage!
 
Old 07-08-2008, 07:29 PM Re: I bought clip bucket but I want to strip it down? Incoding with ffmpeg
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
So basically... you want someone to re-write this script to suit your needs...

Get your wallet out and you might find someone might help

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
View Public Profile Visit dansgalaxy's homepage!
 
Old 07-08-2008, 07:59 PM Re: I bought clip bucket but I want to strip it down? Incoding with ffmpeg
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You could either modify that script, or better yet write an extention class that will do the parent chores along with new additional functionality.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
View Public Profile
 
Closed Thread     « Reply to I bought clip bucket but I want to strip it down? Incoding with ffmpeg
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18352 seconds with 12 queries