如果已经回答,请道歉。我见过很多问题,但没有好的答案。
我正在尝试将立体声音乐从我的iPod库导出到两个单声道文件。我怎么能在iOS上这样做?我目前正在使用Objective C。
谢谢!
更新:我已经设法从这里的苹果获取示例代码:https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/05_Export.html
我的代码现在将导入媒体文件并输出为有效的caf文件,该文件播放正常。我的问题是我无法解决如何在写入之前修改缓冲区。这是我到目前为止的代码:
// Get the next audio sample buffer, and append it to the output file.
CMSampleBufferRef sampleBuffer = [self.assetReaderAudioOutput copyNextSampleBuffer];
if (sampleBuffer != NULL)
{
/////////////////////////////////////////
CMBlockBufferRef blockBuffer;
AudioBufferList audioBufferList;
NSMutableData *data= [NSMutableData data];
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(AudioBufferList), NULL, NULL, kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, &blockBuffer);
AudioBuffer audioBuffer = audioBufferList.mBuffers[0];
for( int y=0; y< audioBufferList.mNumberBuffers; y=y+4 ){
[data appendBytes:(audioBuffer.mData+y) length:2];
}
// how do I replace data in sampleBuffer with new data?
CFRelease(blockBuffer);
//////////////////////////////////////////
BOOL success = [self.assetWriterAudioInput appendSampleBuffer:sampleBuffer];
CFRelease(sampleBuffer);
sampleBuffer = NULL;
completedOrFailed = !success;
}
else
{
completedOrFailed = YES;
}
答案 0 :(得分:1)
我设法通过手动创建标题并写入文件来完成此操作。这篇文章给了我所需的大部分内容:https://stackoverflow.com/a/8677726/313272