I'm using AVCaptureSession to record a video with audio. Everything seems to work properly for short videos, but for some reason, if I record a video that is longer than about 12 seconds, the audio doesn't work.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
I found the solution as an answer to a completely different question.
The issue is the
movieFragmentInterval
property in AVCaptureMovieFileOutput.The documentation for this property explains what these fragments are:
It also says:
So for some reason my recording is getting messed up whenever a fragment is written. I just added the line
movieFileOutput.movieFragmentInterval = kCMTimeInvalid;
(wheremovieFileOutput
is the AVCaptureMovieFileOutput I've added to the AVCaptureSession) to disable fragment writing, and the audio now works.We also experienced this issue. Basically disabling movie fragment writing will work but it doesn't actually explain the issue. Most likely you are recording to an output file using a file extension that does not support this feature, like
mp4
. If you pass an output file with the extensionmov
you should have no issues using movie fragment writing and the output file will have audio.Updating
videoFileOutput.movieFragmentInterval = kCMTimeInvalid
solved this for me.However, I accidentally set the
movieFragmentInterval
after callingstartRecordingToOutputFileURL
. An agonizing hour later I realized my mistake. For newbies like me, note this obvious sequence.