本文整理汇总了C#中Atom.Find方法的典型用法代码示例。如果您正苦于以下问题:C# Atom.Find方法的具体用法?C# Atom.Find怎么用?C# Atom.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Atom
的用法示例。
在下文中一共展示了Atom.Find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mp4Hash
public static void Mp4Hash(string inpath, string outpath)
{
FileInfo f = new FileInfo(inpath);
Stream i = File.OpenRead(inpath);
BinaryReader reader = new BinaryReader(i);
Stream o = File.Open(outpath,FileMode.Create,FileAccess.Write);
BinaryWriter writer = new BinaryWriter(o);
Atom atm =new Atom();
atm.Size = f.Length+8;
atm.Read(reader);
atm.RemoveAll(d => d.Name == "free");
Atom mdat = atm.Find(d => d.Name == "mdat");
long original = mdat.Position;
atm.Remove(mdat);
atm.Add(mdat);
Atom fnd= atm.Find(d => d.Name == "moov");
fnd.RemoveAll(d => d.Name == "udta");
fnd.ReCalcSize();
atm.ReCalcPosition();
//Relocate
foreach (Atom a in fnd)
{
a.ReadData(reader);
byte[] nm=new byte[4];
byte[] nm2 = new byte[8];
for (int x = 0; x < a.Size - 16;x++)
{
Array.Copy(a.Data,x,nm,0,4);
string name = Encoding.ASCII.GetString(nm);
if ((name == "stco") && (x-4>=0))
{
Array.Copy(a.Data,x-4,nm,0,4);
Array.Reverse(nm);
uint size = BitConverter.ToUInt32(nm, 0);
if (size + x + 4 > a.Size)
continue;
Array.Copy(a.Data,x+8,nm, 0,4);
Array.Reverse(nm);
uint cnt = BitConverter.ToUInt32(nm, 0);
if (x+12+cnt*4>a.Size)
continue;
for (int j = 0; j < cnt; j++)
{
Array.Copy(a.Data,x+12+j*4,nm,0,4);
Array.Reverse(nm);
int offset = BitConverter.ToInt32(nm, 0);
offset += (int)(mdat.ExpectedPosition-original);
byte[] ne = BitConverter.GetBytes(offset);
Array.Reverse(ne);
Array.Copy(ne,0,a.Data,x+12+j*4,4);
}
}
else if ((name == "co64") && (x - 4 >= 0))
{
Array.Copy(a.Data, x - 4, nm, 0, 4);
Array.Reverse(nm);
uint size = BitConverter.ToUInt32(nm, 0);
if (size + x + 4 > a.Size)
continue;
Array.Copy(a.Data, x + 8, nm, 0, 4);
Array.Reverse(nm);
uint cnt = BitConverter.ToUInt32(nm, 0);
if (x + 12 + cnt * 8 > a.Size)
continue;
for (int j = 0; j < cnt; j++)
{
Array.Copy(a.Data, x + 12 + j * 8, nm2, 0, 8);
Array.Reverse(nm2);
long offset = BitConverter.ToInt64(nm2, 0);
offset += (long)(mdat.ExpectedPosition - original);
byte[] ne = BitConverter.GetBytes(offset);
Array.Reverse(ne);
Array.Copy(ne, 0, a.Data, x + 12 + j * 8, 8);
}
}
}
}
foreach (Atom a in atm)
a.Write(writer);
writer.Close();
reader.Close();
o.Close();
i.Close();
}