Verificar la Velocidad de Fotogramas en un Video
by Ciberwalter

06/Diciembre/2003 (publicado 07/Dic/2003)
Autor: Walter Martínez O. (Ciberwalter)
waltermilenium@hotmail.com
http://www.geocities.com/gnivel4


ESTE EJEMPLO ES TAN FÁCIL, que me da vergüenza pensar que estuve más de una semana craneando la idea. Al final resultó más fácil de lo esperado. Al ser código abierto pueden usarlo como quieran
por ejemplo en un programa que lea los subtítulos y los añada al video (yo hice uno muy básico pero efectivo quizá en un tiempo más lo publique)

Comenzamos con el Código:

' Comenzamos con el código para abrir el video y cargarlos
' a MediaPlayer1 y a MediaPlayer

Private Sub Command1_Click()

    On Error GoTo mnuFileOpenDialog_Click_Error
    Dim file As OPENFILENAME, sFile As String, sFileTitle As String, lResult As Long, iDelim As Integer

    file.lStructSize = Len(file)
    file.hwndOwner = Me.hWnd
    file.flags = OFN_HIDEREADONLY + OFN_PATHMUSTEXIST + OFN_FILEMUSTEXIST

    file.lpstrFile = "Video" & String$(250, 0)
    file.nMaxFile = 255

    file.lpstrFileTitle = String$(255, 0)
    file.nMaxFileTitle = 255

    file.lpstrInitialDir = App.Path

    file.lpstrFilter = "Videos" & Chr$(0) & "*.MPG;*.AVI;*.MPEG;*.DAT;*.ASF;*.WMV" & Chr$(0) & Chr$(0)
    file.nFilterIndex = 1

    file.lpstrTitle = "Abrir"

    lResult = GetOpenFileName(file)
    If lResult <> 0 Then
        iDelim = InStr(file.lpstrFileTitle, Chr$(0))
        If iDelim > 0 Then
            sFileTitle = Left$(file.lpstrFileTitle, iDelim - 1)
        End If
        iDelim = InStr(file.lpstrFile, Chr$(0))
        If iDelim > 0 Then
            sFile = Left$(file.lpstrFile, iDelim - 1)
        End If

        Text1 = sFile

        ' Carga el video seleccionado a los dos reproductores
        ' MediaPlayer1 y MediaPlayer2

        MediaPlayer1.FileName = sFile
        MediaPlayer2.FileName = sFile

        Timer1.Enabled = True

    End If

mnuFileOpenDialog_Click_Exit:
    Exit Sub

mnuFileOpenDialog_Click_Error:
    MsgBox "Error: " & Format$(Err) & " " & Error$, , "mnuFileOpenDialog_Click"
    Resume mnuFileOpenDialog_Click_Exit

End Sub

Private Sub Timer1_Timer()

    ' Y aquí está toda la mágia:
    ' MediaPlayer1 está en modo Tiempo (DisplayMode = mpTime)
    ' MediaPlayer2 está en modo Fotogramas (DisplayMode = mpFrames)
    ' Primero verificamos el 'SelectionEnd' de ambos.
    ' Player1 = MediaPlayer1.SelectionEnd
    ' Player2 = MediaPlayer2.SelectionEnd
    ' y hacemos la siguiente división Player1 / Player2
    ' el resultado será la Velocidad de los fotogramas

    If MediaPlayer1.CurrentPosition < 5 Then
        Player1 = MediaPlayer1.SelectionEnd
        Player2 = MediaPlayer2.SelectionEnd
        Total = Player2 / Player1
        ' le damos formato para que nos muestre sólo dos decimales
        Total = Format(Total, "##.##")
    End If

    If MediaPlayer1.CurrentPosition > 5 Then
        Timer1.Enabled = False
        MediaPlayer1.Stop()
        MediaPlayer2.Stop()
    End If
End Sub


 

Descargar el Código y el ejecutable ->  (Ciberwalter_FrameRate.zip - 64.1 Kb)


ir al índice