Example #1
0
        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);
            }
        }
Example #2
0
        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);
                    }
                }
            }
        }