[当我使用AVAssetWriterInput时,readyForMoreMediaData的值始终为NO,但是为什么呢?

问题描述 投票:0回答:1

[当我使用AVFoundation录制视频时,视频没有音轨,此代码发生了什么?readyForMoreMediaData的值始终返回no,'appendSampleBuffer:'方法不执行...?

1.
AVAssetWriterInput *audioWriterInput = [self audioWriterInput];
if ([self.assetWriter canAddInput:audioWriterInput]) {
    [self.assetWriter addInput:audioWriterInput];
}
2.
- (AVAssetWriterInput *)audioWriterInput {
    NSDictionary *audioCompressionSettings =
  @{
        AVEncoderBitRatePerChannelKey:@(28000),
        AVFormatIDKey : @(kAudioFormatMPEG4AAC),
        AVNumberOfChannelsKey : @(1),
        AVSampleRateKey : @(22050)
  };
    AVAssetWriterInput *audioWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioCompressionSettings];
    audioWriterInput.expectsMediaDataInRealTime = YES;
    self.audioWriterInput = audioWriterInput;
    return audioWriterInput;
}
3.
- (void)appendingAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer {
    // readyForMoreMediaData is always return NO
    if(self.audioWriterInput.readyForMoreMediaData) {
        BOOL success = [self.audioWriterInput appendSampleBuffer:sampleBuffer];
        if (success) {
            NSLog(@"");
        } else {

        }
    }
}
avfoundation
1个回答
0
投票

我真是个傻孩子。我使用的吸气剂方法错误!!!>

© www.soinside.com 2019 - 2024. All rights reserved.