2011-06-17 18 views
1

我正在使用AVAssetWriterInput從用戶獲取mp3文件併發送電子郵件(僅限DRM自由)。當使用PCM時,我得到了這個過程,但是當我嘗試mp3,或者m4a或caf時,我得到的文件不起作用,或者我得到空的數據。我認爲這是由於我的輸出設置。下面不使用數據的輸出設置如下。我願意改變這一切。謝謝!AVAssetWriterInput輸出設置不呈現有效NSData

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

回答

2

蘋果沒有提供API來編寫MP3文件,也許是因爲MP3僅僅是頭部信息的數據包,並簡單地寫出來的原始數據包正常工作。

至於在m4a/caf容器中寫出AAC數據,我不確定 - 但是AVEncoderBitRateKey絕對不應該存在,因爲你沒有編碼任何東西 - 你只是傳遞數據。那麼爲什麼不忘記AVAssetWriter,並使用AVAssetExportSession和passthrough預設?

+0

非常感謝!我使用AVAssetExportSession工作,但它非常慢。後臺線程需要永久啓動。這是常見的嗎? – nicholjs