Using AVSampleRateKey in outputSettings for AVAssetReaderTrackOutput
Using AVSampleRateKey in outputSettings for AVAssetReaderTrackOutput
- Subject: Using AVSampleRateKey in outputSettings for AVAssetReaderTrackOutput
- From: Simon Haycock <email@hidden>
- Date: Sat, 12 Jan 2013 14:17:51 +0000
Hi Guys.
I have had a good poke around regarding this issue, and I am stumped. I get an NSInvalidArguementException when setting the value for AVSampleRateKey in the outputSettings dictionary when adding a track to an AVAssetReaderTrackOutput. The comment in the console is:
'*** -[AVAssetReaderTrackOutput initWithTrack:outputSettings:] AVAssetReaderTrackOutput does not currently support AVSampleRateKey, AVNumberOfChannelsKey, or AVChannelLayoutKey'
If I comment out the setting of AVSampleRateKey, the AVAssetReaderTrackOutput is initialised fine, and getting PCM data from the AVAssetReader and subsequently playing those samples out to speakers works as it should without any issues. But if I load a .wav / .mp3 at a different sample rate to the hardware sample rate, the audio is obviously heard slower / faster than it should be, therefore I want to be able to set AVSampleRateKey so that sample rate conversion occurs when loading the PCM data. Should setting the AVSampleRateKey allow this to happen?
Interestingly, in the older documentation (from around 1 year ago), the AVAssetReaderTrackOutput reference states exactly the same comment about not currently supporting those keys which are mentioned in the console output (the old doc, by some strange chance, is here: http://disanji.net/iOS_Doc/#documentation/AVFoundation/Reference/AVAssetReaderTrackOutput_Class/Reference/Reference.html ). After I updated Xcode to 4.5.2 (and subsequently the documentation), the comment in the AVAssetReaderTrackOutput reference regarding lack of support for AVSampleRateKey is no longer there (https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVAssetReaderTrackOutput_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009691). However, the changes made seem to imply more ambiguity as to what should work, and what should not.
I have seen several other examples where people have set the AVSampleRateKey with no problems, so I am wondering if it's just me. Any chance someone who has successfully performed a sample rate conversion in a read scenario using AVAssetReader can send me their AVFoundation.framework? It may just be my framework that is out of date...
Here are the rest of my audio read settings and subsequent AVFoundation calls. :
audioReadSettings = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithInt:(32)], AVLinearPCMBitDepthKey, // 32 bits per sample
[NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:YES], AVLinearPCMIsFloatKey,
[NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
/* [NSNumber numberWithFloat:44100.0], AVSampleRateKey, */ // currently not supported
nil];
NSURL *fileURL = [NSURL fileURLWithPath:absolutePath]; // absolute path is the path of my audio file/
audioAsset = [AVURLAsset URLAssetWithURL:fileURL options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]];
trackArray = [[audioAsset tracksWithMediaType:AVMediaTypeAudio] retain];
track = [[trackArray objectAtIndex:0] retain];
AVAssetReaderTrackOutput *readerOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:track outputSettings:audioReadSettings];
Any ideas? Many thanks for reading if you have gotten this far!
Simon
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden