3

I have an app (enterprise, distributed OTA) that among other things records video clips. All of a sudden, we started getting video uploads that were missing audio, and this issue now seems to be totally reproducible. I've been using the PBJVision library, which had seemed to work great, but I have also tested this with SwiftyCam (another AVFoundation-based library) with same results. It's unclear exactly when this was introduced, but I've checked the following:

  • Ensure that a NSMicrophoneUsageDescription is set in the target .plist
  • Ensure that camera and microphone permissions are showing as granted in system settings
  • Try disabling microphone permissions in settings (app correctly prompts the user to re-enable permissions)
  • Try earlier releases of the video capture library in case of regression
  • Try different video capture library
  • Explicitly set audio enabled and bitrate for PBJVision/SwiftyCamera, and ensure that the session is at least reporting that it has audio in the logs (that is, the library and AVFoundation think there's an input set up, with an input stream that's being handled)
  • Take a video with the system camera, and upload through the app — in this case, audio does work (it's not a problem with the hardware)
  • Reset all content and permissions on a device, to make sure there isn't some kind of cached permission hanging out
  • Make sure volume is not muted

The copy that gets saved to the camera roll is also silent, so it's not happening when the video gets uploaded. I also started to implement recording using just AVFoundation, but don't want to waste time if that will produce the same results. What could be causing a particular app not to record audio with video? I have looked at related questions, and none of the solutions provided address the problem I'm having here.

EDIT:

Here are the logs that appear when starting, recording, and stopping a PBJVision session:

[5411:1305718] VISION: camera setup
[5411:1305718] VISION: switchDevice 1 switchMode 1
[5411:1305718] VISION: capture session setup
[5411:1305291] VISION: session was started
[5411:1305718] VISION: capture session running
[5411:1305291] VISION: starting video capture
[5411:1305718] VISION: ready for video (1)
[5411:1305718] VISION: audio stream setup, channels (1) sampleRate (44100.000000)
[5411:1305718] VISION: ready for audio (1)
[5411:1305291] VISION: ending video capture
[5411:1305963] VISION: capture session stopped
[5411:1305963] VISION: session was stopped
[5411:1305291] CMTimeMakeWithSeconds(8.396 seconds, timescale 24): warning: error of -0.021 introduced due to very low timescale
4

1 回答 1

2

事实证明,这实际上是由于在开始视频录制后使用另一个库播放声音所致。这显然抢占了录音的音频通道,因为它最终是空的(请参阅Record Audio/Video with AVCaptureSession and Playback Audio 同时?)。在开始视频录制之前或之后是否开始播放其他声音似乎并不重要。这是一个很好的警告案例,使用多个库都接触相同的系统 API——在某些情况下,就像这个一样,它们以不受欢迎的方式交互。

在这种情况下,解决方案是确保两个源没有使用相同的AVAudioSessionCategory,因此它们不会发生冲突。

于 2017-08-25T21:38:24.540 回答