Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift-EXC_BAD_指令(代码=EXC_I386_INVOP,子代码=0x0)_Ios_Swift_Fatal Error - Fatal编程技术网

Ios Swift-EXC_BAD_指令(代码=EXC_I386_INVOP,子代码=0x0)

Ios Swift-EXC_BAD_指令(代码=EXC_I386_INVOP,子代码=0x0),ios,swift,fatal-error,Ios,Swift,Fatal Error,我正在尝试从视频文件中删除音频。我只在模拟器(iPadPro-12.9英寸)中出现此错误。我在模拟器的所有其他设备上运行了这段代码。它工作得很好 EXC_BAD_指令(代码=EXC_I386_INVOP,子代码=0x0) 在 let exporter:AVAssetExportSession=AVAssetExportSession(资产: 合成,预设名称:AVAssetExportPresetHighestQuality) 这条线 这是我的密码 func removeAudioFromVide

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

EXC_BAD_指令(代码=EXC_I386_INVOP,子代码=0x0)

let exporter:AVAssetExportSession=AVAssetExportSession(资产: 合成,预设名称: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)")                    
                }
        })
    }
屏幕截图:


那里的作文是什么?它看起来像是零,如果不是零,试着不只是放“!”做一些守卫或以不同的方式检查;除了来自Lu_389;的正确注释之外:在创建ExportSession之前使用exportPresets来确定合成是否兼容。但这在所有其他设备中都非常有效。有什么原因吗?你试过了吗?它有帮助吗?如果你使用iOS 13或更高版本的模拟器,它会崩溃,但可以在设备上运行,然后尝试使用模拟器iPhone 5s(iOS 11)。我试着从中学习它,它在模拟器iPhone 11(iOS 13)上崩溃,但在模拟器iPhone 5s(iOS 11)和我的设备iPhone 6(iOS 12.5)上工作