Получить информацию о аудиодорожках указанного видеофайла - VB

Узнай цену своей работы

Формулировка задачи:

Получить информацию о аудио дорожках указанного видеофайла На WSH

Решение задачи: «Получить информацию о аудиодорожках указанного видеофайла»

textual
Листинг программы
Option Explicit
 
Private Const ACMDRIVERDETAILS_SHORTNAME_CHARS As Long = 32
Private Const ACMDRIVERDETAILS_LONGNAME_CHARS As Long = 128
Private Const ACMDRIVERDETAILS_COPYRIGHT_CHARS As Long = 80
Private Const ACMDRIVERDETAILS_LICENSING_CHARS As Long = 128
Private Const ACMDRIVERDETAILS_FEATURES_CHARS As Long = 512
 
Private Type RECT
    left                    As Long
    top                     As Long
    right                   As Long
    bottom                  As Long
End Type
Private Type AVI_STREAM_INFO
    fccType                 As Long
    fccHandler              As Long
    dwFlags                 As Long
    dwCaps                  As Long
    wPriority               As Integer
    wLanguage               As Integer
    dwScale                 As Long
    dwRate                  As Long
    dwStart                 As Long
    dwLength                As Long
    dwInitialFrames         As Long
    dwSuggestedBufferSize   As Long
    dwQuality               As Long
    dwSampleSize            As Long
    rcFrame                 As RECT
    dwEditCount             As Long
    dwFormatChangeCount     As Long
    szName                  As String * 64
End Type
Private Type WAVEFORMATEX
    wFormatTag              As Integer
    nChannels               As Integer
    nSamplesPerSec          As Long
    nAvgBytesPerSec         As Long
    nBlockAlign             As Integer
    wBitsPerSample          As Integer
    cbSize                  As Integer
End Type
 
Private Type ACMDRIVERDETAILSA
    cbStruct                As Long
    fccType                 As String * 4
    fccComp                 As String * 4
    wMid                    As Integer
    wPid                    As Integer
    vdwACM                  As Long
    vdwDriver               As Long
    fdwSupport              As Long
    cFormatTags             As Long
    cFilterTags             As Long
    hIcon                   As Long
    szShortName             As String * ACMDRIVERDETAILS_SHORTNAME_CHARS
    szLongName              As String * ACMDRIVERDETAILS_LONGNAME_CHARS
    szCopyright             As String * ACMDRIVERDETAILS_COPYRIGHT_CHARS
    szLicensing             As String * ACMDRIVERDETAILS_LICENSING_CHARS
    szFeatures              As String * ACMDRIVERDETAILS_FEATURES_CHARS
End Type
 
Private Declare Function AVIStreamOpenFromFile Lib "avifil32.dll" Alias "AVIStreamOpenFromFileW" (ppavi As Long, ByVal szFile As Long, ByVal fccType As Long, ByVal lParam As Long, ByVal mode As Long, pclsidHandler As Any) As Long
Private Declare Function AVIStreamRelease Lib "avifil32.dll" (ByVal pAVIStream As Long) As Long
Private Declare Function AVIStreamInfo Lib "avifil32.dll" (ByVal pAVIStream As Long, pAVIStreamInfo As AVI_STREAM_INFO, ByVal lSize As Long) As Long
Private Declare Function AVIStreamReadFormat Lib "avifil32.dll" (ByVal pAVIStream As Long, ByVal lPos As Long, lpFormat As Any, ByRef lpcbFormat As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function acmStreamOpen Lib "msacm32" (phas As Long, ByVal had As Long, pwfxSrc As Any, pwfxDst As Any, ByVal pwfltr As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal fdwOpen As Long) As Long
Private Declare Function acmStreamClose Lib "msacm32" (ByVal has As Long, ByVal fdwClose As Long) As Long
Private Declare Function acmDriverID Lib "msacm32.dll" (ByVal hao As Long, phadid As Long, ByVal fdwDriverID As Long) As Long
Private Declare Function acmDriverDetails Lib "msacm32.dll" Alias "acmDriverDetailsA" (ByVal hadid As Long, padd As ACMDRIVERDETAILSA, ByVal fdwDetails As Long) As Long
Private Declare Sub AVIFileInit Lib "avifil32.dll" ()
Private Declare Sub AVIFileExit Lib "avifil32.dll" ()
 
Private Const ACM_STREAMOPENF_NONREALTIME       As Integer = &H4
Private Const streamtypeAUDIO                   As Long = 1935963489
 
Private Sub Form_Load()
    GetAudioStreamInfo "D:\Òîëèê\Ôèëüìû\total recall.avi"
End Sub
 
Private Function GetAudioStreamInfo(FileName As String) As Boolean
    Dim aud As Long, si As AVI_STREAM_INFO, buf() As Byte, wf As WAVEFORMATEX, l As Long
    Dim df As WAVEFORMATEX, has As Long, did As Long, dd As ACMDRIVERDETAILSA
    Dim comp As String, bitrate As Long, sr As Long, ch As Long, bps As Integer
    
    AVIFileInit
    
    If AVIStreamOpenFromFile(aud, StrPtr(FileName), streamtypeAUDIO, 0, 0, ByVal 0&) = 0 Then
        AVIStreamInfo aud, si, Len(si)
        AVIStreamReadFormat aud, 0, ByVal 0&, l
        ReDim buf(l - 1)
        AVIStreamReadFormat aud, 0, buf(0), l
        CopyMemory df, buf(0), IIf(Len(df) < l, Len(df), l)
        sr = df.nSamplesPerSec
        ch = df.nChannels
        If df.wFormatTag <> 1 Then
            bitrate = Fix(0.5 + df.nAvgBytesPerSec * (1# / 1000#)) * 8
            df.cbSize = 0
            df.wFormatTag = 1
            df.wBitsPerSample = 16
            df.nBlockAlign = df.nChannels * 2
            df.nAvgBytesPerSec = df.nSamplesPerSec * df.nBlockAlign
            If acmStreamOpen(has, 0, buf(0), df, 0, 0, 0, ACM_STREAMOPENF_NONREALTIME) = 0 Then
                acmDriverID has, did, 0
                dd.cbStruct = Len(dd)
                acmDriverDetails did, dd, 0
                acmStreamClose has, 0
            End If
            comp = RTrim(dd.szLongName)
            Debug.Print "Bitrate:", bitrate; "kb/s"
        Else
            Debug.Print "Bits:", df.wBitsPerSample
            comp = "WAVE PCM"
        End If
 
        Debug.Print "Channels:", ch
        Debug.Print "Compression:", comp
        Debug.Print "Sample rate:", sr; "Hz"
        Debug.Print "Duration:", HMS(si.dwLength * (si.dwScale / si.dwRate))
    End If
    
    AVIStreamRelease aud
    AVIFileExit
End Function
Private Function HMS(sec As Single) As String
    HMS = Fix(sec) \ 3600 & ":" & _
        (Fix(sec) Mod 3600) \ 60 & ":" & _
        (Fix(sec) Mod 60) & "." & _
        Format$((sec - Fix(sec)) * 100, "00")
End Function

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 3.625 из 5
Похожие ответы