1

几周前,我发布了这个关于我在使用 AVAssetWriter 时遇到的问题的帖子:AVAssetWriter Woes

进一步的研究似乎会导致使用 AVAssetWriter 在使用 AVAudioPlayer 播放音频时发生冲突,或者实际上是任何音频系统。我也尝试过使用 OpenAL。

这是背景:

  • 使用 AVAssetWriter 将帧从图像或图像集写入视频可以正常工作,直到调用 [AVAudioPlayer play]。

  • 这只发生在设备上,而不是 SIM 卡上。

  • 尝试从 CVPixelBufferPoolCreatePixelBuffer 创建像素缓冲区时发生错误。

  • 一旦音频开始播放,之前存在的 AVAssetWriterInputPixelBufferAdaptor.pixelBufferPool 突然变为 nil。

您可以在这里下载代表项目:http ://www.mediafire.com/?5k7kqyvtbfdgdgv

注释掉 AVAudioPlayer 播放,它将在设备上运行。

任何线索表示赞赏。

4

2 回答 2

0

我找到了解决这个问题的方法。

如果您想让 AVAudioPlayer 和 AVAssetWriter 一起正确运行,则必须具有“可混合”的音频会话类别。

您可以使用可混合的类别,例如 AVAudioSessionCategoryAmbient。

但是,我需要使用 AVAudioSessionCategoryPlayAndRecord。

您可以通过实现以下方式将任何类别设置为可混合:

OSStatus propertySetError = 0;

UInt32 allowMixing = true;

propertySetError = AudioSessionSetProperty (
                       kAudioSessionProperty_OverrideCategoryMixWithOthers,  // 1
                       sizeof (allowMixing),                                 // 2
                       &allowMixing                                          // 3
                   );
于 2011-07-24T16:43:31.820 回答
0

上面这个答案是完整的。它不起作用。改为这样做

// Setup to be able to record global sounds (preexisting app sounds)
    NSError *sessionError = nil;
    if ([[AVAudioSession sharedInstance] respondsToSelector:@selector(setCategory:withOptions:error:)])
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDuckOthers error:&sessionError];
    else
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];

    // Set the audio session to be active
    [[AVAudioSession sharedInstance] setActive:YES error:&sessionError];

//then call your asset writer 
movieWriter = [[AVAssetWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
于 2014-01-19T16:57:39.660 回答