Command Line

/*
//==========================================================================
//
//  Copyright (c) On2 Technologies Inc. All Rights Reserved.
//
//--------------------------------------------------------------------------
//
//  File:        $Workfile$
//               $Revision$
//
//  Last Update: $DateUTC$
//
//--------------------------------------------------------------------------
*/
import com.on2.flixengine_com.*;

public class cli_encode {
    static IFlix flix;
    
    private static void init() {
        try {
            /*
             * Retrieve the main engine interface, IFlix
             */
            flix = ClassFactory.createFlix();
        } catch(RuntimeException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    private static void printStackTrace(RuntimeException e) {
        e.printStackTrace();
        printEncoderStatus();
        System.exit(1);
    }

    public static void main(String[] args) {
        init();

        /*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
        try {
            flix.setLogLevel(3);
            flix.setLogPath("C:\\cli_encode_java.log");
        } catch(RuntimeException e) {
            printStackTrace(e);
        }*/

        /*
         * print some library information
         */
        try {
            System.out.println("Flix Engine COM library. Flix Engine v" +
                               flix.version() + " COM v" + flix.com_version());
            System.out.println(flix.copyright() + "\n");
        } catch(RuntimeException e) {
            printStackTrace(e);
        }

        if (args.length != 2) {
            System.out.println("usage: java -classpath "+
                    "flixengine_com.jar;com4j.jar;."+
                    " cli_encode <infile> <outfile>\n");
            System.exit(1);
        }

        /*
         * set the source file
         */
        try {
            System.out.println("Input File : " + args[0]);
            flix.setInputFile(args[0]);
        } catch(RuntimeException e) {
            printStackTrace(e);
        }

        /*
         * retrieve the video options interface, IVideoOptions
         */
        try {
            IVideoOptions vidOpts = flix.videoOptions();

            /*
             * print input file information
             */
            int width     = vidOpts.getSourceWidth();
            int height    = vidOpts.getSourceHeight();
            int duration  = flix.getSourceDuration();
            System.out.println("              Width:     " + width + "\n" +
                               "              Height:    " + height + "\n" +
                               "              Duration:  " + duration + "ms");
        } catch(RuntimeException e) {
            printStackTrace(e);
        }

        /*
         * set the destination file
         */
        try {
            flix.setOutputFile(args[1]);
            System.out.println("Output File : " + args[1]);
        } catch(RuntimeException e) {
            printStackTrace(e);
        }

        /*
         * Options may be set and codecs/filters/muxers may be added prior to encode()
         */

        /*Add the scale filter
        try {
            IFlixPlgn filter= flix.addFilter(flix.fE2_FILTER_SCALE());
            filter.setParam(flix.fE2_SCALE_WIDTH(),320);
            filter.setParam(flix.fE2_SCALE_HEIGHT(),240);
        } catch(RuntimeException e) {
            printStackTrace(e);
        }*/

        /*Add the vp6 codec. Though it is the default, you must add it in order
          to modify its settings
        try {
            IFlixPlgn codec= flix.addCodec(flix.fE2_CODEC_VP6());

            codec.setParam(flix.fE2_VP6_RC_MODE(),
                    FE2_VideoBitrateControls.VBR_1PASSControl.ordinal());
        } catch(RuntimeException e) {
            printStackTrace(e);
        }*/

        /*Use the FLV muxer (default)
        try {
            IFlixPlgn muxer= flix.addMuxer(flix.fE2_MUXER_FLV());
        } catch(RuntimeException e) {
            printStackTrace(e);
        }*/

        /*
         * start the encode
         */
        try {
            flix.encode();

            /*
             * retrieve the encoding status interface, IEncodingStatus
             */
            IEncodingStatus status = flix.encodingStatus();

            System.out.println();
            boolean ier;
            do {
                try {Thread.currentThread().sleep(500);}
                catch(InterruptedException e) {}
                ier = flix.isEncoderRunning()==1;
                System.out.print("\rEncoding... "+status.percentComplete()+"% ");
            } while(ier);
            System.out.println("Done!");
            printEncoderStatus();
        } catch(RuntimeException e) {
            System.out.println(e);
            printEncoderStatus();
        }

        /*
         * Force the cleanup of IFlix.
         * Though this is not strictly necessary in this sample, as
         * it is about to exit, if the script is more involved it may be
         * necessary so the input file can be moved as destruction of
         * the underlying FLIX2HANDLE occurs within IFlix's destructor.
         */
        flix.dispose(); flix = null;
        /*
         * Additionally, free any resources/threads started by com4j for use
         * with this object
         */
        com4j.COM4J.cleanUp();
    }

    private static void printEncoderStatus() {
        System.out.println("\nEncoder Status");
        FE2_EncState res = flix.getEncoderState();
        System.out.println(" flix.getEncoderState: " + res );

        System.out.println(" flix.errno_: flixerrno:" + flix.flixerrno() +
                           " syserrno:" + flix.syserrno());
    }
}

On2 Technologies, Inc Flix Engine Windows documentation, generated on Tue Nov 2 15:38:06 2010 by doxygen 1.6.1