public static Mp4Box CreateMp4Box(byte[] buffer, int offset) { if ((buffer != null) && (offset + 8 < buffer.Length)) { Mp4Box box = CreateMp4BoxFromType(ReadMp4BoxType(buffer, offset)); if (box != null) { box.Length = ReadMp4BoxLength(buffer, offset); if ((offset + box.Length <= buffer.Length) && (box.Length > 8)) { box.Type = ReadMp4BoxType(buffer, offset); box.SetPath("/" + box.GetBoxType()); box.Data = ReadMp4BoxData(buffer, offset, box.Length); List <Mp4Box> list = box.GetChildren(); if ((list != null) && (list.Count > 0)) { foreach (var b in list) { box.AddMp4Box(b); } } return(box); } } } return(null); }
public bool AddMp4Box(Mp4Box box, bool bAddInData = false) { if (Children == null) { Children = new List <Mp4Box>(); } if (Children != null) { box.SetParent(this); box.SetPath(this.GetPath() + "/" + box.GetBoxType()); Children.Add(box); if (bAddInData == true) { Append(box.Data); } return(true); } return(false); }
public static bool WriteMp4Box(Mp4Box box, FileStream fs) { bool result = false; if ((box != null) && (fs != null)) { try { byte[] header = new byte[8]; Mp4Box.WriteMp4BoxInt32(header, 0, box.Length); Mp4Box.WriteMp4BoxString(header, 4, box.GetBoxType()); fs.Write(header, 0, 8); fs.Write(box.Data, 0, box.Data.Length); result = true; } catch (Exception ex) { System.Diagnostics.Debug.Write("Exception while writing box in file: " + ex.Message); } } return(result); }