AVCaptureSession音频不适用于长视频 [英] AVCaptureSession audio doesn't work for long videos

查看:295
本文介绍了AVCaptureSession音频不适用于长视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVCaptureSession录制带有音频的视频。一切似乎都适用于短视频,但由于某些原因,如果我录制的视频长度大于12秒,则音频不起作用。

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.

推荐答案

我发现解决方案为一个完全不同的答案问题

问题是AVCaptureMovieFileOutput中的 movieFragmentInterval 属性。

The issue is the movieFragmentInterval property in AVCaptureMovieFileOutput.

此属性的文档说明了这些片段是什么:

The documentation for this property explains what these fragments are:


QuickTime影片由媒体样本和样本表
标识它们在文件中的位置。没有示例
表的电影文件是不可读的。

A QuickTime movie is comprised of media samples and a sample table identifying their location in the file. A movie file without a sample table is unreadable.

在处理过的文件中,示例表通常出现在文件的
开头。它也可能出现在文件的末尾,在
中,在这种情况下,标题包含指向
结尾的样本表的指针。当正在记录新的电影文件时,由于文件的大小尚不清楚,因此无法
写入样本表。
相反,录制完成后必须写入表格。如果
没有采取其他操作,这意味着如果记录没有成功完成
(例如,在发生崩溃的情况下),文件
数据将无法使用(因为有没有样品表)。通过定期
将影片片段插入到影片文件中,样本表可以逐步建立
。这意味着如果文件没有完全写入
,则电影文件仍然可用(直到写入
最后一个片段的位置)。

In a processed file, the sample table typically appears at the beginning of the file. It may also appear at the end of the file, in which case the header contains a pointer to the sample table at the end. When a new movie file is being recorded, it is not possible to write the sample table since the size of the file is not yet known. Instead, the table is must be written when recording is complete. If no other action is taken, this means that if the recording does not complete successfully (for example, in the event of a crash), the file data is unusable (because there is no sample table). By periodically inserting "movie fragments" into the movie file, the sample table can be built up incrementally. This means that if the file is not written completely, the movie file is still usable (up to the point where the last fragment was written).

它还说:


默认值为10秒。设置为kCMTimeInvalid以禁用电影
片段写入(通常不推荐)。

The default is 10 seconds. Set to kCMTimeInvalid to disable movie fragment writing (not typically recommended).

所以由于某种原因我的录音变得混乱无论何时写入片段。我刚刚添加了行 movieFileOutput.movi​​eFragmentInterval = kCMTimeInvalid; (其中 movieFileOutput 是我添加到AVCaptureSession的AVCaptureMovieFileOutput )禁用片段写入,现在音频工作。

So for some reason my recording is getting messed up whenever a fragment is written. I just added the line movieFileOutput.movieFragmentInterval = kCMTimeInvalid; (where movieFileOutput is the AVCaptureMovieFileOutput I've added to the AVCaptureSession) to disable fragment writing, and the audio now works.

这篇关于AVCaptureSession音频不适用于长视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆