Command Line

#!/usr/bin/python -u
##==========================================================================
##
##  Copyright (c) On2 Technologies Inc. All Rights Reserved.
##
##--------------------------------------------------------------------------
##
##  File:        $Workfile: cli_encode.py$
##               $Revision: 15$
##
##  Last Update: $DateUTC: 2007-09-11 20:31:03Z$
##
##--------------------------------------------------------------------------
##
import flixengine2
import time,sys,os

#checks the return value of an API function printing error information on
#failure. usage checksc(funcname,sc)
def checksc(func, sc):
    if (sc != flixengine2.ON2_OK):
        print "%s failed: sc= %d" % (func,sc)

        #if sc == ON2_NET_ERROR Flix2_Errno will return the specific rpc error
        #encountered as flixerrno along with the client lib's errno value
        if (sc == flixengine2.ON2_NET_ERROR): str = "rpcerr";
        else: str = "flixerrno";

        res = flixengine2.Flix2_Errno(flix)
        print " Flix2_Errno: sc:%d %s:%d syserrno:%d\n" %\
            (res[0],str,res[1],res[2])
        raise Exception(func)

def SimpleSet(func, arg):
    sc = func(flix, arg)
    checksc(func,sc)

def SimpleGet(func):
    res = func(flix)
    checksc(func,res[0])
    return res[1]

def print_encoder_status():
    print "\nEncoder Status"

    res = flixengine2.Flix2_GetEncoderState(flix)
    print " Flix2_GetEncoderState: %d" % res[1]

    res = flixengine2.Flix2_Errno(flix)
    print " Flix2_Errno: sc:%d flixerrno:%d syserrno:%d\n" %\
        (res[0],res[1],res[2])

print "Flix Engine client library v%s" % flixengine2.Flix2_Version()
print "%s\n" % flixengine2.Flix2_Copyright()

if (len(sys.argv) < 3):
    print "usage: cli_encode.py <infile> <outfile>\n\n"\
          "NOTE cli_encode.py 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"
    raise Exception()

timeout_s = 0 #rpc timeout in seconds, 0=use default (25s)

flixptr = flixengine2.new_flix2handlep()
sc = flixengine2.Flix2_CreateEx(flixptr, "localhost", timeout_s)

# retrieve the actual flix handle for use in the remaining API calls
flix = flixengine2.flix2handlep_value(flixptr)
checksc('flixengine2.Flix2_CreateEx',sc)

print "Input File  : %s" % sys.argv[1]
if(os.path.isabs(sys.argv[1])!=True):
    print "WARNING: path to input file is not absolute"
SimpleSet(flixengine2.Flix2_SetInputFile,sys.argv[1])

##input file information
print "              Width:    %d\n" \
      "              Height:   %d\n" \
      "              Duration: %dms" % \
    (SimpleGet(flixengine2.video_options_GetSourceWidth),
     SimpleGet(flixengine2.video_options_GetSourceHeight),
     SimpleGet(flixengine2.Flix2_GetSourceDuration))

print "Output File : %s" % sys.argv[2]
if(os.path.isabs(sys.argv[2])!=True):
    print "WARNING: path to output file is not absolute"
SimpleSet(flixengine2.Flix2_SetOutputFile,sys.argv[2])

##
## Options may be set and codecs/filters may be added prior to Flix2_Encode()
##

##Add the scale filter
#create a storage location for the filter handle
#filterptr= flixengine2.new_flix2plgnhandlep()
#sc = flixengine2.Flix2_AddFilter(filterptr,
#        flix,flixengine2.FE2_FILTER_SCALE)
#checksc('Flix2_AddFilter(FE2_FILTER_SCALE)',sc)
#
##retrieve the value of the handle for use in the remaining filter functions
#filter= flixengine2.flix2plgnhandlep_value(filterptr)
#sc = flixengine2.Flix2_FilterSetParam(filter,
#         flixengine2.FE2_SCALE_WIDTH,240)
#checksc('Flix2_FilterSetParam(FE2_SCALE_WIDTH,240)',sc)
#sc = flixengine2.Flix2_FilterSetParam(filter,
#         flixengine2.FE2_SCALE_HEIGHT,160)
#checksc('Flix2_FilterSetParam(FE2_SCALE_HEIGHT,160)',sc)
#
##cleanup
#flixengine2.delete_flix2plgnhandlep(filterptr); filterptr= None

##Add the vp6 codec. Though it is the default, you must add it in order
##to modify its settings
#codecptr= flixengine2.new_flix2plgnhandlep()
#sc = flixengine2.Flix2_AddCodec(codecptr,flix,flixengine2.FE2_CODEC_VP6)
#checksc('Flix2_AddCodec(FE2_CODEC_VP6)',sc)
#
##retrieve the value of the handle for use in the remaining codec functions
#codec= flixengine2.flix2plgnhandlep_value(codecptr)
#
#sc = flixengine2.Flix2_CodecSetParam(codec,
#         flixengine2.FE2_VP6_RC_MODE,flixengine2.VBR_1PASSControl)
#checksc('Flix2_CodecSetParam(FE2_VP6_RC_MODE,VBR_1PASSControl)',sc)
#
##cleanup
#flixengine2.delete_flix2plgnhandlep(codecptr); codecptr= None

sc = flixengine2.Flix2_Encode(flix)
checksc('flixengine2.Flix2_Encode',sc)

ier = 1
print
while(ier != 0):
    ier = SimpleGet(flixengine2.Flix2_IsEncoderRunning)
    print "\rEncoding...%d%%  " % \
        SimpleGet(flixengine2.encoding_status_PercentComplete),
    time.sleep(1)

print "Done!"
print_encoder_status()

#cleanup
sc = flixengine2.Flix2_Destroy(flix)
flixengine2.delete_flix2handlep(flixptr)

On2 Technologies, Inc Flix Engine Linux documentation, generated on Mon May 19 10:56:10 2008 by doxygen 1.5.2