Reputation: 5113
I've set up an AVAssetExportSession
with just 2 tracks of audio and no video, which plays just like I want it to in the AVPlayer
- but as I go to export it, the only available outputFileType
is AVFileTypeQuickTimeMovie
- Why can't I choose an audio format?
When I NSLog(@"%@", [session supportedFileTypes]);
i get;
[51330:c07] (
"com.apple.quicktime-movie"
)
Here is my code;
- (AVMutableComposition *)getComposition {
AVAsset *backingAsset = [AVAsset assetWithURL:self.urlForEightBarAudioFile];
AVAsset *vocalsAsset = [AVAsset assetWithURL:self.recorder.url];
AVMutableComposition *composition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionBackingTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionVocalTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *backingAssetTrack = [backingAsset.tracks objectAtIndex:0];
AVAssetTrack *vocalsAssetTrack = [vocalsAsset.tracks objectAtIndex:0];
CMTimeRange timeRange = CMTimeRangeFromTimeToTime(kCMTimeZero, backingAsset.duration);
[compositionBackingTrack insertTimeRange:timeRange ofTrack:backingAssetTrack atTime:kCMTimeZero error:nil];
[compositionVocalTrack insertTimeRange:timeRange ofTrack:vocalsAssetTrack atTime:kCMTimeZero error:nil];
return composition;
}
- (IBAction)acceptRecording:(id)sender {
AVAssetExportSession * session = [[AVAssetExportSession alloc] initWithAsset:[self getComposition] presetName:AVAssetExportPresetMediumQuality];
NSURL *output = [self.urlForPathToEightBarRecordings URLByAppendingPathComponent:@"mix.mov"];
session.outputURL = output;
session.outputFileType = AVFileTypeQuickTimeMovie;
NSLog(@"%@", [session supportedFileTypes]);
[session exportAsynchronouslyWithCompletionHandler:^() {
switch (session.status) {
case AVAssetExportSessionStatusCompleted:
NSLog(@"It's done...hallelujah");
break;
default:
break;
}
}];
}
Upvotes: 4
Views: 6420
Reputation: 1045
You can use these settings for 128kbps
Preset time: AVAssetExportPresetMediumQuality
OutputfileType AVFileTypeMPEG
format: mp4
Upvotes: 0
Reputation: 5113
Ah right so the reason why it was only giving me the option of quicktime movie was because my preset was set to AVAssetExportPresetMediumQuality
which is a video only preset I guess. I set my preset to AVAssetExportPresetAppleM4A
and the output file type to AVFileTypeAppleM4A
and export was a success!
Upvotes: 7