I am using AVCaptureSession to record video with AVAssetWriter to a file and everything is working fine with iOS 13.+ devices(iPhone or iPad). But it is not working in iOS 12.4 iPad device, in that after a few seconds its video shows as a green screen(Most of the time it's getting the green screen but some times working it perfectly).
The configurations used as follows:
AVAssetWriter - fileType : AVFileType.mp4
let formatDescription = format.formatDescription let dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription)
//Have issue in iOS 12 device. So made the chnage. var videoCodecKey: AVVideoCodecType = .h264 let compressionDictionary: [String : Any] = [AVVideoExpectedSourceFrameRateKey: 25] if Common.isOSAtLeast(majorVersion: 13, minorVersion: 0) { videoCodecKey = .hevc }
let outputSetups: [String : Any] = [ AVVideoCodecKey: videoCodecKey,
AVVideoScalingModeKey: AVVideoScalingModeResizeAspectFill,
AVVideoWidthKey: (dimensions.width),
AVVideoHeightKey: dimensions.height,
AVVideoCompressionPropertiesKey: compressionDictionary]
videoWriterInput = AVAssetWriterInput(mediaType: AVMediaType.video,outputSettings: outputSetups)
let audioSettings: [String : Any] = [ AVFormatIDKey : kAudioFormatMPEG4AAC,
AVNumberOfChannelsKey : 2,
AVSampleRateKey : 44100.0,
AVEncoderBitRateKey: 192000 ]
audioInput = AVAssetWriterInput(mediaType: AVMediaType.audio,
outputSettings: audioSettings)
audioInput?.expectsMediaDataInRealTime = true
if videoWriter?.canAdd(audioInput) ?? false {
videoWriter?.add(audioInput)
print("audio input added")
}
//Add Video
videoWriterInput?.expectsMediaDataInRealTime = true
if videoWriter?.canAdd(videoWriterInput) ?? false {
videoWriter?.add(videoWriterInput)
print("video input added")
} else { print("no input added") }
videoWriter?.startWriting()
Please look into it and inform any issues found or require more information.
When working more on the issue its found that the issue is not related to the AVAssetWriter, In the video recording, we were embedding an image to the video. So that embedding made this issue.