我无法使用iPhone上的avassetwriter将音频录制到视频中。我可以在手机上录制来自摄像头的视频没有问题,但是当我尝试添加音频时,我什么都没有收到,而且相册应用中的视频显示的内容也显示出了一些真正的问题,4秒的视频将会显示15:54:01或类似的东西,即使视频较短,编号后的每个视频都会增加。我一直在试图追寻其他问题,但没有运气。AVAssetWriter不记录音频
继承人设置了AVAssetWriter如何IM
videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:MOVIE_PATH] fileType:AVFileTypeQuickTimeMovie error:&error];
AudioChannelLayout acl;
bzero(&acl, sizeof(acl));
acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
NSDictionary* audioOutputSettings = audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey,
[ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
[ NSData dataWithBytes: &acl length: sizeof(acl) ], AVChannelLayoutKey,
[ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey,
nil];
然后在这里是如何我写使用CMSampleBufferRef音频采样缓冲器发送我怎么设置我的音频输入
captureSession = [[AVCaptureSession alloc] init];
//set up audio input
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error ];
audioOutput = [[AVCaptureAudioDataOutput alloc] init];
if([captureSession canAddOutput:audioOutput])
{
[captureSession addOutput:audioOutput];
}
[audioOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
继承人通过audioOutput回拨
- (void) captureAudio:(CMSampleBufferRef)sampleBuffer
{
if([audioWriterInput isReadyForMoreMediaData]){
[audioWriterInput appendSampleBuffer:sampleBuffer];
}
}
会真的很赞任何帮助,我一直在这一天卡住。
嘿,你找到答案了吗? – 2013-03-24 12:33:56