如何设置仅包含mp4a格式的白噪声的CMSampleBufferRef?这是我到目前为止所尝试的:
CMSampleBufferRef garbageAudioSampleBuffer = NulL;AudioStreamBasicDescription audioFormat;audioFormat.mSampleRate = 44100;audioFormat.mFormatID = kAudioFormatlinearPCM;audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;audioFormat.mFramesPerPacket = 1;audioFormat.mChannelsPerFrame = 2;audioFormat.mBitsPerChannel = 16;audioFormat.mBytesPerPacket = 4; audioFormat.mBytesPerFrame = 4;CMAudioFormatDescriptionRef audioFormatDescrip = NulL;CMAudioFormatDescriptionCreate(kcfAllocatorDefault,&audioFormat,NulL,&audioFormatDescrip );CMSampleBufferCreate(kcfAllocatorDefault,YES,// audioFormatDescrip,&garbageAudioSampleBuffer );if(myAVAssetAudioWriterinput isReadyForMoreMediaData) [myAVAssetAudioWriterinput appendSampleBuffer:garbageAudioSampleBuffer];
当为audioFormatDescrip传递NulL时,mov文件成功生成但仅包含视频轨道(并且没有音频轨道).当我实际传递audioFormatDescrip时,mov文件似乎已损坏.我可能不得不实际传递一些样品,但我不确定如何.
注意:我已经验证了appendSampleBuffer返回YES(为简洁起见,我省略了该代码).
解决方法 您的代码中存在许多问题:>白噪声具有统计定义,您正在创建未定义的噪声.
>您没有将audioFormatDescription传递给CMSampleBufferCreate
>您使用CMSampleBufferCreate而不是CMAudioSampleBufferCreateWithPacketDescriptions使您的生活变得复杂(您没有数据包描述,所以只是过去的null& 0)
>您需要说明音频缓冲区何时带有演示时间戳
>您的音频缓冲区长度为0帧.那太短了.
>最后,您需要不断添加音频缓冲区,足以在整个影片期间使用
CoreMedia代码可能很棘手,因为有数百个参数需要恰到好处.为了你的目的,它可能有点过于笼统,那么为什么不得到一个可循环的白噪声片段并使用AVMutableComposition组装它?这将给你一个电影&和一个音频文件,然后您可以使用另一个AVMutableComposition和AVAssetExportSession压缩在一起.
总结以上是内存溢出为你收集整理的ios – 使用AVAssetWriter创建白噪声音频轨道全部内容,希望文章能够帮你解决ios – 使用AVAssetWriter创建白噪声音频轨道所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)