2012-08-09 79 views
3

我需要將flac文件拆分爲很多部分。我使用jFLAC圖書館閱讀FLAC文件jFLAC。拆分FLAC文件

FLACDecoder decoder = new FLACDecoder(inputStream); 

然後我試圖以SeekPoints

decoder.decode(seekPointFrom, seekPointTo); 

之間的父文件進行解碼我也不太明白如何正確地得到這個seekpoints用於秒值。例如,我需要從0秒和秒到150秒的第一個查找點。如何獲得正確的尋求點對象? Seekpoint cinstructor是

/** 
* The constructor. 
* @param sampleNumber The sample number of the target frame 
* @param streamOffset The offset, in bytes, of the target frame with respect to beginning of the first frame 
* @param frameSamples The number of samples in the target frame 
*/ 
public SeekPoint(long sampleNumber, long streamOffset, int frameSamples) { 
    this.sampleNumber = sampleNumber; 
    this.streamOffset = streamOffset; 
    this.frameSamples = frameSamples; 
} 

解碼器還有一些偵聽器來偵聽每個讀取的塊動作。

@Override 
    public void processPCM(ByteData pcm) { 
     try { 
      outputStream.write(pcm.getData(), 0, pcm.getLen()); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

當書寫時我綁打新FLAC文件,但該文件不正確我的播放器警報。我需要做什麼,我的flac文件將打開權利?也許我需要爲這個文件或其他東西寫一些頭文件?

+0

您應該在[jFLAC郵件列表](http://jflac.sourceforge.net/mail-lists.html)上提問, – 2012-08-09 18:37:12

回答

0

關於FLAC SeekPoints,不能保證會有一個對應於給定的秒 - 在整個音頻文件中可能只有幾個SeekPoints。

因此,我最近更新jFLAC具有搜索功能,讓你至少最接近的音頻幀: https://github.com/nguillaumin/jflac/commit/585940af97157eb11b60c15cc8cb13ef3fc27ce3

在問候寫出一個新的文件,解碼後的數據將是原始PCM樣本。因此,如果您需要一個有效的FLAC文件作爲輸出,您將需要將其傳送到FLAC編碼器。或者,您可以寫出Wave標題並轉儲原始PCM樣本,然後將生成的Wave文件轉換爲FLAC文件。