0
我已成功設置AVAssetWriter以將視頻錄製並保存到相機膠捲。唯一的問題是錄製的視頻的第一幀是空白的白框。有沒有辦法解決這個問題?到底是怎麼回事?AVAssetWriter在Swift中錄製視頻?
我已成功設置AVAssetWriter以將視頻錄製並保存到相機膠捲。唯一的問題是錄製的視頻的第一幀是空白的白框。有沒有辦法解決這個問題?到底是怎麼回事?AVAssetWriter在Swift中錄製視頻?
你對視頻幀有任何操縱嗎?在我的情況下,我正在調整視頻幀的大小,然後再編寫它們。在這種情況下,首先寫入音頻幀,在幾幀後寫入視頻幀。由於這個原因,前幾幀在預覽中顯示爲白色。但它在視頻播放中幾乎不明顯。
解決方案:
跳過寫音頻幀,直到你使用avasssetwriter
推薦代碼captureoutput
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection!) {
if CMSampleBufferDataIsReady(sampleBuffer) == false
{
// Handle error
return;
}
startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer)
if videoWriter.status == AVAssetWriterStatus.Unknown {
videoWriter.startWriting()
videoWriter.startSessionAtSourceTime(startTime)
return
}
if videoWriter.status == AVAssetWriterStatus.Failed {
// Handle error here
return;
}
// Here you collect each frame and process it
if(recordingInProgress){
if let _ = captureOutput as? AVCaptureVideoDataOutput {
if videoWriterInput.isReadyForMoreMediaData{
videoWriterInput.append(sampleBuffer)
video_frames_written = true
}
}
if let _ = captureOutput as? AVCaptureAudioDataOutput {
if audioWriterInput.isReadyForMoreMediaData && video_frames_written{
audioWriterInput.append(sampleBuffer)
}
}
}
}
我想這可能工作寫一個視頻幀,但似乎即使我只在寫入視頻幀時寫入音頻幀,仍然存在一個白色幀,其中既沒有視頻也沒有au dio被記錄。還有其他建議嗎? –
你能分享錄製的文件嗎?可能是第一個samplebuffer的日誌? – manishg
以下是視頻https://drive.google.com/file/d/0B2QAK-lm39WhdVlqa0hSY0tNaGM/view?usp=sharing的示例。錄音機的設置方式是每隔一秒錄製一個新的片段,但問題不在於此,因爲在錄製的第一秒內仍然存在空白幀,沒有視頻或音頻。 –