I am able to compress video captured from camera device to h264 format using video toolbox framework, but when I tried to play that h264 file in VLC player I am not able to hear the audio of the video. I think audio compression should also be done in code.
But how I didn't found any resource?
You can decode your recorded video by this way :-
func encodeReocrdedVideoToH264(url:URL) {
        let anAsset =  AVAsset.init(url: url)// Your source AVAsset movie in HEVC format //
        let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
        let outputURL = documentsURL?.appendingPathComponent("recording.mp4")
        // These settings will encode using H.264.
        let preset = AVAssetExportPresetHighestQuality
        let outFileType = AVFileType.mov
        AVAssetExportSession.determineCompatibility(ofExportPreset: preset, with: anAsset, outputFileType: outFileType) { (isCompatible) in
            if !isCompatible {
                print("AVAssetExportSession Not Compatible")
                return
            }
        }
        guard let export = AVAssetExportSession(asset: anAsset, presetName: preset) else {
            return
        }
        export.outputFileType = outFileType
        export.outputURL = outputURL
        export.exportAsynchronously { () -> Void in
            // Handle export results.
            print("exportAsynchronously Succesuffully")
        }
    }
You can see your encoded video at outputURL.
For more information, please check Apple's doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With