قالب وردپرس درنا توس
Home / IOS Development / ios – How do you save a long video using AVFoundation (> 1 min)?

ios – How do you save a long video using AVFoundation (> 1 min)?



When I record video using the following view controls:

  class AVCameraViewController: UIViewController, AVCaptureFileOutputRecordingDelegate {

override func viewDidAppear (_ animated: Bool) {
super.viewDidAppear (animated)
initializeMotionManager ()
sessionQueue.async {
leave movieFileOutput = AVCaptureMovieFileOutput ()
if self.session.canAddOutput (movieFileOutput) {
self.session.beginConfiguration ()
self.session.addOutput (movieFileOutput)
self.session.sessionPreset = .high
if added = movieFileOutput.connection (with: .video) {
if connected.VideoStabilizationSupported {
connection.preferredVideoStabilizationMode = .auto
}
}
self.session.commitConfiguration ()
movieFileOutput.maxRecordedDuration = CMTime (seconds: 1
20, preferredTime scale: 60) self.movieFileOutput = movieFileOutput DispatchQueue.main.async { self.recordButton.isEnabled = true } } } } func fileOutput (_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from compounds: [AVCaptureConnection], Error: Error?) { // Note: Since we use a unique file path for each recording, a new recording will not overwrite a recording in the middle store. UIApplication.shared.isIdleTimerDisabled = false func cleanup () { let jobs = outputFileURL.path if FileManager.default.fileExists (atPath: path) { do { try FileManager.default.removeItem (atPath: path) } catch { print ("Could not remove file on url: (outputFileURL)") } } if leave currentBackgroundRecordingID = backgroundRecordingID { backgroundRecordingID = UIBackgroundTaskIdentifier.invalid if currentBackgroundRecordingID! = UIBackgroundTaskIdentifier.invalid { UIApplication.shared.endBackgroundTask (currentBackgroundRecordingID) } } } was success = true if wrong! = zero { print ("File file fill error: (String (describes: error))") success = (((error! like NSError) .userInfo [AVErrorRecordingSuccessfullyFinishedKey] as AnyObject) .boolValue)! } whose success { // Check authorization status. UIView.animate (withDuration: 0.5) { self.overlay.alpha = 0.9 self.navigationController? .navigationBar.isTranslucent = false } footageURL = outputFileURL performSegue (withIdentifier: "TrimFootage", sender: null) } other { clean up() } // Activate the camera and recording buttons to let the user switch the camera and start another recording. DispatchQueue.main.async { // Only enable the ability to change the camera if the device has more than one camera. self.recordButton.isEnabled = true // self.recordButton.setImage (#imageLiteral (resource name: "CaptureVideo"), for: []) } } }

As you can see, I set maxRecordedDuration to 2 minutes. When the recording is finished, another viewer finally succeeds.

The problem is right now, it only records a moment and then stops recording and victory. I am not sure if I do not correctly enter maxRecordedDuration or if I have to do anything else instead.


Source link