我一直在尝试使用AVAssetWriter和AVAssetWriterInputs编写视频+音频.
我在这个论坛上看了很多人说他们能够做到这一点,但这对我不起作用.如果我只是写视频,那么代码就能很好地完成它的工作.当我添加音频时,输出文件已损坏且无法再现.
这是我的代码的一部分:
设置AVCaptureVideoDataOutput和AVCaptureAudioDataOutput:
NSError *error = nil;
// Setup the video input
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
// Create a device input with the device and add it to the session.
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
// Setup the video output
_videoOutput = [[AVCaptureVideoDataOutput alloc] init];
_videoOutput.alwaysDiscardsLateVideoFrames = NO;
_videoOutput.videoSettings =
[NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
// Setup the audio input
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error ];
// Setup the …
Run Code Online (Sandbox Code Playgroud) 我正在研究记录用户音频的应用程序,使用数据写入文件AudioToolbox
并处理这些数据.在分析中,我看到AudioToolbox录制中发生了很多错误.其中几乎一半是-38 kAudioFileNotOpenError
从AudioFileWriteBytes()
通话中返回的错误.
现在似乎没有任何理由发生这种情况:用户开始录制,一切顺利,然后连续10-80次记录错误.在分析中,没有用户操作,例如转到后台或暂停录制(我们有此功能).
我在线研究了信息,但没有找到有关错误的更多信息.
我发布了所有录制代码(带有剥离的未使用或分析代码),因为除了-38 kAudioFileNotOpenError
我有一堆其他错误,这可能意味着我可能以AudioToolbox
错误的方式使用.以下是最重要的错误:
AudioFileWriteBytes()
返回-38 kAudioFileNotOpenError
错误:( [1]
代码中) - 约50%的错误AudioUnitRender()
返回-10863 kAudioUnitErr_CannotDoInCurrentContext
错误([2]
代码中) - ~5%AudioFileWriteBytes()
返回1868981823 kAudioFileDoesNotAllow64BitDataSizeError
错误:( [1]
代码中) - ~4%AudioUnitRender()
返回-1
错误([2]
代码中) - ~3%任何帮助,评论或建议将非常有帮助!
这是代码(它也可以在GitHub上找到:https://github.com/derpoliuk/SO-AudioToolbox-error-quesion):
class Recorder {
static let shared = Recorder()
private static let sampleRate: Float64 = 16000
var processAudioData: ((Data) -> ())?
fileprivate var remoteIOUnit: …
Run Code Online (Sandbox Code Playgroud) audio ×2
cocoa-touch ×2
audiotoolbox ×1
cocoa ×1
ios ×1
iphone ×1
objective-c ×1
swift ×1
video ×1
xcode ×1