Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot export the video to play in full screen #31

Closed
rjt3662 opened this issue Jul 27, 2020 · 1 comment
Closed

Cannot export the video to play in full screen #31

rjt3662 opened this issue Jul 27, 2020 · 1 comment

Comments

@rjt3662
Copy link

rjt3662 commented Jul 27, 2020

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
                }
            })
            
        }
    }
@piemonte
Copy link
Contributor

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:

            AVVideoWidthKey: NSNumber(integerLiteral: Int(videoTrack?.naturalSize.height ?? 1080)),
            AVVideoHeightKey: NSNumber(integerLiteral: Int(videoTrack?.naturalSize.width ?? 1920)),

If you just use 1080 x 1920 instead to ensure you have a large video, if that's what you want.

Next, I recommend ensuring your video player is using aspectfit, then you should be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants