public List <int> GetListTrackToDecrypt() { List <int> result = new List <int>(); if (Children != null) { foreach (var box in Children) { if (box.GetBoxType() == "trak") { Mp4Box encbox = box.FindChildBox("encv"); if (encbox == null) { encbox = box.FindChildBox("enca"); if (encbox == null) { encbox = box.FindChildBox("enct"); } } if (encbox != null) { Mp4BoxTRAK trakbox = box as Mp4BoxTRAK; if (trakbox != null) { result.Add(trakbox.GetTrackID()); } } } } } return(result); }
public static Mp4Box CreateMp4Box(byte[] buffer, int offset) { if ((buffer != null) && (offset + 8 < buffer.Length)) { Mp4Box box = new Mp4Box(); if (box != null) { box.Length = ReadMp4BoxLength(buffer, offset); if ((offset + box.Length <= buffer.Length) && (box.Length > 8)) { box.Type = ReadMp4BoxType(buffer, offset); 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(box); } } return(box); } } } return(null); }
private static Mp4Box ReadMp4Box(FileStream fs) { Mp4Box box = null; if (fs != null) { byte[] buffer = new byte[4]; if (buffer != null) { if (fs.Read(buffer, 0, 4) == 4) { int mp4BoxLen = 0; mp4BoxLen |= (int)(buffer[0] << 24); mp4BoxLen |= (int)(buffer[1] << 16); mp4BoxLen |= (int)(buffer[2] << 8); mp4BoxLen |= (int)(buffer[3] << 0); if (mp4BoxLen >= 8) { buffer = new byte[mp4BoxLen]; if (buffer != null) { WriteMp4BoxInt32(buffer, 0, mp4BoxLen); if (fs.Read(buffer, 4, mp4BoxLen - 4) == (mp4BoxLen - 4)) { return(CreateMp4Box(buffer, 0)); } } } } } } return(box); }
public byte[] GetFTYPData() { ISMHelper.Mp4Box box = ISMHelper.Mp4Box.CreateFTYPBox(); if (box != null) { return(box.GetBoxBytes()); } return(null); }
public override byte[] GetMOOVData() { ISMHelper.Mp4Box box = ISMHelper.Mp4Box.CreateTextMOOVBox((Int16)TrackID, TimeScale, Duration, Language, ProtectionGuid, ProtectionData); if (box != null) { return(box.GetBoxBytes()); } return(null); }
public override byte[] GetMOOVData() { ISMHelper.Mp4Box box = ISMHelper.Mp4Box.CreateAudioMOOVBox((Int16)TrackID, MaxFramesize, Bitrate, BitsPerSample, SamplingRate, Channels, TimeScale, Duration, Language, CodecPrivateData, ProtectionGuid, ProtectionData); if (box != null) { return(box.GetBoxBytes()); } return(null); }
public override byte[] GetMOOVData() { ISMHelper.Mp4Box box = ISMHelper.Mp4Box.CreateVideoMOOVBox((Int16)TrackID, (Int16)Width, (Int16)Height, TimeScale, Duration, Language, CodecPrivateData, ProtectionGuid, ProtectionData); if (box != null) { return(box.GetBoxBytes()); } return(null); }
public virtual byte[] GetMFRAData(ulong OffsetWithVideo) { ISMHelper.Mp4Box box = ISMHelper.Mp4Box.CreateMFRABox((Int16)TrackID, ListTimeOffset, OffsetWithVideo); if (box != null) { return(box.GetBoxBytes()); } return(null); }
public bool UpdateEncBoxes() { bool result = false; if (Children != null) { foreach (var box in Children) { if (box.GetBoxType() == "trak") { Mp4Box encbox = box.FindChildBox("encv"); if (encbox != null) { encbox.SetBoxType("avc1"); Mp4Box sinfbox = box.FindChildBox("sinf"); if (sinfbox != null) { int Len = sinfbox.GetBoxLength(); UpdateParentLength(sinfbox, -Len); encbox.RemoveChildBox("sinf"); } } else { encbox = box.FindChildBox("enca"); if (encbox != null) { encbox.SetBoxType("mp4a"); Mp4Box sinfbox = box.FindChildBox("sinf"); if (sinfbox != null) { int Len = sinfbox.GetBoxLength(); UpdateParentLength(sinfbox, -Len); encbox.RemoveChildBox("sinf"); } } else { encbox = box.FindChildBox("enct"); if (encbox != null) { encbox.SetBoxType("dfxp"); Mp4Box sinfbox = box.FindChildBox("sinf"); if (sinfbox != null) { int Len = sinfbox.GetBoxLength(); UpdateParentLength(sinfbox, -Len); encbox.RemoveChildBox("sinf"); } } } } } } } return(result); }
public int GetTrackID() { Mp4Box box = FindChildBox("tkhd"); if (box != null) { Mp4BoxTKHD tkhdbox = box as Mp4BoxTKHD; if (tkhdbox != null) { return(tkhdbox.GetTrackID()); } } return(0); }
public bool UpdateMFHDSequence(int SequenceNumber) { bool result = false; Mp4Box box = FindChildBox("mfhd"); if (box != null) { Mp4BoxMFHD mfhdbox = box as Mp4BoxMFHD; if (mfhdbox != null) { return(mfhdbox.UpdateSequenceNumber(SequenceNumber)); } } return(result); }
public int GetTrackID() { int result = 0; Mp4Box box = FindChildBox("tfhd"); if (box != null) { Mp4BoxTFHD tfhdbox = box as Mp4BoxTFHD; if (tfhdbox != null) { return(tfhdbox.GetTrackID()); } } return(result); }
public static Mp4Box CreateEmptyMp4Box(string Type) { Mp4Box box = new Mp4Box(); if (box != null) { box.Length = 8; if (!string.IsNullOrEmpty(Type) && (Type.Length <= 4)) { box.Type = Type; return(box); } } return(null); }
public bool AddMp4Box(Mp4Box box, bool bAddInData = false) { if (Children == null) { Children = new List <Mp4Box>(); } if (Children != null) { Children.Add(box); if (bAddInData == true) { Append(box.Data); } return(true); } return(false); }
public static string ParseFile(string Path) { string result = "\r\n"; try { FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read); if (fs != null) { long offset = 0; fs.Seek((long)offset, SeekOrigin.Begin); while (offset < fs.Length) { Mp4Box box = ReadMp4Box(fs); if (box != null) { result += box.ToString() + "\tat offset: " + offset.ToString() + "\r\n"; if (box.Type != "mdat\0") { result += GetBoxChildrenString(0, box); } offset += box.Length; } else { break; } } fs.Close(); } } catch (Exception ex) { result += "ERROR: Exception while parsing the file: " + ex.Message; } return(result); }
public List <Mp4Box> GetChildren() { List <Mp4Box> list = new List <Mp4Box>(); if ((list != null) && (Data != null)) { int offset = 0; while (offset < Data.Length) { Mp4Box box = CreateMp4Box(Data, offset); if (box != null) { list.Add(box); offset += box.Length; } else { break; } } } return(list); }
public static string GetBoxChildrenString(int level, Mp4Box box) { string result = string.Empty; int locallevel = level + 1; if (box != null) { List <Mp4Box> list = box.GetChildren(); if ((list != null) && (list.Count > 0)) { foreach (var m in list) { string prefix = string.Empty; for (int i = 0; i < locallevel; i++) { prefix += "\t\t"; } result += prefix + m.ToString() + "\r\n"; result += GetBoxChildrenString(locallevel, m); } } } return(result); }
static private byte[] GetESDescriptor(int mMaxFrameSize, int mBitrate, int mSampleRate, int mChannels, string CodecPrivateData) { int BufferCodecPrivateDataLen = 0; byte[] BufferCodecPrivateData = null; byte[] ESDescriptorBuffer = null; try { BufferCodecPrivateData = Mp4Box.HexStringToByteArray(CodecPrivateData); if (BufferCodecPrivateData != null) { BufferCodecPrivateDataLen = BufferCodecPrivateData.Length; } int Len = 1 + 3 + 1 + 2 + 1 + 1 + 3 + 1 + 1 /*Type*/ + 1 + 3 + 4 + 4 + 1 + 3 + 1 + BufferCodecPrivateDataLen + 3; ESDescriptorBuffer = new byte[Len]; int offset = 0; ESDescriptorBuffer[offset++] = 0x03; ESDescriptorBuffer[offset++] = 0x80; ESDescriptorBuffer[offset++] = 0x80; ESDescriptorBuffer[offset++] = 0x80; ESDescriptorBuffer[offset++] = (byte)(Len - offset - 1); Mp4Box.WriteMp4BoxInt16(ESDescriptorBuffer, offset, 0); offset += 2; ESDescriptorBuffer[offset++] = 0x00; ESDescriptorBuffer[offset++] = 0x04; ESDescriptorBuffer[offset++] = 0x80; ESDescriptorBuffer[offset++] = 0x80; ESDescriptorBuffer[offset++] = 0x80; // Update Length for tag 0x04 ESDescriptorBuffer[offset++] = (byte)(Len - offset - 1 - 2); // ESDescriptorBuffer[offset++] = (byte)(Len - offset - 1 - 4); // MPEG 4 Audio ESDescriptorBuffer[offset++] = 0x40; ESDescriptorBuffer[offset++] = 0x15; int bufferSize = 0x300; while (bufferSize < 2 * mMaxFrameSize) { bufferSize += 0x100; } Mp4Box.WriteMp4BoxInt24(ESDescriptorBuffer, offset, bufferSize); offset += 3; Mp4Box.WriteMp4BoxInt32(ESDescriptorBuffer, offset, mBitrate); offset += 4; Mp4Box.WriteMp4BoxInt32(ESDescriptorBuffer, offset, mBitrate); offset += 4; ESDescriptorBuffer[offset++] = 0x05; ESDescriptorBuffer[offset++] = 0x80; ESDescriptorBuffer[offset++] = 0x80; ESDescriptorBuffer[offset++] = 0x80; ESDescriptorBuffer[offset++] = (byte)BufferCodecPrivateDataLen; if (BufferCodecPrivateData != null) { Mp4Box.WriteMp4BoxData(ESDescriptorBuffer, offset, BufferCodecPrivateData); } offset += BufferCodecPrivateDataLen; ESDescriptorBuffer[offset++] = 0x06; ESDescriptorBuffer[offset++] = 0x01; ESDescriptorBuffer[offset++] = 0x02; } catch (Exception) { } return(ESDescriptorBuffer); }