2017-04-24 64 views
2

我試圖通過this規範製作一個工具來編輯和嵌入mp3文件中的章節標記(用於播客)。如何在C#中的mp3文件中嵌入章節元數據?

到目前爲止,我發現的所有庫都不支持CHAP或CTOC框架,我也無法找出使它們適用於自定義框架的方法。 NTagLite似乎是我迄今爲止最喜歡的,但是我在構建VS2017源代碼時遇到問題,無法在我自己的方法中嘗試拼接不同的幀類型,並且在一天結束時,我不是一個非常高級的程序員,所以使用ByteStream手動是有點超過我的頭。

有沒有人知道一種方法來實現這一目標?有經驗的人在這裏?我是否錯過了這些庫中的調用,並且這些功能已經在那裏了?

回答

0

如果你找不到能爲你做到這一點的圖書館,你可以自己做。首先,定義一些對象,它封裝了ID3標籤的章節相關的元數據/幀:

public class ChapterFrame : Frame 
{ 
    private Header Header { get; set; } 
    private string ElementId { get; set; } 
    private TimeSpan StartTime { get; set; } 
    private TimeSpan EndTime { get; set; } 
    private TimeSpan StartOffset { get; set; } 
    private TimeSpan EndOffset { get; set; } 
    private List<ChapterFrame> Subframes = new List<ChapterFrame>(); 
} 

然後寫一些方法(類似於ChapterFrame.ToByteArray()):

public byte[] ToByteArray(ChapterFrame frame) { 
    return new byte[]; 
} 

...這需要每個ChapterFrame的的字段和變平出來成字節的序列化陣列,符合的與ID3 V2.3/2.4章幀編標準:

from "ID3v2 Chapter Frame Addendum", C. Newell, 2 December 2005

現在您已經有了一個新框架,您可以掃描ID3標籤以確定插入新框架的位置。

請注意,我絕對不是這裏的專家 - 這只是一個猜測。

0

用於.NET的音頻工具庫(https://github.com/Zeugma440/atldotnet)的最新版本支持ID3v2章節(CTOC/CHAP幀)讀取和寫入。

using System; 
using ATL.AudioData; 
using System.Collections.Generic; 

AudioDataManager theFile = new AudioDataManager(AudioData.AudioDataIOFactory.GetInstance().GetDataReader(<fileLocation>)); 

Dictionary<uint, ChapterInfo> expectedChaps = new Dictionary<uint, ChapterInfo>(); 
TagData theTag = new TagData(); 
theTag.Chapters = new List<ChapterInfo>(); 
expectedChaps.Clear(); 

ChapterInfo ch = new ChapterInfo(); 
ch.StartTime = 123; 
ch.StartOffset = 456; 
ch.EndTime = 789; 
ch.EndOffset = 101112; 
ch.UniqueID = ""; 
ch.Title = "aaa"; 
ch.Subtitle = "bbb"; 
ch.Url = "ccc\0ddd"; 

theTag.Chapters.Add(ch); 
expectedChaps.Add(ch.StartTime, ch); 

ch = new ChapterInfo(); 
ch.StartTime = 1230; 
ch.StartOffset = 4560; 
ch.EndTime = 7890; 
ch.EndOffset = 1011120; 
ch.UniqueID = "002"; 
ch.Title = "aaa0"; 
ch.Subtitle = "bbb0"; 
ch.Url = "ccc\0ddd0"; 

theTag.Chapters.Add(ch); 
expectedChaps.Add(ch.StartTime, ch); 

// Persists the chapters 
theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_ID3V2); 

// Reads them 
theFile.ReadFromFile(null, true); 

foreach (ChapterInfo chap in theFile.ID3v2.Chapters) 
{ 
    System.Console.WriteLine(chap.Title + "(" + chap.StartTime + ")"); 
} 
:從下面的維基

示例代碼

相關問題