使用AVCaptureSession录制视频和音频。如果是短时间的视频录制,完全没有问题。但是出于某种原因,如果我录制超过10秒的视频,就会没有音频。这个问题困扰了很久。
最终发现。
这个问题是AVCaptureMovieFileOutput movieFragmentInterval属性。
@property movieFragmentInterval
@abstract
Specifies the frequency with which movie fragments should be written.
@discussion
When movie fragments are used, a partially written QuickTime movie file whose writing is unexpectedly interrupted can
be successfully opened and played up to multiples of the specified time interval. A value of kCMTimeInvalid indicates
that movie fragments should not be used, but that only a movie atom describing all of the media in the file should be
written. The default value of this property is ten seconds.
Changing the value of this property will not affect the movie fragment interval of the file currently being written,
if there is one.
可以看出,它的默认值就是10秒。将这个值禁用后。
_captureMovieFileOutput.movieFragmentInterval = kCMTimeInvalid
问题得到了圆满解决。
希望能帮助和我一样,因为这个苦苦搜寻的同学们。

本文详细解析了在使用AVCaptureSession录制视频时遇到的音频丢失问题,发现并解决了AVCaptureMovieFileOutput的movieFragmentInterval属性导致的问题。通过将该属性设置为kCMTimeInvalid,成功解决了录制超过10秒视频时无音频的问题。
1196

被折叠的 条评论
为什么被折叠?



