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, TagType = TagType.DATA,
Data = Header.ToBytes() Data = Header.ToBytes()
}; };
var b = t.ToBytes(true); t.WriteTo(fs);
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);
int timestamp = Tags[0].TimeStamp; HTags.ForEach(tag => tag.WriteTo(fs));
Tags.ForEach(tag => tag.WriteTo(fs));
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);
});
fs.Close(); fs.Close();
} }

View File

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

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -30,5 +31,14 @@ namespace BililiveRecorder.FlvProcessor
return tag; 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);
}
} }
} }