录制视频的时候,视频长度超过10s,没有声音的解决方案


  我使用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
问题得到了圆满解决。

希望能帮助和我一样,因为这个苦苦搜寻的同学们。

视频 ios

全人类D绯想天 10 years, 2 months ago

Your Answer