gpt4 book ai didi

ios - 未捕获的异常 'NSInvalidArgumentException',原因 : -[_SwiftValue floatValue]: unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-28 08:26:30 24 4
gpt4 key购买 nike

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[_SwiftValue floatValue]:无法识别的选择器发送到实例 0x17445bd80”

我在尝试快速压缩视频时收到上述错误。我很不明白为什么原因甚至是 floatValue,因为我的两个字典中的值都不是 float 。这导致我什至无法追查这个问题的根源。如果有人能指出正确的方向,我将不胜感激,下面是我用来压缩的两个函数。

func compressVideo(_ inputURL: URL, outputURL: URL, handler:@escaping (_ session: SDAVAssetExportSession)-> Void)
{



do{
let fileLocation = URL(fileURLWithPath: inputURL.path)
let videoData = try Data(contentsOf: fileLocation)
print(" \n BEFORE COMPRESSION: " + mbSizeWithData(data: videoData) + "\n")
} catch {}

let urlAsset = AVURLAsset(url: inputURL, options: nil)

//let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetHighestQuality)
let exportSession = SDAVAssetExportSession(asset: urlAsset)

exportSession?.outputURL = outputURL

exportSession?.videoSettings =
[(AVVideoCodecKey as NSString) as String : AVVideoCodecH264 as NSString
, AVVideoWidthKey : 1080 as Int64,
AVVideoHeightKey : 1920 as Int64,
AVVideoCompressionPropertiesKey : [AVVideoAverageBitRateKey as NSString: 100 as Int64,
AVVideoProfileLevelKey as NSString: AVVideoProfileLevelH264Main31, AVVideoMaxKeyFrameIntervalKey as NSString: 30 as Int64]]
exportSession?.audioSettings = [
AVFormatIDKey : kAudioFormatMPEG4AAC,
AVNumberOfChannelsKey : 2 as Int64,
AVSampleRateKey : 44100 as Int64,
AVEncoderBitRateKey : 128000 as Int64
]

exportSession?.outputFileType = AVFileTypeMPEG4

exportSession?.shouldOptimizeForNetworkUse = true

exportSession?.exportAsynchronously { () -> Void in

handler(exportSession!)
}

}


func doCompress() {
self.url = UserDefaults.standard.url(forKey: "videoURL")
print("\(self.url)")
let format = DateFormatter()
format.dateFormat="yyyy-MM-dd-HH-mm-ss"
let outputURl = self.url!.deletingLastPathComponent().appendingPathComponent("video\(format.string(from: Date())).mp4")
print("\(outputURl)")
self.compressVideo(self.url!, outputURL: outputURl, handler: { (session) in
if session.status == AVAssetExportSessionStatus.completed
{
//DEBUG :
let tempData = try? Data(contentsOf: outputURl)
print("\n AFTER COMPRESSION: " + mbSizeWithData(data: tempData!) + "\n")

self.url! = outputURl
print(self.url)
let data = try? Data(contentsOf: self.url!)
UserDefaults.standard.set(self.url, forKey: "videoURL")
UserDefaults.standard.synchronize()

print("File size after compression: \(Double(data!.count / 1048576)) mb")
self.videoData = try? Data(contentsOf: self.url!)
//print(self.videoData)



}

else if session.status == AVAssetExportSessionStatus.failed
{
print("failed")
}
})
}

最佳答案

您的视频和音频设置值类型错误,看起来您切换了宽度和高度并且您的 AVVideoAverageBitRateKey 看起来太低了。另外,我不确定 AVVideoProfileLevelH264Main31 是否受支持:

exportSession?.videoSettings = [
AVVideoCodecKey: AVVideoCodecH264,
AVVideoWidthKey : NSNumber(value:1920),
AVVideoHeightKey : NSNumber(value: 1080),
AVVideoCompressionPropertiesKey : [
AVVideoAverageBitRateKey: NSNumber(value:100),
// AVVideoProfileLevelKey: AVVideoProfileLevelH264Main31,
AVVideoMaxKeyFrameIntervalKey: NSNumber(value:30)
]
]

exportSession?.audioSettings = [
AVFormatIDKey : NSNumber(value:kAudioFormatMPEG4AAC),
AVNumberOfChannelsKey : NSNumber(value:2),
AVSampleRateKey : NSNumber(value:44100.0),
AVEncoderBitRateKey : NSNumber(value:128000)
]

关于ios - 未捕获的异常 'NSInvalidArgumentException',原因 : -[_SwiftValue floatValue]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39822974/

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