我这段代码AVIFileCreateStream参数哪里错了?(在线等)

askdef 2016-03-21 10:25:07
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
...全文
2378 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hc2008l5 2020-02-19
  • 打赏
  • 举报
回复
https://blog.csdn.net/jinboker/article/details/52128276?utm_source=distribute.wap_relevant.none-task
苍山的雪 2019-09-10
  • 打赏
  • 举报
回复
帅哥.音频问题搞掂了没?我下载了你的VB6实现屏幕和音频都录入 合成avi音影视听的 源码实例,但没窗体.我想说的不是这个.我一直在找你的联系方式,但没有.音频问题我也被搞疯掉了.如果你搞掂了.麻烦跟我联系一下.有谢礼啊.如果能将语言聊天保存为avi文件(即电话录音),一个远程音频采集传输到本机+本机采集.能入保存为avi文件(时间线要统一).请与我联系.Q452781589重谢
askdef 2016-03-21
  • 打赏
  • 举报
回复
把图片写入avi文件没有问题可以显示,就是把音频写入avi不会发声,只有图像没有声音。谁能指点一下写音频的关健地方吗
内容概要:本文是一篇详尽的Python调用万邦API实战教程,以速卖通关键词搜索接口(aliexpress.item_search)为主线,系统讲解了从注册获取Key、安装requests库、构建请求、参数详解、解析JSON返回值,到数据清洗、翻页采集、去重、导出CSV/Excel,以及提升代码健壮性的完整流程。文章深入剖析了接口的公共参数与业务参数配置方法,解读了复杂的返回结构(包括外层元信息与内层商品数据),并提供了自定义解析、异常处理、重试机制、限流控制等实用代码模板,最后还指导如何将方案迁移到1688、京东、Lazada等其他电商平台。; 适合人群:具备基础Python编程能力,对网络爬虫、自动化数据采集或跨境电商数据分析感兴趣的研发人员、数据分析师或运营人员。; 使用场景及目标:① 实现对速卖通等电商平台的商品数据进行高效、稳定的批量采集,用于选品分析、竞品监控和价格带研究;② 学习如何构建一个健壮、可复用的第三方API调用程序,掌握错误处理、数据清洗和自动化导出的核心技能。; 阅读建议:学习时应结合文档提供的完整可运行脚本,逐步动手实践每个环节,重点关注“常见问题排查手册”中的坑点,并在真实项目中应用所学的错误码判断、数据类型安全转换和额度监控等最佳实践。

807

社区成员

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

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