This commit is contained in:
Genteure 2018-03-24 08:41:29 +08:00
parent 222879c1ce
commit fc9434c5cb
3 changed files with 15 additions and 30 deletions

View File

@ -52,29 +52,10 @@ namespace BililiveRecorder.FlvProcessor
TagType = TagType.DATA,
Data = Header.ToBytes()
};
var b = t.ToBytes(true);
fs.Write(b, 0, b.Length);
fs.Write(t.Data, 0, t.Data.Length);
fs.Write(BitConverter.GetBytes(t.Data.Length + b.Length).ToBE(), 0, 4);
t.WriteTo(fs);
int timestamp = Tags[0].TimeStamp;
HTags.ForEach(tag =>
{
var vs = tag.ToBytes(true);
fs.Write(vs, 0, vs.Length);
fs.Write(tag.Data, 0, tag.Data.Length);
fs.Write(BitConverter.GetBytes(tag.Data.Length + vs.Length).ToBE(), 0, 4);
});
Tags.ForEach(tag =>
{
tag.TimeStamp -= timestamp;
var vs = tag.ToBytes(true);
fs.Write(vs, 0, vs.Length);
fs.Write(tag.Data, 0, tag.Data.Length);
fs.Write(BitConverter.GetBytes(tag.Data.Length + vs.Length).ToBE(), 0, 4);
});
HTags.ForEach(tag => tag.WriteTo(fs));
Tags.ForEach(tag => tag.WriteTo(fs));
fs.Close();
}

View File

@ -143,10 +143,7 @@ namespace BililiveRecorder.FlvProcessor
// TODO: 添加录播姬标记、录制信息
tag.Data = Metadata.ToBytes();
var b = tag.ToBytes(true);
_fs.Write(b, 0, b.Length);
_fs.Write(tag.Data, 0, tag.Data.Length);
_fs.Write(BitConverter.GetBytes(tag.Data.Length + b.Length).ToBE(), 0, 4);
tag.WriteTo(_fs);
}
else
{
@ -218,10 +215,7 @@ namespace BililiveRecorder.FlvProcessor
// Tags.RemoveAll(x => (MaxTimeStamp - x.TimeStamp) > (Clip_Past * SEC_TO_MS));
// 写入硬盘
var b = tag.ToBytes(true);
_fs.Write(b, 0, b.Length);
_fs.Write(tag.Data, 0, tag.Data.Length);
_fs.Write(BitConverter.GetBytes(tag.Data.Length + b.Length).ToBE(), 0, 4); // Last Tag Size
tag.WriteTo(_fs);
TagProcessed?.Invoke(this, new TagProcessedArgs() { Tag = tag });
} // if (Metadata == null) else

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@ -30,5 +31,14 @@ namespace BililiveRecorder.FlvProcessor
return tag;
}
public void WriteTo(Stream stream)
{
var vs = ToBytes(true);
stream.Write(vs, 0, vs.Length);
stream.Write(Data, 0, Data.Length);
stream.Write(BitConverter.GetBytes(Data.Length + vs.Length).ToBE(), 0, 4);
}
}
}