2011-07-31 29 views
0

是否可以使用AVAssetWriter在ios上編寫MPEG2 ADTS或AAC ADTS?使用AVAssetWriter在iPhone上創建MPEG-2或AAC ADTS

首先我做一個AVAssetWriter

assetWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:filePath] 
                   fileType:AVFileTypeCoreAudioFormat 
                    error:&er]; 

然後我做的輸入使用的是什麼,我懷疑是正確的設置,並試圖將其添加到作家,但無濟於事:

AudioChannelLayout channelLayout; 
memset(&channelLayout, 0, sizeof(AudioChannelLayout)); 
channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo; 
NSDictionary *outputSettings = 
[NSDictionary dictionaryWithObjectsAndKeys: 
[NSNumber numberWithInt:kAudioFormatMPEGLayer2], AVFormatIDKey, 
[NSNumber numberWithFloat:44100.0], AVSampleRateKey, 
[NSNumber numberWithInt:2], AVNumberOfChannelsKey, 
[NSNumber numberWithInt:128000], AVEncoderBitRateKey, 
[NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey, 
nil]; 

assetWriterInput = [[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeAudio 
                outputSettings:outputSettings]; 
assetWriterInput.expectsMediaDataInRealTime = NO; 

if ([assetWriter canAddInput:assetWriterInput]) { 
    [assetWriter addInput:assetWriterInput]; 
} else { 
    NSLog (@"can't add asset writer input."); 
} 

回答

1

這裏是我的工作設置爲aac

AudioChannelLayout channelLayout; 
    memset(&channelLayout, 0, sizeof(AudioChannelLayout)); 
    channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo; 

    AVAssetWriter *assetWriter = [[AVAssetWriter assetWriterWithURL:exportURL 
                  fileType:AVFileTypeMPEG4 

                   error:&assetError] retain]; 

    NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
            [ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey, 
            [ NSNumber numberWithInt: 2 ], AVNumberOfChannelsKey, 
            [ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey, 
            [NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey, 
            [ NSNumber numberWithInt: 128000 ], AVEncoderBitRateKey,nil]; 
+1

請注意,它是MPEG4,而不是MPEG2。 –

相關問題