ios - AVVideoCompressionProperties按键崩溃

标签 ios swift avfoundation avassetwriter

我正在使用 AVAssetWriter 和 AVCaptureVideoDataOutput 进行实时视频录制。我在用户设备上看到许多崩溃报告,但无法在我的任何设备上重现它。我需要有关下面代码中可能出现问题的信息。发生这种情况可能是因为 NSDictionary 到 [String:AnyObject] 的类型转换失败。

在类里面我有:

private var videoOut: AVCaptureVideoDataOutput?

然后在一个函数中,我这样做:

  var recommendedSettings:[String:AnyObject]?

  recommendedSettings = videoOut.recommendedVideoSettings(forVideoCodecType: AVVideoCodecType.hevc, assetWriterOutputFileType: AVFileType.mov) as? [String : AnyObject]

  if let recommendedSettings = recommendedSettings {

  /* crashes here */
  var compressionSettings = recommendedSettings[AVVideoCompressionPropertiesKey] as! [String:AnyObject]


  }

Swift 中 AVVideoCompressionPropertiesKey 返回的字典的假定返回类型是什么?

最佳答案

返回的类型是字典,即

let videoCompressionProps: Dictionary<String, Any> = [
    AVVideoAverageBitRateKey : videoBitrate,
    AVVideoMaxKeyFrameIntervalKey : videomaxKeyFrameInterval,
    AVVideoProfileLevelKey : avVideoProfileLevel
]

关于ios - AVVideoCompressionProperties按键崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58500163/

相关文章:

ios - WatchOS2 的日期选择器?

swift - TableView 分隔符单元格消失?

ios - 如何在同一个 AVCaptureSession 上添加 AVVideoDataOutput 和 AVStillImageOutput?

ios - 拍照时有时不会播放相机快门噪音。

swift - AVAudioPCMBuffer 作为 Base64

ios - AVCaptureOutput didOutputSampleBuffer 停止被调用

Ios:如何避免捕获过程中视频方向发生变化?

ios - 内存永远不会释放潜在的内存泄漏

ios - .xib 文件如何自动关联并加载到我的 ViewController?

arrays - 如何仅在搜索栏文本不为空时才运行过滤功能?