objective-c - objective-c - 将 mpmediaitem 转换为 ogg vorbis
<p><p>我找到(自定义我找到的方法)一种转换 MpMediaItem 并获取 mp3 文件的方法。可能这不是最好的方法,但它确实有效。</p>
<p>有没有办法获得 *.ogg 文件而不是 *.mp3 ?什么是正确的方法?</p>
<p>这是我用来获取 *.mp3 文件的方法:</p>
<pre><code> -(void)exportMP3:(NSURL*)url toFileUrl:(NSString*)fileURL
{
AVURLAsset *asset=[ initWithURL:url options:nil];
AVAssetReader *reader=[ initWithAsset:asset error:nil];
NSMutableArray *myOutputs =[ init];
for(id track in )
{
AVAssetReaderTrackOutput *output=;
;
;
}
;
NSFileHandle *fileHandle ;
NSFileManager *fm=;
if(!)
{
init] attributes:nil];
}else{
NSURL *url = ;
;
init] attributes:nil];
}
fileHandle=;
;
AVAssetReaderOutput *output=;
int totalBuff=0;
int test = 1;
while(test == 1)
{
CMSampleBufferRef ref=;
if(ref==NULL)
test = 0;
if(ref==NULL)
break;
//copy data to file
//read next one
AudioBufferList audioBufferList;
NSMutableData *data;
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(ref, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
for( int y=0; y<audioBufferList.mNumberBuffers; y++ )
{
AudioBuffer audioBuffer = audioBufferList.mBuffers;
void *frame = audioBuffer.mData;
data = [ initWithBytes:frame length:audioBuffer.mDataByteSize];
}
totalBuff++;
NSLog(@"\n%d\n",totalBuff);
int time = ;
if (totalBuff * 2 <= time + 1)
;
}
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以使用 <a href="http://xiph.org/vorbis/" rel="noreferrer noopener nofollow">libvorbis</a>将 PCM 数据编码为 Vorbis。</p></p>
<p style="font-size: 20px;">关于objective-c -objective-c- 将 mpmediaitem 转换为 ogg vorbis,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/12526754/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/12526754/
</a>
</p>
页:
[1]