我目前拍攝視頻,並使用AVCaptureSession音頻,並建立了管道寫出來使用AVAssetWriter的數據到硬盤的視頻。對於短片來說,這很好,絕對沒有問題。AVAssetWriter finishWriting失敗,生產只能觀看50%
但是,如果記錄介質的長度越過一些任意時間,通常約2分鐘,然後調用來完成寫入失敗,但仍設法制作的視頻文件只播放大約50%的內容。我在寫作過程中不斷調用isReadyForMoreMediaData並追加了SampleBuffer,並且它們始終返回true。我似乎沒有得到任何通知,直到finishWriting調用出現問題。
的AVAssetWriters錯誤是失敗的finishWriting呼叫
Capture failed to end with status 3 and error Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x210b7880 {NSLocalizedFailureReason=An unknown error occurred (268451843), NSUnderlyingError=0x210b1ee0 "The operation couldn’t be completed. (OSStatus error 268451843.)", NSLocalizedDescription=The operation could not be completed}
不是世界上最有用的錯誤後,設定成以下...
這是通過對AVCaptureSessionRuntimeErrorNotification監聽通話隨後不久我已經建立了一個包含錯誤
Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x21011940 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}
同樣不是非常有幫助?
這是代碼我用來配置AVAssetWriter輸入音頻
//\Configure Audio Writer Input
AudioChannelLayout acl;
bzero(&acl, sizeof(acl));
acl.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
NSDictionary* audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[ NSNumber numberWithInt: 2 ], AVNumberOfChannelsKey,
[ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
[ NSData dataWithBytes: &acl length: sizeof(AudioChannelLayout) ], AVChannelLayoutKey,
[ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey,
nil];
m_audioWriterInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioOutputSettings] retain];
這是我用來配置AVAssetWriterInput視頻
videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt:640], AVVideoWidthKey,
[NSNumber numberWithInt:480], AVVideoHeightKey,
nil];
m_videoWriterInput = [[AVAssetWriterInput
assetWriterInputWithMediaType:AVMediaTypeVideo
outputSettings:videoSettings] retain];
m_videoWriterInput.expectsMediaDataInRealTime = YES;
代碼這是我使用的初始化代碼AVAssetWriter
m_audioAndVideoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:outputPath] fileType:AVFileTypeQuickTimeMovie error:&error];
m_audioAndVideoWriter.shouldOptimizeForNetworkUse = YES;
[m_audioAndVideoWriter addInput:m_videoWriterInput];
[m_audioAndVideoWriter addInput:m_audioWriterInput];
有沒有人遇到類似的問題?或者知道可能會導致此問題的finishWriting調用內部發生了什麼?或者也許有人知道一些新穎的方法來調試這個問題?
感謝
將m_audioAndVideoWriter.shouldOptimizeForNetworkUse設置爲NO似乎可以停止發生錯誤。但是,我們需要將此設置設置爲yes,因爲視頻在流式傳輸的服務器上結束。 – RyanSullivan