繁体   English   中英

如何为视频录制设置10秒的限制并实时删除10秒的旧胶片部分-Swift iOS

[英]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秒。 因此它不会占用太多内存。 当有人按下“停止记录按钮”时,它将保存到相机胶卷中。

我已经在网上搜索了类似的内容,但没有任何帮助。 您知道一个好的教程,甚至是源代码吗?

//预先感谢,安东

使用属性:

videoMaximumDuration

您有一个令人困惑的问题。 您不想停止录制,但只想删除剪辑的结尾? 为什么不在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM