簡體   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