#!/usr/bin/perl -w
##==========================================================================
##
## Copyright (c) On2 Technologies Inc. All Rights Reserved.
##
##--------------------------------------------------------------------------
##
## File: $Workfile$
## $Revision$
##
## Last Update: $DateUTC$
##
##--------------------------------------------------------------------------
##
use Win32::OLE;
## extract constants from the type lib
use Win32::OLE::Const 'On2.FlixEngine Type Library';
use Win32::OLE::Variant;
sub print_encoder_status()
{
print "\nEncoder Status\n";
$res= $flix->getEncoderState();
print " flix->getEncoderState: $res\n";
my $flixerr= Variant(VT_I4|VT_BYREF,0);
my $syserr= Variant(VT_I4|VT_BYREF,0);
$flix->errno_($flixerr,$syserr);
printf(" flix->errno_: flixerrno:%d syserrno:%d\n",$flixerr,$syserr);
}
sub checkhr($)
{
if(Win32::OLE->LastError) {
warn "$_[0] failed. hr= ".Win32::OLE->LastError;
print_encoder_status();
exit 1;
}
}
##
## retrieve the main engine interface, IFlix
##
$flix= Win32::OLE->new("On2.FlixEngine") or
die("Error loading Flix Engine COM: $!, ".Win32::OLE->LastError);
##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); checkhr('flix->setLogLevel');
#$flix->setLogPath("\\cli_encode.pl.log"); checkhr('flix->setLogPath');
##
## 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(@ARGV<2) {
die("usage: cli_encode.pl <infile> <outfile>\n");
}
##
## set the source file
##
print "Input File : $ARGV[0]\n";
$flix->setInputFile($ARGV[0]); checkhr('flix->setInputFile($ARGV[0])');
##
## retrieve the video options interface, IVideoOptions
##
$vidopts= $flix->videoOptions(); checkhr('flix->videoOptions()');
##
## print input file information
##
$srcduration= $flix->getSourceDuration(); checkhr('flix->getSourceDuration()');
$srcw= $vidopts->getSourceWidth(); checkhr('vidopts->getSourceWidth()');
$srch= $vidopts->getSourceHeight(); checkhr('vidopts->getSourceHeight()');
print <<EOT;
Width: $srcw
Height: $srch
Duration: ${srcduration}ms
EOT
##
## set the destination file
##
print "Output File : $ARGV[1]\n";
$flix->setOutputFile($ARGV[1]); checkhr('flix->setOutputFile($ARGV[1]');
##
## 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);
# checkhr('flix->addFilter(FE2_FILTER_SCALE)');
#
#$filter->setParam($flix->FE2_SCALE_WIDTH, 240);
# checkhr('flix->setParam(FE2_SCALE_WIDTH,240)');
#$filter->setParam($flix->FE2_SCALE_HEIGHT,160);
# checkhr('flix->setParam(FE2_SCALE_HEIGHT,160)');
##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);
# checkhr('flix->addCodec(FE2_CODEC_VP6)');
#
#$codec->setParam($flix->FE2_VP6_RC_MODE,VBR_1PASSControl);
# checkhr('codec->setParam(FE2_VP6_RC_MODE,VBR_1PASSControl)');
##Use the FLV muxer (default)
#$muxer= $flix->addMuxer($flix->FE2_MUXER_FLV);
# checkhr('flix->addMuxer(FE2_MUXER_FLV)');
##
## start the encode
##
$flix->encode(); checkhr('flix->encode()');
##
## retrieve the encoding status interface, IEncodingStatus
##
$encstatus= $flix->encodingStatus(); checkhr('flix->encodingStatus()');
print "\n";
$| = 1; #auto flush
my $ier;
do {
sleep(1);
$ier = $flix->isEncoderRunning();
print "\rEncoding...".$encstatus->percentComplete()."% ";
} while($ier);
print "Done!\n";
print_encoder_status();
##cleanup
Win32::OLE->Uninitialize();