Swift - EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)

时间:2017-05-09 10:43:41

标签: ios swift fatal-error

我正在尝试从视频文件中删除音频。我只在模拟器(iPadPro-12.9英寸)中收到此错误。我在模拟器中的所有其他设备上运行此代码。它工作得很好。

  

EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)

in

  

让导出器:AVAssetExportSession = AVAssetExportSession(资产:   composition,presetName:AVAssetExportPresetHighestQuality)!

这一行。

这是我的代码

func removeAudioFromVideo(_ videoURL: URL) {
        let inputVideoURL: URL = videoURL
        let sourceAsset = AVURLAsset(url: inputVideoURL)
        let sourceVideoTrack: AVAssetTrack? = sourceAsset.tracks(withMediaType: AVMediaTypeVideo)[0]
        let composition : AVMutableComposition = AVMutableComposition()
        var compositionVideoTrack: AVMutableCompositionTrack? = composition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid)
        let x: CMTimeRange = CMTimeRangeMake(kCMTimeZero, sourceAsset.duration)
        _ = try? compositionVideoTrack!.insertTimeRange(x, of: sourceVideoTrack!, at: kCMTimeZero)

        mutableVideoURL = NSURL(fileURLWithPath: NSHomeDirectory() + "/Documents/mutableVideo\(mutableVideoCounter).mp4")
        mutableVideoCounter += 1

        //video orientation
        let assetVideoTrack = (sourceAsset.tracks(withMediaType: AVMediaTypeVideo)).last
        compositionVideoTrack = (composition.tracks(withMediaType: AVMediaTypeVideo)).last
        if ((assetVideoTrack?.isPlayable)! && (compositionVideoTrack?.isPlayable)!) {
            compositionVideoTrack?.preferredTransform = (assetVideoTrack?.preferredTransform)!
        }

        let exporter: AVAssetExportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality)!
        exporter.outputFileType = AVFileTypeMPEG4
        exporter.outputURL = mutableVideoURL as URL
        exporter.exportAsynchronously(completionHandler:
            {
                switch exporter.status
                {
                case AVAssetExportSessionStatus.failed:
                    print("failed \(String(describing: exporter.error))")
                case AVAssetExportSessionStatus.cancelled:
                    print("cancelled \(String(describing: exporter.error))")
                case AVAssetExportSessionStatus.unknown:
                    print("unknown\(String(describing: exporter.error))")
                case AVAssetExportSessionStatus.waiting:
                    print("waiting\(String(describing: exporter.error))")
                case AVAssetExportSessionStatus.exporting:
                    print("exporting\(String(describing: exporter.error))")
                default:
                    print("-----Mutable video exportation complete.\(self.mutableVideoURL)")                    
                }
        })
    }
屏幕截图: enter image description here

enter image description here

0 个答案:

没有答案