来自后台时 CMSampleBuffer 的音频格式会发生变化

问题描述

我正在使用 AVFoundation 的 AVCaptureSession 捕获音频和视频,使用 AVCaptureVideoDataOutputSampleBufferDelegate 和 AVCaptureAudioDataOutputSampleBufferDelegate 来收集 CMSampleBuffers 并使用 AVAssetWriter 将它们写入文件

我面临的问题是,在录制时,如果用户进入后台并返回,CMSampleBuffer 的 AudioFormat 会从:

这个

Try
    Dim adres As String = "https://www.google.com/search?q=" + TextBox1.Text
    Dim istek As WebRequest = HttpWebRequest.Create(adres)
    Dim cevap As WebResponse
    cevap = istek.GetResponse()
    Dim donenBilgiler As StreamReader = New StreamReader(cevap.GetResponseStream())
    Dim gelen As String = donenBilgiler.ReadToEnd()
    Dim titleIndexBaslangici As Integer = gelen.IndexOf("<link href") + 2
    Dim titleIndexBitisi As Integer = gelen.Substring(titleIndexBaslangici).IndexOf(">")
    ListBox1.Items.Add(gelen.Substring(titleIndexBaslangici,titleIndexBitisi))
Catch ex As Exception
    MsgBox(ex.Message)
End Try

为此:

  FormatList Array: {
    Index: 0 
    ChannelLayoutTag: 0x640001 
    ASBD: {
    mSampleRate: 48000.000000 
    mFormatID: 'lpcm' 
    mFormatFlags: 0xc 
    mBytesPerPacket: 2 
    mFramesPerPacket: 1 
    mBytesPerFrame: 2 
    mChannelsPerFrame: 1 
    mBitsPerChannel: 16     }} 

这显然会导致 AVAssetWriter 中的 AudioInput 出现问题并导致写入失败

有人知道发生了什么吗?

关于 CaptureSession 设置:

输入: 前置/后置摄像头和内置麦克风

输出: AVCaptureVideoDataOutput & AVCaptureAudioDataOutput

当我开始会话时,我正在更改 videoInput 设备中的活动格式

谢谢,Yoav

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)