'Option Strict Off
'Option Explicit Off

'Imports System.Threading
'Imports System.Runtime.InteropServices
'Imports System.Runtime.CompilerServices
'Imports System.Reflection

'Imports Stax.UI

'<Serializable()> _
'Public Class WMVEncoder
'    Inherits VideoEncoder

'    Private LastLog As String

'    Public Sub New()
'        Name = "WMV"
'        Muxer = New EncoderMuxer("WMV", StaxRip.StreamType.WMV, StaxRip.StreamType.AC3 Or StaxRip.StreamType.MP3CBR Or StaxRip.StreamType.MP3VBR Or StaxRip.StreamType.MPA Or StaxRip.StreamType.MP2 Or StaxRip.StreamType.WMV, GetType(WMVEncoder))
'        StreamType = StaxRip.StreamType.WMV
'    End Sub

'    Public Overrides Sub Encode()
'        WMENC_ENCODER_STOPPED = 5
'        WMENC_AUDIO  = 1
'        WMENC_VIDEO = 2

'        Dim encoder = GetObject("WMEncEng.WMEncoder")
'        Dim profile = GetObject("WMEncEng.WMEncProfile2")

'        Dim sourceGroupCol = encoder.SourceGroupCollection
'        Dim sourceGroup = sourceGroupCol.Add("g1")
'        Dim videoSource = sourceGroup.AddSource(WMENC_VIDEO)

'        videoSource.SetInput(p.TargetAviSynthDocument.Path)
'        videoSource.PreProcessPass = 1

'        If TypeOf p.VideoEncoder.Muxer Is EncoderMuxer Then
'            If p.Audio0.File <> "" AndAlso Muxer.IsStreamSupported(p.Audio0.Profile.StreamType) Then
'                Dim audioSource = sourceGroup.AddSource(WMENC_AUDIO)
'                audioSource.SetInput(p.Audio0.File)
'                audioSource.PreProcessPass = 1
'            End If

'            If p.Audio1.File <> "" AndAlso Muxer.IsStreamSupported(p.Audio1.Profile.StreamType) Then
'                Dim audioSource = sourceGroup.AddSource(WMENC_AUDIO)
'                audioSource.SetInput(p.Audio1.File)
'                audioSource.PreProcessPass = 1
'            End If
'        End If

'        encoder.File.LocalFileName = OutputPath
'        profile.LoadFromFile("C:\Dokumente und Einstellungen\Frank\Desktop\test.prx")

'        Dim bitrate As Integer = 1000
'        Dim framerate As Double = 25
'        Dim width As Integer = 384
'        Dim height As Integer = 288

'        Dim a

'        For i As Integer = 0 To profile.AudienceCount - 1
'            a = profile.Audience(i)
'            a.VideoBitrate(0) = CInt(bitrate * 1000 - a.AudioBitrate(0))
'            a.VideoFPS(0) = CInt(framerate * 1000)
'            a.VideoHeight(0) = 288
'            a.VideoWidth(0) = height
'        Next

'        SetProperty("Profile", sourceGroup, profile)

'        encoder.AutoStop = True
'        encoder.PrepareToEncode(True)
'        encoder.Start()

'        Log.AddLine("Starting WMV Encoding")

'        Dim stats = encoder.Statistics
'        Dim fileStats = stats.FileArchiveStats

'        Do Until encoder.RunState = WMENC_ENCODER_STOPPED
'            WriteLog( _
'                "Encoded Size: " + CInt((fileStats.FileSize * 10) / 1024).ToString() + " MB" + vbCrLf + _
'                "Encoded Time: " + New TimeSpan(0, 0, CInt(fileStats.FileDuration * 10)).ToString() + vbCrLf + _
'                "Elapsed Time: " + New TimeSpan(0, 0, CInt(stats.EncodingTime * 10)).ToString() + vbCrLf)

'            Thread.Sleep(500)
'        Loop
'    End Sub

'    Public Sub WriteLog(ByVal value As String)
'        If Log.Text.Contains(value) Then
'            Exit Sub
'        End If

'        If Not LastLog Is Nothing Then
'            If Log.Text.Contains(LastLog) Then
'                Log.Text = Log.Text.Replace(LastLog, "")
'            End If
'        End If

'        Log.Text += value
'        LastLog = value
'    End Sub

'    Public Overrides ReadOnly Property Extension() As String
'        Get
'            Return ".wmv"
'        End Get
'    End Property

'    Public Overrides Function GetMenu() As List(Of OptionListBoxItem)
'        Dim ret As New List(Of OptionListBoxItem)

'        Dim muxConfig As New OptionListBoxItem
'        muxConfig.Text = "Muxer"
'        muxConfig.Description = "Opens the Muxer configuration dialog."
'        muxConfig.ClickSub = AddressOf OpenMuxerConfigDialog
'        ret.Add(muxConfig)

'        Return ret
'    End Function

'    Private Function GetObject(ByVal progID As Object) As Object
'        Return Activator.CreateInstance(Type.GetTypeFromProgID(progID))
'    End Function

'    Private Sub SetProperty(ByVal name As String, ByVal target As Object, ByVal value As Object)
'        target.GetType.InvokeMember("Profile", BindingFlags.SetProperty, Nothing, target, New Object() {value})
'    End Sub
'End Class