- srt字幕格式
srt字幕包含多个字幕段,每个字幕段由以下几部分组成:
字幕序号
字幕起止时间
字幕内容(可多行)
空白行
例如:
222
00:09:03,560 --> 00:09:04,940
他怎么会来这里
223
00:09:04,950 --> 00:09:06,300
我捡到了他的狗
2.srt字幕文件解析
此处的解析只保存了字幕里面一行的内容
public class SubtitleBlock
{
public int Index {
get; private set; }
public double Length {
get; private set; }
public double From {
get; private set; }
public double To {
get; private set; }
public string Text {
get; private set; }
public SubtitleBlock(int index, double from, double to, string text)
{
this.Index = index;
this.From = from;
this.To = to;
this.Length = to - from;
this.Text = text;
}
public override string ToString()
{
return "Index: " + Index + " From: " + From + " To: " + To + " Text: " + Text;
}
static public List<SubtitleBlock> ParseSubtitles(string content)
{
var subtitles = new List<SubtitleBlock>();
var regex = new Regex($@"(?<index>\d*\s*)\n(?<start>\d*:\d*:\d*,\d*)\s*-->\s*(?<end>\d*:\d*:\d*,\d*)\s*\n(?<content>.*)\n(?<content2>.*)\n")