#!/usr/bin/perl -w ##========================================================================== ## ## Copyright (c) On2 Technologies Inc. All Rights Reserved. ## ##-------------------------------------------------------------------------- ## ## File: $Workfile$ ## $Revision$ ## ## Last Update: $DateUTC$ ## ##-------------------------------------------------------------------------- ## use On2::flixengine2; use File::Spec::Functions; package On2::flixengine2; #use flixengine2's namespace #checks the return value of an API function printing error information on #failure. usage checksc(funcname,sc) sub checksc($$) { my $sc = $_[1]; if ($sc != $ON2_OK) { my $esc; select STDERR; print "$_[0] 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 @_ = Flix2_Errno($flix); $esc= shift; printf(" Flix2_Errno: sc:%d %s:%d syserrno:%d\n", $esc,($sc==$ON2_NET_ERROR)?"rpcerr":"flixerrno",$_[0],$_[1]); exit 1; } } sub print_encoder_status() { print "\nEncoder Status\n"; my $state = Flix2_GetEncoderState($flix); print " Flix2_GetEncoderState: $state\n"; my ($sc,@err) = Flix2_Errno($flix); printf(" Flix2_Errno: sc:%d flixerrno:%d syserrno:%d\n",$sc,$err[0],$err[1]); } my $rpchost = "localhost"; my $timeout_s = 0; #rpc timeout in seconds, 0=use default (25s) print "Flix Engine client library v".Flix2_Version()."\n"; print Flix2_Copyright()."\n\n"; die "usage: ./cli_encode.pl <infile> <outfile>\n\n". "NOTE cli_encode.pl 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" if @ARGV < 2; #create a new flix2handle ptr my $flixptr = new_flix2handlep(); ## contact flixd on rpchost w/timeout of timeout_s. ## A port may be specified by giving rpchost in the form 'server:port' ## to avoid making a connection to portmap before contacting flixd. ## This is only useful if flixd is being run with the --port option. ## If timeout_s is 0 rpc's default timeout will be used (typically 25s) my $sc = Flix2_CreateEx($flixptr, $rpchost, $timeout_s); #recover the actual handle value to be used in remaining flixengine calls $flix = flix2handlep_value($flixptr); checksc('Flix2_CreateEx',$sc); print "Input File : $ARGV[0]\n"; print "WARNING: path to input file is not absolute\n" unless File::Spec::Functions::file_name_is_absolute($ARGV[0]); $sc = Flix2_SetInputFile($flix, $ARGV[0]); checksc('Flix2_SetInputFile', $sc); ##input file information my ($srcduration,$srcw,$srch); ($sc,$srcduration)= Flix2_GetSourceDuration($flix); checksc('Flix2_GetSourceDuration', $sc); ($sc,$srcw)= video_options_GetSourceWidth($flix); checksc('video_options_GetSourceWidth', $sc); ($sc,$srch)= video_options_GetSourceHeight($flix); checksc('video_options_GetSourceHeight', $sc); print <<EOT; Width: $srcw Height: $srch Duration: ${srcduration}ms EOT print "Output File : $ARGV[1]\n"; print "WARNING: path to output file is not absolute\n" unless File::Spec::Functions::file_name_is_absolute($ARGV[1]); $sc = Flix2_SetOutputFile($flix, $ARGV[1]); 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 #my $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 #my $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); $filterptr= undef; # ##Add the vp6 codec. Though it is the default, you must add it in order ##to modify its settings #my $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 #my $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); $codecptr= undef; # ##Use the FLV muxer (default) #my $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 #my $muxer= flix2plgnhandlep_value($muxerptr); # ##cleanup #delete_flix2plgnhandlep($muxerptr); $muxerptr= undef; $sc = Flix2_Encode($flix); checksc('Flix2_Encode',$sc); print "\n"; $| = 1; #auto flush my ($ier,$pcnt); do { ($sc,$ier)= Flix2_IsEncoderRunning($flix); checksc('Flix2_IsEncoderRunning',$sc); ($sc,$pcnt)= encoding_status_PercentComplete($flix); checksc('encoding_status_PercentComplete',$sc); print "\rEncoding...$pcnt% "; sleep(1); } while($ier); print "Done!\n"; print_encoder_status(); #cleanup $sc = Flix2_Destroy($flix); checksc('Flix2_Destroy',$sc); delete_flix2handlep($flixptr);