VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsTitleVideoInfo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' -------------------------------------------------------------------------------
'
'   AVStoDVD - by MrC
'   File: clsTitleVideoInfo.cls
'   Purpose: Class that handle Title Info properties
'   Requires: clsMediaInfo.cls, modStr.bas
'
' -------------------------------------------------------------------------------


Option Explicit
Option Compare Binary
Option Base 0

Public Enum DVD_Video_Compl
    Not_Video_Compl
    PAL_Full_D1
    PAL_Half_D1
    PAL_VCD
    NTSC_Full_D1
    NTSC_Half_D1
    NTSC_VCD
End Enum

Private VideoPathname As String
Private VideoID As String
Private VideoStreamOrder As String
Private VideoTime As String
Private VideoCompression As String
Private VideoBitRateMode As String
Private VideoAvgBitRate As String
Private VideoMinBitRate As String
Private VideoMaxBitRate As String
Private VideoWidth As String
Private VideoHeight As String
Private VideoDAR As String
Private VideoPAR As String
Private VideoFAR As String
Private VideoFrameRateMode As String
Private VideoFPS As String
Private VideoFrameCount As String
Private VideoScanType As String
Private VideoScanOrder As String
Private VideoColorSpace As String
Private VideoColorCoefficients As String

Public Function Initialize(SourceMediaInfo As clsMediaInfo) As Boolean

    Dim aStream
    
    With SourceMediaInfo
        VideoPathname = .PathName
        VideoID = .VideoID
        If IsNumeric(.VideoStreamOrder) = True Then
            VideoStreamOrder = .VideoStreamOrder
        ElseIf InStr(1, .VideoStreamOrder, "-") <> 0 Then
            aStream = Split(.VideoStreamOrder, "-")
            If IsNumeric(aStream(UBound(aStream))) = True Then
                VideoStreamOrder = aStream(UBound(aStream))
            End If
        End If
        VideoTime = .Time
        VideoCompression = .VideoCompression
        VideoBitRateMode = .VideoBitRateMode
        VideoAvgBitRate = .VideoAvgBitRate
        VideoMinBitRate = .VideoMinBitRate
        VideoMaxBitRate = .VideoMaxBitRate
        VideoWidth = .VideoWidth
        VideoHeight = .VideoHeight
        VideoDAR = .VideoDAR
        VideoPAR = .VideoPAR
        VideoFAR = .VideoFAR
        VideoFrameRateMode = .VideoFrameRateMode
        'VideoFrameRateMode = "VFR"
        VideoFPS = CStr(Replace(Round(Val(.VideoFPS), 3), ",", "."))
        VideoFrameCount = .VideoFrameCount
        VideoScanType = .VideoScanType
        VideoScanOrder = .VideoScanOrder
        VideoColorSpace = .VideoColorSpace
        VideoColorCoefficients = .VideoColorCoefficients
    End With
    Initialize = CBool(Len(VideoCompression))

End Function

Public Property Get ID() As String

    'Dim aID
    
    'aID = Split(VideoID, "-")
    'If UBound(aID) > 0 Then
    '    ID = aID(UBound(aID))
    'Else
        ID = VideoID
    'End If

End Property
    
Public Property Let ID(value As String)

    VideoID = value
    
End Property
    
Public Property Get StreamOrder() As String

    StreamOrder = VideoStreamOrder

End Property
    
Public Property Let StreamOrder(value As String)

    VideoStreamOrder = value
    
End Property

Public Property Get Time() As String

    Time = VideoTime

End Property
    
Public Property Let Time(value As String)

    VideoTime = value
    
End Property
    
Public Property Get Compression() As String

    Compression = VideoCompression

End Property
    
Public Property Let Compression(value As String)

    VideoCompression = value
    
End Property

Public Property Get BitRateMode() As String

    BitRateMode = VideoBitRateMode

End Property
    
Public Property Let BitRateMode(value As String)

    VideoBitRateMode = value
    
End Property

Public Property Get AvgBitRate() As String

    AvgBitRate = VideoAvgBitRate

End Property
    
Public Property Let AvgBitRate(value As String)

    VideoAvgBitRate = value
    
End Property

Public Property Get MinBitRate() As String

    MinBitRate = VideoMinBitRate

End Property
    
Public Property Let MinBitRate(value As String)

    VideoMinBitRate = value
    
End Property
    
Public Property Get MaxBitRate() As String

    MaxBitRate = VideoMaxBitRate

End Property
    
Public Property Let MaxBitRate(value As String)

    VideoMaxBitRate = value
    
End Property
    
Public Property Get Width() As String

    Width = VideoWidth

End Property
    
Public Property Let Width(value As String)

    VideoWidth = value
    
End Property
    
Public Property Get Height() As String

    Height = VideoHeight

End Property
    
Public Property Let Height(value As String)

    VideoHeight = value
    
End Property
    
Public Property Get DAR() As String

    DAR = VideoDAR

End Property
    
Public Property Let DAR(value As String)

    VideoDAR = value
    
End Property
    
Public Property Get PAR() As String

    PAR = VideoPAR

End Property
    
Public Property Let PAR(value As String)

    VideoPAR = value
    
End Property
    
Public Property Get FAR() As String

    FAR = VideoFAR

End Property
    
Public Property Let FAR(value As String)

    VideoFAR = value
    
End Property
    
Public Property Get FrameRateMode() As String

    FrameRateMode = VideoFrameRateMode

End Property
    
Public Property Let FrameRateMode(value As String)

    VideoFrameRateMode = value
    
End Property
    
Public Property Get FPS() As String

    FPS = VideoFPS

End Property
    
Public Property Let FPS(value As String)

    VideoFPS = value
    
End Property
    
Public Property Get FrameCount() As String

    FrameCount = VideoFrameCount

End Property
    
Public Property Let FrameCount(value As String)

    VideoFrameCount = value
    
End Property
    
Public Property Get ScanType() As String

    ScanType = VideoScanType

End Property
    
Public Property Let ScanType(value As String)

    VideoScanType = value
    
End Property
    
Public Property Get ScanOrder() As String

    ScanOrder = VideoScanOrder

End Property
    
Public Property Let ScanOrder(value As String)

    VideoScanOrder = value
    
End Property

Public Property Get ColorSpace() As String

    ColorSpace = VideoColorSpace

End Property
    
Public Property Let ColorSpace(value As String)

    VideoColorSpace = value
    
End Property

Public Property Get ColorCoefficients() As String

    ColorCoefficients = VideoColorCoefficients

End Property
    
Public Property Let ColorCoefficients(value As String)

    VideoColorCoefficients = value
    
End Property

Public Property Get Interlaced() As Boolean

    Select Case UCase(VideoScanType)
    Case "INTERLACED", "MBAFF", "PAFF"
        Interlaced = True
    Case Else
        Interlaced = False
    End Select

End Property

Public Property Get DVDCompliant() As DVD_Video_Compl

    Dim TentativeVideoStandard As Byte    ' 0->None 1->PAL 2->NTSC
    
    If InStr(1, VideoCompression, "MPEG-2 Video") <> 0 Then
        If VideoDAR = "1.333" Or VideoDAR = "1.778" Then
            Select Case Val(VideoFPS)
            Case 24
                If LCase(VideoScanOrder) = "2:2:2:2:2:2:2:2:2:2:2:3 pulldown" Then TentativeVideoStandard = 1
            Case 25
                TentativeVideoStandard = 1
            Case 23.976
                If LCase(VideoScanOrder) = "2:3 pulldown" Then TentativeVideoStandard = 2
            Case 29.97
                TentativeVideoStandard = 2
            End Select
            If TentativeVideoStandard = 1 Then
                If Val(VideoHeight) = 576 Then
                    If Val(VideoWidth) = 720 Or Val(VideoWidth) = 704 Then
                        DVDCompliant = PAL_Full_D1
                    ElseIf Val(VideoWidth) = 352 Then
                        DVDCompliant = PAL_Half_D1
                    End If
                ElseIf Val(VideoHeight) = 288 Then
                    If Val(VideoWidth) = 352 Then
                        DVDCompliant = PAL_VCD
                    End If
                End If
            ElseIf TentativeVideoStandard = 2 Then
                If Val(VideoHeight) = 480 Then
                    If Val(VideoWidth) = 720 Or Val(VideoWidth) = 704 Then
                        DVDCompliant = NTSC_Full_D1
                    ElseIf Val(VideoWidth) = 352 Then
                        DVDCompliant = NTSC_Half_D1
                    End If
                ElseIf Val(VideoHeight) = 240 Then
                    If Val(VideoWidth) = 352 Then
                        DVDCompliant = NTSC_VCD
                    End If
                End If
            End If
            If Val(VideoAvgBitRate) / 1000 > 9500 Then
                DVDCompliant = Not_Video_Compl
            ElseIf Val(VideoMaxBitRate) / 1000 > 10000 Then
                DVDCompliant = Not_Video_Compl
            End If
        End If
    End If
    
End Property


Public Property Get Extension() As String

    Dim sCompr As String
    Dim jj As Integer
    Dim bFlag As Boolean
    
        sCompr = UCase(VideoCompression)
        If InStr(1, sCompr, "MPEG-1") <> 0 Then
            Extension = "m1v"
        ElseIf InStr(1, sCompr, "MPEG-2") <> 0 Then
            Extension = "m2v"
        ElseIf InStr(1, sCompr, "AVC") <> 0 Then
            Extension = "m4v"
        ElseIf InStr(1, sCompr, "DIVX") <> 0 Then
            Extension = "avi"
        ElseIf InStr(1, sCompr, "XVID") <> 0 Then
            Extension = "avi"
        ElseIf sCompr = "DV" Then
            Extension = "avi"
        ElseIf InStr(1, sCompr, "WMV") <> 0 Then
            Extension = "wmv"
        ElseIf InStr(1, sCompr, "VC-1") <> 0 Then
            Extension = "wmv"
        Else
            Do
                jj = jj + 1
                Extension = Right(VideoPathname, jj)
                If Left(Extension, 1) = "." Then
                    Extension = Right(Extension, Len(Extension) - 1)
                    bFlag = True
                End If
            Loop Until bFlag = True
        End If

End Function

Public Property Get Summary() As String

    Dim sDAR As String
    
    If VideoCompression <> "" Then
        Select Case Round(Val(VideoDAR), 3)
        Case 1
            sDAR = "1:1"
        Case 1.25
            sDAR = "5:4"
        Case 1.333
            sDAR = "4:3"
        Case 1.5
            sDAR = "3:2"
        Case 1.778
            sDAR = "16:9"
        Case Else
            sDAR = Round(Val(VideoDAR), 3)
        End Select
        Summary = VideoCompression & " - " & _
                  Int(Val(VideoAvgBitRate) / 1000) & " kbps - " & _
                  VideoWidth & "x" & VideoHeight & _
                  " - DAR " & sDAR & " - " & _
                  Round(Val(VideoFPS), 3) & " fps" & IIf(VideoFrameRateMode <> "", " (" & VideoFrameRateMode & ")", "") & IIf(VideoScanType <> "", " - " & VideoScanType, "") & IIf(VideoScanOrder <> "", " (" & VideoScanOrder & ")", "") & " - " & _
                  VisualTime(Val(VideoTime) / 1000) & " - " & _
                  VideoFrameCount & " frames"
    End If

End Property

Public Property Get SummaryLong() As String

    If VideoCompression <> "" Then
        If VideoID <> "" Then
            SummaryLong = "Track ID: " & VideoID & vbCrLf & _
                          "Stream Order: " & VideoStreamOrder & vbCrLf
        End If
        SummaryLong = SummaryLong & _
                      "Time: " & VisualTime(Val(VideoTime) / 1000, True, True) & vbCrLf & _
                      "Compression: " & VideoCompression & vbCrLf & _
                      "BitRate Mode: " & VideoBitRateMode & vbCrLf & _
                      "Avg BitRate: " & IIf(VideoAvgBitRate = "", "", Round(Val(VideoAvgBitRate) / 1000) & " kbps") & vbCrLf & _
                      "Min BitRate: " & IIf(VideoMinBitRate = "", "", Round(Val(VideoMinBitRate) / 1000) & " kbps") & vbCrLf & _
                      "Max BitRate: " & IIf(VideoMaxBitRate = "", "", Round(Val(VideoMaxBitRate) / 1000) & " kbps") & vbCrLf & _
                      "Resolution: " & VideoWidth & "x" & VideoHeight & vbCrLf & _
                      "Display AspectRatio: " & Round(Val(VideoDAR), 3) & vbCrLf & _
                      "Pixel AspectRatio: " & Round(Val(VideoPAR), 3) & vbCrLf & _
                      "Frame AspectRatio: " & Round(Val(VideoFAR), 3) & vbCrLf & _
                      "FrameRate Mode: " & VideoFrameRateMode & vbCrLf & _
                      "FrameRate: " & Round(Val(VideoFPS), 3) & " fps" & vbCrLf & _
                      "Frame Count: " & VideoFrameCount & vbCrLf & _
                      "Scan Type: " & VideoScanType & vbCrLf & _
                      "Interlaced: " & IIf(Interlaced = True, "Yes", "No") & vbCrLf & _
                      "Field Order: " & VideoScanOrder & vbCrLf & _
                      "Color Space: " & VideoColorSpace & vbCrLf & _
                      "Color Coefficients: " & VideoColorCoefficients & vbCrLf & _
                      "DVD Compliance: " & DVDCompliant
    End If

End Property

