#!/usr/bin/env php <?php ##========================================================================== ## ## Copyright (c) On2 Technologies Inc. All Rights Reserved. ## ##-------------------------------------------------------------------------- ## ## File: $Workfile$ ## $Revision$ ## ## Last Update: $DateUTC$ ## ##-------------------------------------------------------------------------- ## #checks the return value of an API function printing error information on #failure. usage checksc(funcname,sc) function checksc($func, $sc) { global $flix; if ($sc != ON2_OK) { echo "$func failed: sc= $sc\n"; ##if sc == ON2_NET_ERROR Flix2_Errno will return the specific rpc error ##encountered as flixerrno along with the client lib's errno value $res = Flix2_Errno($flix); printf(" Flix2_Errno: sc:%d %s:%d syserrno:%d\n", $res[0],($sc==ON2_NET_ERROR)?"rpcerr":"flixerrno",$res[1],$res[2]); die; } } function print_encoder_status() { global $flix; echo "\nEncoder Status\n"; $res = Flix2_GetEncoderState($flix); echo " Flix2_GetEncoderState: $res[1]\n"; $res = Flix2_Errno($flix); printf(" Flix2_Errno: sc:%d flixerrno:%d syserrno:%d\n", $res[0],$res[1],$res[2]); } # Load the FlixEngine module $flixphp = 'flixengine2.php'; echo 'Loading flix: ' . $flixphp . "\n"; # If this include fails you may need to edit you include_path variable in # your php.ini file. # See the accompanying Flix Linux Engine documentation for further details. # add extension_dir/.. to 'include_path' as this is often missing from php.ini set_include_path(get_include_path().PATH_SEPARATOR.ini_get("extension_dir")."/.."); include ($flixphp); printf("Flix Engine client library v%s\n",Flix2_Version()); printf("%s\n\n",Flix2_Copyright()); if (count($argv) < 3) { die("usage: cli_encode.php <infile> <outfile>\n\n". "NOTE cli_encode.php uses libflixengine2.so which is a client\n". "NOTE side rpc library. All paths must be accessible to the\n". "NOTE server side, i.e., flixd, thus relative paths will most\n". "NOTE likely give undesired results. The same can be said\n". "NOTE for clients running on different machines.\n"); } $timeout_s = 0; #rpc timeout in seconds, 0=use default (25s) $flixptr = new_flix2handlep(); $sc = Flix2_CreateEx($flixptr, "localhost", $timeout_s); # retrieve the actual flix handle for use in the remaining API calls $flix = flix2handlep_value($flixptr); checksc('Flix2_CreateEx',$sc); echo "Input File : $argv[1]\n"; if(!ereg("^/",$argv[1])) { echo "WARNING: path to input file is not absolute\n"; } $sc = Flix2_SetInputFile($flix, $argv[1]); checksc('Flix2_SetInputFile',$sc); ##input file information $srcduration = Flix2_GetSourceDuration($flix); checksc('Flix2_GetSourceDuration',$srcduration[0]); $srcw = video_options_GetSourceWidth($flix); checksc('video_options_GetSourceWidth',$srcw[0]); $srch = video_options_GetSourceHeight($flix); checksc('video_options_GetSourceHeight',$srch[0]); echo <<<EOT Width: $srcw[1] Height: $srch[1] Duration: $srcduration[1]ms EOT; echo "Output File : $argv[2]\n"; if(!ereg("^/",$argv[2])) { echo "WARNING: path to output file is not absolute\n"; } $sc = Flix2_SetOutputFile($flix, $argv[2]); checksc('Flix2_SetOutputFile',$sc); ## ## Options may be set and codecs/filters/muxers may be added prior to Flix2_Encode() ## ##Add the scale filter ##create a storage location for the filter handle #$filterptr= new_flix2plgnhandlep(); #$sc = Flix2_AddFilter($filterptr,$flix,FE2_FILTER_SCALE); # checksc('Flix2_AddFilter(FE2_FILTER_SCALE)',$sc); # ##retrieve the value of the handle for use in the remaining filter functions #$filter= flix2plgnhandlep_value($filterptr); #$sc = Flix2_FilterSetParam($filter,FE2_SCALE_WIDTH,240); # checksc('Flix2_FilterSetParam(FE2_SCALE_WIDTH,240)',$sc); #$sc = Flix2_FilterSetParam($filter,FE2_SCALE_HEIGHT,160); # checksc('Flix2_FilterSetParam(FE2_SCALE_HEIGHT,160)',$sc); # ##cleanup #delete_flix2plgnhandlep($filterptr); unset($filterptr); # ##Add the vp6 codec. Though it is the default, you must add it in order ##to modify its settings #$codecptr= new_flix2plgnhandlep(); #$sc = Flix2_AddCodec($codecptr,$flix,FE2_CODEC_VP6); # checksc('Flix2_AddCodec(FE2_CODEC_VP6)',$sc); # ##retrieve the value of the handle for use in the remaining codec functions #$codec= flix2plgnhandlep_value($codecptr); # #$sc = Flix2_CodecSetParam($codec,FE2_VP6_RC_MODE,VBR_1PASSControl); # checksc('Flix2_CodecSetParam(FE2_VP6_RC_MODE,VBR_1PASSControl)',$sc); # ##cleanup #delete_flix2plgnhandlep($codecptr); unset($codecptr); # ##Use the FLV muxer (default) #$muxerptr= new_flix2plgnhandlep(); #$sc = Flix2_AddMuxer($muxerptr,$flix,FE2_MUXER_FLV); # checksc('Flix2_AddMuxer(FE2_MUXER_FLV)',$sc); # ##retrieve the value of the handle for use in the remaining muxer functions #$muxer= flix2plgnhandlep_value($muxerptr); # ##cleanup #delete_flix2plgnhandlep($muxerptr); unset($muxerptr); $sc = Flix2_Encode($flix); checksc('Flix2_Encode',$sc); echo "\n"; do { $ier = Flix2_IsEncoderRunning($flix); checksc('Flix2_IsEncoderRunning',$ier[0]); $pcnt = encoding_status_PercentComplete($flix); checksc('encoding_status_PercentComplete',$pcnt[0]); echo "\rEncoding...$pcnt[1]% "; sleep(1); } while(($sc == ON2_OK) && ($ier[1] != on2false)); echo "Done!\n"; print_encoder_status(); #cleanup $sc = Flix2_Destroy($flix); checksc('Flix2_Destroy',$sc); delete_flix2handlep($flixptr); ?>