[英]How to set a 10 second limit to video recording and in real time remove the 10 seconds old film parts - Swift iOS
我可以理解标题是否真的令人困惑,但是我将尽力更详细地解释! 我有一个关于iOS Swift应用的计划,该应用将录制时间限制为10秒的视频。 但是当短片达到10秒时,它不应停止录制。 它应该去掉剪辑的末端,所以它的长度不会超过10秒。 因此它不会占用太多内存。 当有人按下“停止记录按钮”时,它将保存到相机胶卷中。
我已经在网上搜索了类似的内容,但没有任何帮助。 您知道一个好的教程,甚至是源代码吗?
//预先感谢,安东
使用属性:
您有一个令人困惑的问题。 您不想停止录制,但只想删除剪辑的结尾? 为什么不在10秒后停止录制?
您可以使用dispatch_time停止,对我有用:
func captureOutput(captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAtURL fileURL: NSURL!, fromConnections connections: [AnyObject]!) {
captureOutput.maxRecordedDuration = CMTimeMake(10, 1)
/* After 10 seconds, let's stop the recording process */
let delayInSeconds = 10.0
let delayInNanoSeconds = dispatch_time(DISPATCH_TIME_NOW, Int64(delayInSeconds * Double(NSEC_PER_SEC)))
dispatch_after(delayInNanoSeconds, dispatch_get_main_queue(), {
captureOutput.stopRecording()
})
return
}
如果在将AVCaptureMovieFileOutput
添加到AVCaptureSession
时使用AVFoundation
进行AVFoundation
应设置最大录制持续时间。
private let session = AVCaptureSession()
private let movieOutput = AVCaptureMovieFileOutput()
movieOutput.maxRecordedDuration = CMTime(seconds: 10, preferredTimescale: 600)
if session.canAddOutput(movieOutput) {
session.addOutput(movieOutput)
}
在最大录制持续时间后,将调用fileOutput(didFinishRecordingTo:from:error:)
并将视频保存到指定的URL,持续时间fileOutput(didFinishRecordingTo:from:error:)
最大录制时间短几毫秒。 请注意,错误不会为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.