'==========================================================================
'
' Copyright (c) On2 Technologies Inc. All Rights Reserved.
'
'--------------------------------------------------------------------------
'
' File: $Workfile$
' $Revision$
'
' Last Update: $DateUTC$
'
'--------------------------------------------------------------------------
Imports System
Imports System.Runtime.InteropServices 'COMException
Imports flixengine_com 'Flix Engine interfaces
Module cli_encode
Sub PrintStackTrace(ByVal flix As Flix, ByVal e As COMException)
Console.WriteLine(e)
If Not flix Is Nothing
PrintEncoderStatus(flix)
End If
Environment.Exit(e.ErrorCode)
End Sub
Sub Main()
'Create an instance of the main engine interface, IFlix
Dim flix
Try
flix = New Flix
Catch e As COMException
PrintStackTrace(Nothing,e)
End Try
'enable logging, 0=none(disable), 1=info, 2=error(asserts), 3=debug, 4=heavy
'Try
' flix.setLogLevel(3)
' flix.setLogPath("\cli_encode_vbnet.log")
'Catch e As COMException
' PrintStackTrace(flix,e)
'End Try
'Print some library information
Try
Console.WriteLine("Flix Engine Com Library. Flix Engine v" & _
flix.version & " COM v" & flix.com_version)
Console.WriteLine(flix.copyright)
Console.WriteLine()
Catch e As COMException
PrintStackTrace(flix,e)
End Try
If (System.Environment.GetCommandLineArgs.GetLength(0) < 3) Then
Console.Error.WriteLine("usage: cli_encode_vbnet.exe <infile> <outfile>")
Environment.Exit(1)
End If
'Set the source file
Try
Console.WriteLine("Input File : " & _
System.Environment.GetCommandLineArgs(1))
flix.setInputFile(System.Environment.GetCommandLineArgs(1))
Catch e As COMException
PrintStackTrace(flix,e)
End Try
'Retrieve the video options interface, IVideoOptions
Try
Dim vidopts As IVideoOptions
vidopts = flix.videoOptions
'Print input file information
Console.WriteLine("Width: ".PadLeft(24) & vidopts.getSourceWidth)
Console.WriteLine("Height: ".PadLeft(24) & vidopts.getSourceHeight)
Console.WriteLine("Duration: ".PadLeft(24) & flix.getSourceDuration & "ms")
Catch e As COMException
PrintStackTrace(flix,e)
End Try
'Set the destination file
Try
Console.WriteLine("Output File : " & _
System.Environment.GetCommandLineArgs(2))
flix.setOutputFile(System.Environment.GetCommandLineArgs(2))
Catch e As COMException
PrintStackTrace(flix,e)
End Try
'Options may be set and codecs/filters/muxers may be added prior to encode
'Add the scale filter
'Try
' Dim scaleFilter As IFlixPlgn
' scaleFilter = flix.addFilter(flix.FE2_FILTER_SCALE)
' scaleFilter.setParam(flix.FE2_SCALE_WIDTH, 240)
' scaleFilter.setParam(flix.FE2_SCALE_HEIGHT, 160)
'Catch e As COMException
' PrintStackTrace(flix,e)
'End Try
'Add the vp6 codec. Though it is the default,
'you must add it in order to modify its settings.
'Try
' Dim vp6Codec As IFlixPlgn
' vp6Codec = flix.addCodec(flix.FE2_CODEC_VP6)
' vp6Codec.setParam(flix.FE2_VP6_RC_MODE, _
' flixengine_com.FE2_VideoBitrateControls.VBR_1PASSControl)
'Catch e As COMException
' PrintStackTrace(flix,e)
'End Try
'Use the FLV muxer (default)
'Try
' Dim muxer As IFlixPlgn
' muxer = flix.addMuxer(flix.FE2_MUXER_FLV)
'Catch e As COMException
' PrintStackTrace(flix,e)
'End Try
'Start the encode
Try
flix.encode()
'Retrieve the encoding status interface, IEncodingStatus
Dim encStatus As IEncodingStatus
encStatus = flix.encodingStatus
Console.WriteLine()
Dim isRunning As Integer
Do
System.Threading.Thread.Sleep(500)
isRunning = flix.isEncoderRunning
Console.Write(vbCr & "Encoding..." & _
encStatus.percentComplete.ToString.PadLeft(3) & "% ")
Loop Until (isRunning = 0)
Catch e As COMException
PrintStackTrace(flix,e)
End Try
Console.WriteLine("Done!")
PrintEncoderStatus(flix)
'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.
'By explicitly defining a WeakReference and removing the strong
'referenece to the flix object we are guaranteeing that it will
'not survive the garbage collection.
Dim wkref = New WeakReference(flix)
flix = Nothing
System.GC.Collect(System.GC.GetGeneration(wkref))
System.GC.WaitForPendingFinalizers()
End Sub
Sub PrintEncoderStatus(ByVal flix As IFlix)
Console.WriteLine()
Console.WriteLine("Encoder Status")
Try
Console.WriteLine(" flix.getEncoderState: " & flix.getEncoderState)
Dim flixerr As FE2_errno
Dim syserr As Integer
flix.errno_(flixerr, syserr)
Console.WriteLine(" flix.errno_: flixerrno:" & _
flixerr & " syserrno:" & syserr)
Catch e As COMException
PrintStackTrace(Nothing,e)
End Try
End Sub
End Module