gpt4 book ai didi

ios - 无法设置视频录制的最长持续时间?

转载 作者:行者123 更新时间:2023-11-28 14:11:43 25 4
gpt4 key购买 nike

我创建了一个自定义相机,我想将最长录制时间设置为 30 秒。这是为设置最大值编写代码的地方。

@objc func videoAction(sender: UIButton){

if(imageSetAction()){
videoImage.image = UIImage(named: "video")
flashButton.isHidden = true
videoLabel.textColor = ConstantColors.selectedTextColor
currentSelected = sender.tag
if(videoButton.isEnabled){
if(photoOutput != nil){
captureSession.removeOutput(photoOutput!)
}

self.movieFileOutput = AVCaptureMovieFileOutput()
self.movieFileOutput?.maxRecordedDuration = CMTime(seconds: 30, preferredTimescale: 600)
if captureSession.canAddOutput(movieFileOutput!) {
captureSession.addOutput(movieFileOutput!)
}
captureSession.commitConfiguration()
captureSession.sessionPreset = AVCaptureSession.Preset.high
}
let longPressGesture = UILongPressGestureRecognizer.init(target: self, action: #selector(handleLongPress))
self.semiCircleView.addGestureRecognizer(longPressGesture);
videoButton.isEnabled = false
}
}

之后我有一个选项供用户编辑视频,所以我在委托(delegate)方法中调用默认视频编辑器。

func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
if error == nil {
//UISaveVideoAtPathToSavedPhotosAlbum(outputFileURL.path, nil, nil, nil)
if UIVideoEditorController.canEditVideo(atPath: outputFileURL.path){
let videoEditorController = UIVideoEditorController()
videoEditorController.delegate = self
videoEditorController.videoPath = outputFileURL.path
videoEditorController.modalPresentationStyle = .popover
videoEditorController.popoverPresentationController?.sourceView = self.view
present(videoEditorController, animated: true, completion: nil)
}
}
print("completed")
}

func fileOutput(_ output: AVCaptureFileOutput, didStartRecordingTo fileURL: URL, from connections: [AVCaptureConnection]) {
movieFileOutput?.maxRecordedDuration = CMTimeMake(30, 1)

/* After 30 seconds, let's stop the recording process */
DispatchQueue.main.asyncAfter(deadline: .now() + 30.0, execute: {
debugPrint("longpress ended")
self.movieFileOutput?.stopRecording()
self.removeProgressBar()
})
}

不知道为什么,视频只录制了 10 秒。任何帮助表示赞赏。谢谢。

最佳答案

来自有关 maxRecordedDuration 方法的 Apple 文档。

This property specifies a hard limit on the duration of recorded files. Recording is stopped when the limit is reached and the fileOutput(_:didFinishRecordingTo:from:error:) delegate method is invoked with an appropriate error. The default value of this property is invalid, which indicates no limit.

如果它会在 fileOutput(_:didFinishRecordingTo:from:error:) 方法中停止,也许你不应该停止自己录制。

关于ios - 无法设置视频录制的最长持续时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52469187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com