You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm recording video using AVCaptureMovieFileOutput and passing the file URL given by AVCaptureMovieFileOutput to NextLevelSessionExporter instance.
I'm trying to export the video in a way that it takes up the whole device's screen to display video. It is working into the app, when I play the exported video using AVPreviewLayer it plays in full screen and takes up the whole device screen but as soon as I export the video into gallery then playing from gallery it does not plays into full screen and have black stripes above and below.
Basically, I want to do just like snapchat does, when we save a snap-video from snapchat it is being played into full screen from gallery.
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
if let err = error as NSError?, err.code != -11810 { //-11810 = recording stopped when timelimit reached
print("Error recording movie: \(err)")
} else {
let asset = AVAsset(url: outputFileURL)
let exporter = NextLevelSessionExporter(withAsset: asset)
exporter.outputFileType = AVFileType.mp4
let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
.appendingPathComponent(ProcessInfo().globallyUniqueString)
.appendingPathExtension("mp4")
exporter.outputURL = tmpURL
let compressionDict: [String: Any] = [
AVVideoAverageBitRateKey: NSNumber(integerLiteral: 1100000),
AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel as String,
]
let videoTrack = asset.tracks(withMediaType: .video).first
exporter.videoOutputConfiguration = [
AVVideoCodecKey: AVVideoCodecType.h264,
AVVideoWidthKey: NSNumber(integerLiteral: Int(videoTrack?.naturalSize.height ?? 1080)),
AVVideoHeightKey: NSNumber(integerLiteral: Int(videoTrack?.naturalSize.width ?? 1920)),
AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
AVVideoCompressionPropertiesKey: compressionDict
]
exporter.audioOutputConfiguration = [
AVFormatIDKey: kAudioFormatMPEG4AAC,
AVEncoderBitRateKey: NSNumber(integerLiteral: 128000),
AVNumberOfChannelsKey: NSNumber(integerLiteral: 2),
AVSampleRateKey: NSNumber(value: Float(44100))
]
exporter.export(progressHandler: { (progress) in
print(progress)
}, completionHandler: { [weak self] result in
guard let self = self else { return }
switch result {
case .success(let status):
switch status {
case .completed:
print("NextLevelSessionExporter, export completed, \(exporter.outputURL?.description ?? "")")
break
default:
print("NextLevelSessionExporter, did not complete")
break
}
break
case .failure(let error):
print("NextLevelSessionExporter, failed to export \(error)")
break
}
})
}
}
The text was updated successfully, but these errors were encountered:
hey @rjt3662 thanks for the project interest. to give you some tips, i recommend decoupling "playing fullscreen" from exporting the video to another format. It seems like you may be exporting the video at a small size:
I'm recording video using AVCaptureMovieFileOutput and passing the file URL given by AVCaptureMovieFileOutput to NextLevelSessionExporter instance.
I'm trying to export the video in a way that it takes up the whole device's screen to display video. It is working into the app, when I play the exported video using AVPreviewLayer it plays in full screen and takes up the whole device screen but as soon as I export the video into gallery then playing from gallery it does not plays into full screen and have black stripes above and below.
Basically, I want to do just like snapchat does, when we save a snap-video from snapchat it is being played into full screen from gallery.
The text was updated successfully, but these errors were encountered: