问题
I have been successfull in making viedo (though Blur) but have been Unsuccessful in recording audio Please Help.
I am using the following code Pls go through it ans suggest some solution or a working tutorial.
I am Appending the Sample Buffer using
[encoder._writerInput appendSampleBuffer:sampleBuffer];
And The App Crashes When the following statement is called
[encoder.audioWriterInput appendSampleBuffer:sampleBuffer];
- (void) initPath:(NSString*)path Height:(int) height andWidth:(int) width bitrate:(int)bitrate
{
self.path = path;
_bitrate = bitrate;
[[NSFileManager defaultManager] removeItemAtPath:self.path error:nil];
NSURL* url = [NSURL fileURLWithPath:self.path];
//Initialize Video Writer
_writer = [AVAssetWriter assetWriterWithURL:url fileType:AVFileTypeMPEG4 error:nil];
//Initialize Audio writer
// audioWriter = [AVAssetWriter assetWriterWithURL:url fileType:AVFileTypeCoreAudioFormat error:nil];
// NSDictionary* settings = @{
// AVVideoCodecKey: AVVideoCodecH264,
// AVVideoWidthKey: @(width),
// AVVideoHeightKey: @(height),
// AVVideoCompressionPropertiesKey: @{
// AVVideoAverageBitRateKey: @(self.bitrate),
// AVVideoMaxKeyFrameIntervalKey: @(150),
// AVVideoProfileLevelKey: AVVideoProfileLevelH264BaselineAutoLevel,
// AVVideoAllowFrameReorderingKey: @NO,
// //AVVideoH264EntropyModeKey: AVVideoH264EntropyModeCAVLC,
// //AVVideoExpectedSourceFrameRateKey: @(30),
// //AVVideoAverageNonDroppableFrameRateKey: @(30)
// }
// };
NSDictionary* settings = @{
AVVideoCodecKey: AVVideoCodecH264,
AVVideoWidthKey: [NSNumber numberWithInt:width],
AVVideoHeightKey: [NSNumber numberWithInt:height],
AVVideoCompressionPropertiesKey: @{
AVVideoAverageBitRateKey: [NSNumber numberWithInt:bitrate],
AVVideoMaxKeyFrameIntervalKey: @(150),
AVVideoProfileLevelKey: AVVideoProfileLevelH264BaselineAutoLevel,
AVVideoAllowFrameReorderingKey: @NO,
AVVideoH264EntropyModeKey: AVVideoH264EntropyModeCAVLC,
AVVideoExpectedSourceFrameRateKey: @(30),
AVVideoAverageNonDroppableFrameRateKey: @(30)
}
};
AudioChannelLayout acl;
bzero( &acl, sizeof(acl));
acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
NSDictionary *audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[ NSNumber numberWithInt: kAudioFormatMPEG4AAC ], AVFormatIDKey,
[ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey,
[ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
[ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey,
[ NSData dataWithBytes: &acl length: sizeof( acl ) ], AVChannelLayoutKey,
nil];
audioWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioOutputSettings];
audioWriterInput.expectsMediaDataInRealTime=YES;
_writerInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:settings];
_writerInput.expectsMediaDataInRealTime = YES;
[_writer addInput:audioWriterInput];
[_writer addInput:_writerInput];
}
来源:https://stackoverflow.com/questions/23216610/ios-avassetwriter-writes-video-but-does-not-record-audio