vb 音频写入avi时返回错误-2147205014 ,重谢(有红包噢)

苍山的雪 2019-09-10 09:54:09
我要疯掉了.好几天都没弄好.是哪里错了.
一直返回的都是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
...全文
455 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
苍山的雪 2019-09-16
  • 打赏
  • 举报
回复
谢谢.关于视频API,资料很少.我也是没辙了.
PctGL 2019-09-12
  • 打赏
  • 举报
回复
错误信息的意思是 参数错误,
没研究过视频的东西, 建议你去msdn好好查查这个api的各参数意义

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧