0

我正在开发具有修剪功能的视频播放器。我为此使用 ABVideoRangeSlider。每当我尝试修剪和保存视频时,我都会收到Error Domain=NSCocoaErrorDomain Code=-1 "(null)"此错误。这是我的代码片段

    let composition = AVMutableComposition()
    let track = composition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID:Int32(kCMPersistentTrackID_Invalid))

    try! track.insertTimeRange(CMTimeRangeMake(startTimeForCurrentSlice, endTimeForCurrentSlice), of: asset.tracks(withMediaType: AVMediaTypeVideo)[0] as AVAssetTrack, at: kCMTimeZero)
    var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let documentsDirectory = paths[0] as String
    let videoPathToSave = documentsDirectory.appending("mergeVideo-\(arc4random()%1000)-d.mp4")
    let videoURLToSave = NSURL(fileURLWithPath: videoPathToSave)

    PHPhotoLibrary.shared().performChanges({
        PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoURLToSave as URL)
    }) { saved, error in
        if saved {
            let alertController = UIAlertController(title: "Your video was successfully saved", message: nil, preferredStyle: .alert)
            let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
            alertController.addAction(defaultAction)
            self.present(alertController, animated: true, completion: nil)
        } else {
            print("Error: \(String(describing: error!))")
        }
    }

任何帮助将不胜感激。

4

1 回答 1

0

保存到相机胶卷之前您需要AVMutableComposition使用AVAssetExportSession或导出您的AVAssetWriter,然后您可以将其保存到相机胶卷。

查看教程以了解AVAssetExportSession使用情况。保存到相机胶卷它使用ALAssetsLibrary,但你可以保存它Photos

于 2017-07-04T20:01:45.273 回答