开发者

AVAssetReader doesn't read whole file?

I am reading audio assets from the iPod library on iOS with an AVAssetReader and AVAssetReaderTrackOutput. However, when i read the data and put the chunks back together, the file isn't exactly the same. A few kB are missing, and therefore the audio file won't play back.

Here is the code i use to extract the audio data

// Copy next audio samples
CMSampleBufferRef buffer = [[reader_.outputs objectAtIndex:0] copyNextSampleBuffer];

// Extract bytes from buffer
CMBlockBufferRef dataBuffer = CMSampleBufferGetDataBuffer(buffer);

size_t bufLen = CMBlockBufferGetDataLength(dataBuffer);
UI开发者_运维百科nt8 buf[bufLen];

CMBlockBufferCopyDataBytes(dataBuffer, 0, bufLen, buf);

// Pass data to delegate
if ([delegate respondsToSelector:@selector(assetStream:hasDataAvailable:)]) {
    [delegate assetStream:self hasDataAvailable:[NSData dataWithBytes:buf length:bufLen]];
}

// Invalidate buffer
CMSampleBufferInvalidate(buffer);

What am I doing wrong here?


Yep I guessed right. The copyNextSampleBuffer does omit the AAC header, and therefore the media player API can't process the file.

You can copy the stream description with other methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜