Strange phenomenon when recording video with AVCaptureVideoDataOutput during the first video recording

35 Views Asked by At

I use AVCaptureVideoDataOutput to capture video with setSampleBufferDelegate function:

isRecoding = true
videoOutput.setSampleBufferDelegate(videoCaptureAssign, queue: videoQueue)
audioOutput.setSampleBufferDelegate(videoCaptureAssign, queue: videoQueue)

I get writeable data using function:

func writeBufferVideoToFile(assetWriter: AVAssetWriter,
                            sampleBuffer: CMSampleBuffer) {
    guard isRecoding else {
        return
    }
    // Start record
    if assetWriter.status == .unknown {
        assetWriter.startWriting()
        assetWriter.startSession(atSourceTime: CMSampleBufferGetPresentationTimeStamp(sampleBuffer))
    }
    
    // Record data
    if let assetWriterInput = assetWriter.videoInput,
       assetWriterInput.isReadyForMoreMediaData {
        // Record
        assetWriterInput.append(sampleBuffer)
    }
}

Before recording video with isRecoding = true, I set:

device.torchMode = .on

However, the first time I record a video, device.torchMode will automatically switch to .off and the screen will go dark for about 0.2 seconds. This no longer happens the next time the video is recorded.

How to make sure that the first time you record a video, touchMode doesn't automatically turn off and the screen doesn't go so dark. Can anyone give me a suggestion to solve this problem?

0

There are 0 best solutions below