我要瘋掉了.好幾天都沒弄好.是哪里錯了.
一直回傳的都是avierr_ok,一到寫入時就出現-2147205014 錯誤.圖片壓縮時沒問題,如果有avi視頻及音頻處理經驗的可以聯系我Q452781589.實時聊天音頻資料保存為avi(類似電話錄音),重謝(有紅包噢)
Public Function InitWare(savefile As String) As Boolean '保存到位元組流
'SaveTofile保存到檔案 fps每秒禎數 PicFile 圖片樣張大小
If IsSaveAVI Then
MsgBox "檔案保存中,不能再次執行此操作!", vbInformation, "方舟提示"
Exit Function
End If
Dim res As Long
Dim strhdr_vides As AVI_STREAM_INFO
Dim BI As BITMAPINFOHEADER
Dim opts As AVI_COMPRESS_OPTIONS
Dim opts2 As AVI_COMPRESS_OPTIONS
Dim pOpts As Long, pOpts2 As Long
Dim Psfile As String
res = AVIFileOpen(fileHDC, savefile, OF_WRITE Or OF_CREATE, 0&) '創建或打開AVI檔案
If (res <> AVIERR_OK) Then GoTo error
Dim strhdr_auds_info As AVI_STREAM_INFO
With strhdr_auds_info '音頻流結構
.fccType = mmioStringToFOURCC("auds", 0&)
'.fccHandler = mmioFOURCC("g", "7", "2", "6")
.dwFlags = 0 '
.dwCaps = 0 '
.wPriority = 0 '
.wLanguage = 0 '
.dwScale = 1600 ' //
.dwRate = 8000 ' //Hz
.dwStart = 0 '
.dwInitialFrames = 0 '
.dwSuggestedBufferSize = 1600 '
.dwQuality = -1 '
.dwSampleSize = 1 '
'.rcFrame.bottom = 0 '
'.rcFrame.left = 0 '
'.rcFrame.right = 0 '
'.rcFrame.top = 0 '
.dwEditCount = 0 '
.dwFormatChangeCount = 0 '
.dwLength = 0 '
End With
res = AVIFileCreateStream(fileHDC, AuStream, strhdr_auds_info) '創建音頻流
If (res <> AVIERR_OK) Then GoTo error
'設備音頻流
Dim strhdr_auds As WAVEFORMATEX
With strhdr_auds '音頻格式
.wFormatTag = WAVE_FORMAT_PCM
.nChannels = 1
.nSamplesPerSec = 8000
.wBitsPerSample = 8
.nBlockAlign = (.wBitsPerSample / 8) * .nChannels
.nAvgBytesPerSec = .nSamplesPerSec * .nBlockAlign
'AVIStreamSetFormat(m_paviAudioStream, m_aviAudioFrames, &wave_format, sizeof(wave_format))
End With
Dim strauds() As Byte
ReDim strauds(0 To Len(strhdr_auds) - 1)
CopyMemory strauds(0), strhdr_auds, Len(strhdr_auds)
Dim btBuf As Long
btBuf = VarPtr(strauds(0))
Dim BufLen As Long
BufLen = UBound(strauds) + 1
res = AVIStreamSetFormat(AuStream, 0, ByVal btBuf, BufLen) '設備音頻格式
If (res <> AVIERR_OK) Then GoTo error
' res = AVIStreamSetFormat(AuStream, 0, ByVal strhdr_auds, Len(strhdr_auds)) '設備音頻格式
'If (res <> AVIERR_OK) Then GoTo error
pOpts2 = VarPtr(opts2)
'res = AVISaveOptions(Form1.hWnd, ICMF_CHOOSE_KEYFRAME Or ICMF_CHOOSE_DATARATE, 1, AuStream, pOpts2) '音頻壓縮方式
res = AVISaveOptions(Form1.hwnd, _
ICMF_CHOOSE_KEYFRAME Or ICMF_CHOOSE_DATARATE, _
1, _
AuStream, _
pOpts2) 'returns TRUE if User presses OK, FALSE if Cancel, or error code
'If res <> 1 Then 'In C TRUE = 1
' Call AVISaveOptionsFree(1, pOpts2)
' GoTo error
'End If
res = AVIMakeCompressedStream(AuCompressed, AuStream, opts2, 0&) '設定音頻壓縮方式
If res <> AVIERR_OK Then GoTo error
'res = AVIStreamSetFormat(AuCompressed, 0, ByVal VarPtr(strauds(0)), UBound(strauds) + 1) '設備音頻格式
'If (res <> AVIERR_OK) Then GoTo error
'Dim res As Long
''Dim btBuf As Long
''Dim BufLen As Long
'btBuf = VarPtr(btWare(0))
'BufLen = UBound(btWare) + 1
Dim byt(1 To 1600) As Byte
BufLen = UBound(byt)
btBuf = VarPtr(byt(1))
ChunkID = 1
res = AVIStreamWrite(AuCompressed, _
ChunkID, _
1, _
btBuf, _
BufLen, _
AVIIF_KEYFRAME, _
ByVal 0&, _
ByVal 0&)
'出錯位置,大佬們麻煩看一下寫不了 音頻寫入avi時回傳錯誤-2147205014
Debug.Print res
If res <> AVIERR_OK Then GoTo error
ChunkID = ChunkID + 1
InitWare = True
InitWare = True
Exit Function
error:
StopSave res
uj5u.com熱心網友回復:
錯誤資訊的意思是 引數錯誤,沒研究過視頻的東西, 建議你去msdn好好查查這個api的各引數意義
uj5u.com熱心網友回復:
謝謝.關于視頻API,資料很少.我也是沒轍了.轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/25195.html
標籤:多媒體
