809
社区成员
发帖
与我相关
我的任务
分享
Private Type AVI_COMPRESS_OPTIONS
fccType As Long
fccHandler As Long
dwKeyFrameEvery As Long
dwQuality As Long
dwBytesPerSecond As Long
dwFlags As Long
lpFormat As Long
cbFormat As Long
lpParms As Long
cbParms As Long
dwInterleaveEvery As Long
End Type
Private Type WAVEHDR
lpData As Long
dwBufferLen As Long
dwBytesRec As Long
dwUser As Long
dwFlags As Long
dwLoops As Long
lpNext As Long
Reserved As Long
End Type
Private Type WAVEFORMATEX
wFormatTag As Integer '波形声音的格式,本人此处设置为WAVE_FORMAT_PCM
nChannels As Integer '通道数量,单声道为1,立体声为2
nSamplesPerSec As Long '样本采样率,对于 WAVE_FORMAT_PCM通常为8.0 kHz, 11.025 kHz, 22.05 kHz和44.1 kHz
nAvgBytesPerSec As Long ' for buffer estimation */
nBlockAlign As Integer 'block size of data
wBitsPerSample As Integer '//每个样本的BIT数目,一般为16
biSize As Integer '// 额外信息的大小,以字节为单位,添加在
End Type
Const WAVE_FORMAT_PCM = 1 '这一块的const 都是我写的
Const WHDR_BEGINLOOP = 4
Const WHDR_DONE = 1
Const WHDR_ENDLOOP = 8
Const WHDR_INQUEUE = &H10
Const WHDR_PREPARED = 2
Global Const AVIERR_OK As Long = 0&
Global Const OF_WRITE As Long = &H1
Global Const OF_CREATE As Long = &H1000
Global Const AVIIF_KEYFRAME As Long = &H10
Global Const DATARATE As Long = &H280
Global Const ICMF_CHOOSE_KEYFRAME As Long = &H1
Global Const ICMF_CHOOSE_DATARATE As Long = &H2
Dim res As Long, pfile As Long, ps As Long, psCompressed As Long, pOpts As Long
Dim ps2 As Long, psCompressed2 As Long, pOpts2 As Long '这一行是自己写的
Dim bmp As cDIB, strhdr As AVI_STREAM_INFO, BI As BITMAPINFOHEADER, opts As AVI_COMPRESS_OPTIONS, avifile As String
Dim wav As cWAV, WH As WAVEHDR, opts2 As AVI_COMPRESS_OPTIONS '这一行是自己写的
Dim strhdr2 As WAVEFORMATEX 'AVI_STREAM_INFO '
'转Integer数组到 byte数组用的
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
'转Integer数组到 byte数组用的
Public Function StartDecode(hwnd As Long, base As String, path As String, fps%) As Boolean
avifile = path: AVIFileInit: res = AVIFileOpen(pfile, path, OF_WRITE Or OF_CREATE, 0&)
If (res <> AVIERR_OK) Then
EndDecode
Exit Function
End If
Set bmp = New cDIB
If bmp.CreateFromFile(base) <> True Then
MsgBox "Could not load first bitmap file in list!", vbExclamation, App.title
EndDecode
Exit Function
End If
With strhdr
.fccType = mmioStringToFOURCC("vids", 0&)
.fccHandler = 0&
.dwScale = 1
.dwRate = Val(fps)
.dwSuggestedBufferSize = bmp.SizeImage
SetRect .rcFrame, 0, 0, bmp.Width, bmp.Height
End With
If strhdr.dwRate < 1 Then strhdr.dwRate = 1
If strhdr.dwRate > 30 Then strhdr.dwRate = 30
res = AVIFileCreateStream(pfile, ps, strhdr)
If (res <> AVIERR_OK) Then
EndDecode
Exit Function
End If
With strhdr2
.wFormatTag = 1
.nChannels = Val(2)
.wBitsPerSample = Val(16)
.nSamplesPerSec = Val(44100) '采样率
.nAvgBytesPerSec = Val(176400) 'WAVE声音中每秒的数据量 (CLng(cboSamplerate.Text) * (2 * (chkStereo.value + 1))) = 44100 * (2*(1+1))
.nBlockAlign = (10240) '数据块的对齐标志
.biSize = 14 '此结构的大小
End With 'SetFormat VarPtr(wfx), Len(wfx),"44.1 kHz 16 Bit Stereo", "PCM"
Dim strhdr3 As AVI_STREAM_INFO
With strhdr3
.fccType = mmioStringToFOURCC("auds", 0&)
.fccHandler = 1&
.dwScale = Val(10240)
.dwRate = Val(176400)
.dwSuggestedBufferSize = bmp.SizeImage
'SetRect .rcFrame, 0, 0, bmp.Width, bmp.Height
End With
' update recorded time
'lngMSEncoded = lngMSEncoded + ((lngLen / lngBytesPerSec) * 1000)
res = AVIFileCreateStream(pfile, ps2, strhdr3)
If (res <> AVIERR_OK) Then
EndDecode
Exit Function
End If
Dim b() As Byte, i As Long
' ReDim b(Len(strhdr2) * 2 - 1)
' For i = 0 To UBound(intSamples)
' CopyMemory b(i * 2), intSamples(i), ByVal 2 'LenB(intSamples(i))
' Next
res = AVIStreamSetFormat(ps2, 0, ByVal VarPtr(strhdr2), Len(strhdr2))
If (res <> AVIERR_OK) Then
EndDecode
Exit Function
End If
pOpts = VarPtr(opts)
res = AVISaveOptions(hwnd, ICMF_CHOOSE_KEYFRAME Or ICMF_CHOOSE_DATARATE, 1, ps, pOpts)
If res <> 1 Then
AVISaveOptionsFree 1, pOpts
EndDecode
Exit Function
End If
res = AVIMakeCompressedStream(psCompressed, ps, opts, 0&)
If res <> AVIERR_OK Then
EndDecode
Exit Function
End If
With BI
.biBitCount = bmp.BitCount
.biClrImportant = bmp.ClrImportant
.biClrUsed = bmp.ClrUsed
.biCompression = bmp.Compression
.biHeight = bmp.Height
.biWidth = bmp.Width
.biPlanes = bmp.Planes
.biSize = bmp.SizeInfoHeader
.biSizeImage = bmp.SizeImage
.biXPelsPerMeter = bmp.XPPM
.biYPelsPerMeter = bmp.YPPM
End With
res = AVIStreamSetFormat(psCompressed, 0, ByVal bmp.PointerToBitmapInfo, bmp.SizeBitmapInfo)
If (res <> AVIERR_OK) Then
EndDecode
Exit Function
End If
'Set wav = New cWAV
'If wav.CreateFromFile(App.path & "\t.wav") = True Then
'EndDecode
'Exit Function
'End If
'Dim mWFeX As WAVEFORMATEX
' .nBlockAlign = .nSamplesPerSec * .wBitsPerSample 'block size of data (_wfx.wBitsPerSample * _wfx.nChannels) >> 3;
' .nAvgBytesPerSec = .nBlockAlign * .nSamplesPerSec '/* for buffer estimation */ _wfx.nBlockAlign * _wfx.nSamplesPerSec;
' .cbSize = 0 '额外信息的大小,如果没有额外信息可为0'
StartDecode = 1
End Function
Public Sub Decode(ByVal Index As Integer, ByVal file As String)
bmp.CreateFromFile (file)
res = AVIStreamWrite(psCompressed, Index, 1, bmp.PointerToBits, bmp.SizeImage, AVIIF_KEYFRAME, ByVal 0&, ByVal 0&)
If res <> AVIERR_OK Then EndDecode
End Sub
Public Sub Decode2(ByVal Index As Integer, ii() As Integer) '我写的 录入音频
'Dim b() As Byte, i As Long
'Dim Buffer(3) As Byte
'a = Val(Text1) CopyMemory Buffer(0), a, 4
'For i = 0 To UBound(ii)
' b(i) = CByte(ii)
'Next
Dim b() As Byte
Dim i As Long
ReDim b((UBound(intSamples) + 1) * 2 - 1)
For i = 0 To UBound(intSamples)
CopyMemory b(i * 2), intSamples(i), ByVal 2 'LenB(intSamples(i))
Next
res = AVIStreamWrite(ps2, Index, 1, b, intSamplesSize, AVIIF_KEYFRAME, ByVal 0&, ByVal 0&) 'AVIIF_KEYFRAME AVIIF_DATARATE
If res <> AVIERR_OK Then EndDecode
End Sub