Does AVAssetReader not read the entire file?

I am reading audio resources from the iPod library on iOS using AVAssetReader and AVAssetReaderTrackOutput. However, when I read the data and return the pieces, the file is not exactly the same. Several kB are absent, and therefore the sound file does not play.

Here is the code that I use to extract 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);
UInt8 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?

+3
source share
1 answer

Yes, I guessed. copyNextSampleBufferomits the AAC header, so the media player API cannot process the file.

You can copy the stream description in other ways.

0
source

Source: https://habr.com/ru/post/1772519/


All Articles