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

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

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

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

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

textual
Листинг программы
  1. Option Explicit
  2.  
  3. Private Const ACMDRIVERDETAILS_SHORTNAME_CHARS As Long = 32
  4. Private Const ACMDRIVERDETAILS_LONGNAME_CHARS As Long = 128
  5. Private Const ACMDRIVERDETAILS_COPYRIGHT_CHARS As Long = 80
  6. Private Const ACMDRIVERDETAILS_LICENSING_CHARS As Long = 128
  7. Private Const ACMDRIVERDETAILS_FEATURES_CHARS As Long = 512
  8.  
  9. Private Type RECT
  10.     left                    As Long
  11.     top                     As Long
  12.     right                   As Long
  13.     bottom                  As Long
  14. End Type
  15. Private Type AVI_STREAM_INFO
  16.     fccType                 As Long
  17.     fccHandler              As Long
  18.     dwFlags                 As Long
  19.     dwCaps                  As Long
  20.     wPriority               As Integer
  21.     wLanguage               As Integer
  22.     dwScale                 As Long
  23.     dwRate                  As Long
  24.     dwStart                 As Long
  25.     dwLength                As Long
  26.     dwInitialFrames         As Long
  27.     dwSuggestedBufferSize   As Long
  28.     dwQuality               As Long
  29.     dwSampleSize            As Long
  30.     rcFrame                 As RECT
  31.     dwEditCount             As Long
  32.     dwFormatChangeCount     As Long
  33.     szName                  As String * 64
  34. End Type
  35. Private Type WAVEFORMATEX
  36.     wFormatTag              As Integer
  37.     nChannels               As Integer
  38.     nSamplesPerSec          As Long
  39.     nAvgBytesPerSec         As Long
  40.     nBlockAlign             As Integer
  41.     wBitsPerSample          As Integer
  42.     cbSize                  As Integer
  43. End Type
  44.  
  45. Private Type ACMDRIVERDETAILSA
  46.     cbStruct                As Long
  47.     fccType                 As String * 4
  48.     fccComp                 As String * 4
  49.     wMid                    As Integer
  50.     wPid                    As Integer
  51.     vdwACM                  As Long
  52.     vdwDriver               As Long
  53.     fdwSupport              As Long
  54.     cFormatTags             As Long
  55.     cFilterTags             As Long
  56.     hIcon                   As Long
  57.     szShortName             As String * ACMDRIVERDETAILS_SHORTNAME_CHARS
  58.     szLongName              As String * ACMDRIVERDETAILS_LONGNAME_CHARS
  59.     szCopyright             As String * ACMDRIVERDETAILS_COPYRIGHT_CHARS
  60.     szLicensing             As String * ACMDRIVERDETAILS_LICENSING_CHARS
  61.     szFeatures              As String * ACMDRIVERDETAILS_FEATURES_CHARS
  62. End Type
  63.  
  64. 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
  65. Private Declare Function AVIStreamRelease Lib "avifil32.dll" (ByVal pAVIStream As Long) As Long
  66. Private Declare Function AVIStreamInfo Lib "avifil32.dll" (ByVal pAVIStream As Long, pAVIStreamInfo As AVI_STREAM_INFO, ByVal lSize As Long) As Long
  67. Private Declare Function AVIStreamReadFormat Lib "avifil32.dll" (ByVal pAVIStream As Long, ByVal lPos As Long, lpFormat As Any, ByRef lpcbFormat As Long) As Long
  68. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  69. 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
  70. Private Declare Function acmStreamClose Lib "msacm32" (ByVal has As Long, ByVal fdwClose As Long) As Long
  71. Private Declare Function acmDriverID Lib "msacm32.dll" (ByVal hao As Long, phadid As Long, ByVal fdwDriverID As Long) As Long
  72. Private Declare Function acmDriverDetails Lib "msacm32.dll" Alias "acmDriverDetailsA" (ByVal hadid As Long, padd As ACMDRIVERDETAILSA, ByVal fdwDetails As Long) As Long
  73. Private Declare Sub AVIFileInit Lib "avifil32.dll" ()
  74. Private Declare Sub AVIFileExit Lib "avifil32.dll" ()
  75.  
  76. Private Const ACM_STREAMOPENF_NONREALTIME       As Integer = &H4
  77. Private Const streamtypeAUDIO                   As Long = 1935963489
  78.  
  79. Private Sub Form_Load()
  80.     GetAudioStreamInfo "D:\Òîëèê\Ôèëüìû\total recall.avi"
  81. End Sub
  82.  
  83. Private Function GetAudioStreamInfo(FileName As String) As Boolean
  84.     Dim aud As Long, si As AVI_STREAM_INFO, buf() As Byte, wf As WAVEFORMATEX, l As Long
  85.     Dim df As WAVEFORMATEX, has As Long, did As Long, dd As ACMDRIVERDETAILSA
  86.     Dim comp As String, bitrate As Long, sr As Long, ch As Long, bps As Integer
  87.    
  88.     AVIFileInit
  89.    
  90.     If AVIStreamOpenFromFile(aud, StrPtr(FileName), streamtypeAUDIO, 0, 0, ByVal 0&) = 0 Then
  91.         AVIStreamInfo aud, si, Len(si)
  92.         AVIStreamReadFormat aud, 0, ByVal 0&, l
  93.         ReDim buf(l - 1)
  94.         AVIStreamReadFormat aud, 0, buf(0), l
  95.         CopyMemory df, buf(0), IIf(Len(df) < l, Len(df), l)
  96.         sr = df.nSamplesPerSec
  97.         ch = df.nChannels
  98.         If df.wFormatTag <> 1 Then
  99.             bitrate = Fix(0.5 + df.nAvgBytesPerSec * (1# / 1000#)) * 8
  100.             df.cbSize = 0
  101.             df.wFormatTag = 1
  102.             df.wBitsPerSample = 16
  103.             df.nBlockAlign = df.nChannels * 2
  104.             df.nAvgBytesPerSec = df.nSamplesPerSec * df.nBlockAlign
  105.             If acmStreamOpen(has, 0, buf(0), df, 0, 0, 0, ACM_STREAMOPENF_NONREALTIME) = 0 Then
  106.                 acmDriverID has, did, 0
  107.                 dd.cbStruct = Len(dd)
  108.                 acmDriverDetails did, dd, 0
  109.                 acmStreamClose has, 0
  110.             End If
  111.             comp = RTrim(dd.szLongName)
  112.             Debug.Print "Bitrate:", bitrate; "kb/s"
  113.         Else
  114.             Debug.Print "Bits:", df.wBitsPerSample
  115.             comp = "WAVE PCM"
  116.         End If
  117.  
  118.         Debug.Print "Channels:", ch
  119.         Debug.Print "Compression:", comp
  120.         Debug.Print "Sample rate:", sr; "Hz"
  121.         Debug.Print "Duration:", HMS(si.dwLength * (si.dwScale / si.dwRate))
  122.     End If
  123.    
  124.     AVIStreamRelease aud
  125.     AVIFileExit
  126. End Function
  127. Private Function HMS(sec As Single) As String
  128.     HMS = Fix(sec) \ 3600 & ":" & _
  129.         (Fix(sec) Mod 3600) \ 60 & ":" & _
  130.         (Fix(sec) Mod 60) & "." & _
  131.         Format$((sec - Fix(sec)) * 100, "00")
  132. End Function

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


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

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

8   голосов , оценка 3.625 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы