Advertisement
Guest User

Untitled

a guest
Nov 26th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.39 KB | None | 0 0
  1.         let exporter = NextLevelSessionExporter(withAsset: asset)
  2.         exporter.outputFileType = AVFileType.mov
  3.         let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
  4.             .appendingPathComponent(ProcessInfo().globallyUniqueString)
  5.             .appendingPathExtension("mov")
  6.         exporter.outputURL = tmpURL
  7.        
  8.         let compressionDict: [String: Any] = [
  9.             AVVideoAverageBitRateKey: NSNumber(integerLiteral: 6000000),
  10.             AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel as String,
  11.         ]
  12.         if #available(iOS 11.0, *) {
  13.             exporter.videoOutputConfiguration = [
  14.                 AVVideoCodecKey: AVVideoCodecType.hevc, // set hevc codec instead of h264
  15.                 AVVideoWidthKey: NSNumber(integerLiteral: 1920),
  16.                 AVVideoHeightKey: NSNumber(integerLiteral: 1080),
  17.                 AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
  18.                 AVVideoCompressionPropertiesKey: compressionDict
  19.             ]
  20.         } else {
  21.             // Fallback on earlier versions
  22.         }
  23.         exporter.audioOutputConfiguration = [
  24.             AVFormatIDKey: kAudioFormatMPEG4AAC,
  25.             AVEncoderBitRateKey: NSNumber(integerLiteral: 128000),
  26.             AVNumberOfChannelsKey: NSNumber(integerLiteral: 2),
  27.             AVSampleRateKey: NSNumber(value: Float(44100))
  28.         ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement