#!php <?php ##========================================================================== ## ## Copyright (c) On2 Technologies Inc. All Rights Reserved. ## ##-------------------------------------------------------------------------- ## ## File: $Workfile$ ## $Revision$ ## ## Last Update: $DateUTC$ ## ##-------------------------------------------------------------------------- ## $cli_encode= 1; $version = explode('.',phpversion()); ## report all errors error_reporting(E_ALL); ## disable html w/in error text ini_set("html_errors","0"); ## ## Manually load the Flix Engine type library to allow PHP to register ## constants contained within it. PHP4 seems to ignore com.autoregister_typelib. ## In addition PHP 5.2.0 will cause an exception on exit with autoregister. ## 5.(0|1).x seem to show the opposite behavior. ## if($version[0]<5 || ($version[0]==5 && $version[1]>1)) { ini_set("com.autoregister_typelib","0"); com_load_typelib("On2.FlixEngine") or die("Error loading Flix Engine type library"); } else { ini_set("com.autoregister_typelib","1"); } ## allow encodes of long files to complete ini_set("max_execution_time","-1"); ini_set("max_input_time","-1"); function print_encoder_status() { global $flix, $version; print "\nEncoder Status\n"; $res= $flix->getEncoderState(); print " flix->getEncoderState: $res\n"; if($version[0] == 4) { $flixerr= $flix->flixerrno(); $syserr= $flix->syserrno(); } else { ## PHP5 can automatically detect byref parameters $flixerr = $syserr = 0; $flix->errno_($flixerr,$syserr); } printf(" flix->errno_: flixerrno:%d syserrno:%d\n",$flixerr,$syserr); } function configure_encode() { global $argv, $flix, $version; ## ## print some library information ## print "Flix Engine COM library. Flix Engine v".$flix->version(). " COM v".$flix->com_version()."\n"; print $flix->copyright()."\n\n"; if (count($argv) < 3) { die("usage: cli_encode.php <infile> <outfile>\n"); } ## ## set the source file ## print "Input File : $argv[1]\n"; $flix->setInputFile($argv[1]); ## ## retrieve the video options interface, IVideoOptions ## $vidopts= $flix->videoOptions(); ## ## print input file information ## $srcduration= $flix->getSourceDuration(); $srcw= $vidopts->getSourceWidth(); $srch= $vidopts->getSourceHeight(); echo <<<EOT Width: $srcw Height: $srch Duration: ${srcduration}ms EOT; if($version[0] == 4) { ##release vidopts as we're through with it $vidopts->Release(); } ## ## set the destination file ## echo "Output File : $argv[2]\n"; $flix->setOutputFile($argv[2]); ## ## Options may be set and codecs/filters/muxers may be added prior to encode() ## ##Add the scale filter #$filter= $flix->addFilter($flix->FE2_FILTER_SCALE); # #$filter->setParam($flix->FE2_SCALE_WIDTH,240); #$filter->setParam($flix->FE2_SCALE_HEIGHT,160); #if($version[0] == 4) { # $filter->Release(); #} ##Add the vp6 codec. Though it is the default, you must add it in order ##to modify its settings #$codec= $flix->addCodec($flix->FE2_CODEC_VP6); # #$codec->setParam($flix->FE2_VP6_RC_MODE,VBR_1PASSControl); #if($version[0] == 4) { # $codec->Release(); #} ##Use the FLV muxer (default) #$muxer= $flix->addMuxer($flix->FE2_MUXER_FLV); # #if($version[0] == 4) { # $muxer->Release(); #} } ## function configure_encode() function encode() { global $flix; ## ## start the encode ## $flix->encode(); ## ## retrieve the encoding status interface, IEncodingStatus ## $encstatus= $flix->encodingStatus(); print "\n"; do { sleep(1); flush(); $ier= $flix->isEncoderRunning(); print "\rEncoding...".$encstatus->percentComplete()."% "; } while($ier); echo "Done!\n"; print_encoder_status(); } ## function encode() ## ## retrieve the main engine interface, IFlix ## $flix= new COM("On2.FlixEngine") or die("Error loading Flix Engine COM!"); ##enable logging, 0=none(disable) 1=info 2=error(asserts) 3=debug 4=heavy ##CONOUT$ can be used as the log file name to send output to the console #$flix->setLogLevel(3); #$flix->setLogPath("\\cli_encode.php.log"); if($version[0] == 4) { print "******************************\n"; print "It appears you're running under PHP4 (".phpversion().").\n". "This version of PHP does not provide a way to trap". " errors returned from the COM library aside from the ways provided". " by PHP itself (track_errors, set_error_handler, ...).". " Should a function fail only an E_WARNING will be issued.\n\n". "For this reason it is STRONGLY recommended that you consider". " using PHP5 as it provides try/catch blocks and throws". " a com_exception should a function fail.\n"; print "******************************\n\n"; include 'cli_encode.php4'; } else { include 'cli_encode.php5'; } ## vim:expandtab ?>