internal override void Write(Stream output) { var contents = Encoding.UTF8.GetBytes(Value); using (var writer = new Mp4Writer(output)) { // Write the atom header writer.WriteBigEndian((uint)contents.Length + 24); #if NETSTANDARD2_0 writer.Write(CodePagesEncodingProvider.Instance.GetEncoding(1252).GetBytes(_fourCc)); #else Span <byte> fourCcBuffer = stackalloc byte[4]; CodePagesEncodingProvider.Instance.GetEncoding(1252).GetBytes(_fourCc, fourCcBuffer); writer.Write(fourCcBuffer); #endif // Write the data atom header writer.WriteBigEndian((uint)contents.Length + 16); writer.WriteBigEndian(0x64617461); // 'data' // Set the type flag writer.WriteBigEndian(1); writer.WriteZeros(4); writer.Write(contents); } }
internal void Write([NotNull] Stream output) { if (_atoms.Count == 0) { return; } var startPosition = output.Position; using (var writer = new Mp4Writer(output)) { // Write the atom header, but we don't know the size yet writer.Seek(4, SeekOrigin.Current); writer.WriteBigEndian(0x696c7374); // 'ilst' foreach (var atom in _atoms) { atom.Write(output); } // Update the size var size = output.Position - startPosition; writer.BaseStream.Position = startPosition; writer.WriteBigEndian((uint)size); writer.Seek((int)size - 4, SeekOrigin.Current); } }
void UpdateTimeStamp( [NotNull, ItemNotNull] string[] hierarchy, DateTime?creationTime, DateTime?modificationTime) { DescendToAtom(hierarchy); var version = _stream.ReadByte(); _stream.Seek(3, SeekOrigin.Current); var epoch = new DateTime(1904, 1, 1); var creationSeconds = creationTime?.Subtract(epoch).TotalSeconds ?? 0; var modificationSeconds = modificationTime?.Subtract(epoch).TotalSeconds ?? 0; using (var writer = new Mp4Writer(_stream)) { if (version == 0) { if (creationTime.HasValue) { writer.WriteBigEndian((uint)creationSeconds); } else { writer.Seek(4, SeekOrigin.Current); } if (modificationTime.HasValue) { writer.WriteBigEndian((uint)modificationSeconds); } } else { if (creationTime.HasValue) { writer.WriteBigEndian((ulong)creationSeconds); } else { writer.Seek(8, SeekOrigin.Current); } if (modificationTime.HasValue) { writer.WriteBigEndian((ulong)modificationSeconds); } } } }
internal override void Write(Stream output) { if (_size <= 8) { return; } using (var writer = new Mp4Writer(output)) { // Write the atom header writer.WriteBigEndian(_size); writer.WriteBigEndian(0x66726565); // 'free' writer.WriteZeros((int)_size - 8); } }
internal void UpdateAtomSizes(uint increase) { if (_atomInfoStack.Count <= 0) { return; } using (var writer = new Mp4Writer(_stream)) { do { var currentAtom = _atomInfoStack.Pop(); _stream.Position = currentAtom.Start; writer.WriteBigEndian(currentAtom.Size + increase); } while (_atomInfoStack.Count > 0); } }
internal override void Write(Stream output) { using (var writer = new Mp4Writer(output)) { // Write the atom header writer.WriteBigEndian(32); writer.WriteBigEndian(0x74726B6E); // 'trkn' // Write the data atom header writer.WriteBigEndian(24); writer.WriteBigEndian(0x64617461); // 'data' writer.WriteZeros(11); writer.Write(TrackNumber); writer.WriteZeros(1); writer.Write(TrackCount); writer.WriteZeros(2); } }
internal void UpdateStco(uint offset) { DescendToAtom("moov", "trak", "mdia", "minf", "stbl", "stco"); _stream.Seek(4, SeekOrigin.Current); using (var reader = new Mp4Reader(_stream)) using (var writer = new Mp4Writer(_stream)) { var count = reader.ReadUInt32BigEndian(); var dataStart = _stream.Position; for (var i = 0; i < count; i++) { _stream.Position = dataStart + i * 4; var value = reader.ReadUInt32BigEndian(); _stream.Seek(-4, SeekOrigin.Current); writer.WriteBigEndian(value + offset); } } }
internal override void Write(Stream output) { using (var writer = new Mp4Writer(output)) { // Write the atom header writer.WriteBigEndian((uint)Value.Data.Length + 24); writer.WriteBigEndian(0x636F7672); // 'covr' // Write the data atom header writer.WriteBigEndian((uint)Value.Data.Length + 16); writer.WriteBigEndian(0x64617461); // 'data' // Set the type flag to PNG or JPEG writer.WriteBigEndian(Value.Lossless ? 14u : 13u); writer.WriteZeros(4); #if NETSTANDARD2_0 writer.Write(Value.Data.ToArray()); #else writer.Write(Value.Data); #endif } }