public static float CalculateTimeScale(MovieMetadataBox moovBox, TrackBox trackBox) { MovieHeaderBox headerBox = moovBox.MovieHeaderBox; ulong moovDuration = headerBox.Duration; uint moovTimeScale = headerBox.TimeScale; MediaHeaderBox mdhdBox = trackBox.MediaBox.MediaHeaderBox; ulong mediaDuration = mdhdBox.Duration; float mediaTimeScale = mdhdBox.TimeScale; // Note that time scales may differ between moov and each media (because sampling rate can differ?) moovDuration = moovDuration / moovTimeScale; mediaDuration = (ulong)(mediaDuration / mediaTimeScale); long diff = Math.Abs((long)moovDuration - (long)mediaDuration); if ((diff * diff) > (long)((moovDuration * moovDuration) / 100)) // must be within 1% { throw new Exception("Media Box Header inconsistent with Track Header"); } // scale to 10,000,000 ticks per second mediaTimeScale /= TimeSpan.FromSeconds(1.0).Ticks; if (mediaTimeScale == 0) { throw new Exception("MP4VideoTrack: media time scale is zero"); } return(mediaTimeScale); }
public MediaBox(IsochronousTrackInfo trackInfo) : this() { ulong scaledDuration = (ulong)TimeArithmetic.ConvertToTimeScale(trackInfo.TimeScale, trackInfo.DurationIn100NanoSecs); MediaHeaderBox = new MediaHeaderBox(this, scaledDuration, trackInfo.TimeScale); this.Size += MediaHeaderBox.Size; Codec codec = null; if (trackInfo.GetType() == typeof(RawAudioTrackInfo)) { RawAudioTrackInfo audioInfo = (RawAudioTrackInfo)trackInfo; codec = new Codec(CodecTypes.Audio); codec.PrivateCodecData = audioInfo.CodecPrivateData; } else if (trackInfo.GetType() == typeof(RawVideoTrackInfo)) { RawVideoTrackInfo videoInfo = (RawVideoTrackInfo)trackInfo; codec = new Codec(CodecTypes.Video); codec.PrivateCodecData = videoInfo.CodecPrivateData; } HandlerReferenceBox = new HandlerReferenceBox(this, codec); this.Size += HandlerReferenceBox.Size; MediaInformationBox = new MediaInformationBox(this, trackInfo); // MediaInformationBox.Size is indeterminate at this time; it is determined only during SampleTableBox.FinalizeBox }
public override void Write(BoxWriter writer) { using (new SizeCalculator(this, writer)) { base.Write(writer); MediaHeaderBox.Write(writer); HandlerReferenceBox.Write(writer); MediaInformationBox.Write(writer); } }
public override string ToString() { StringBuilder xml = new StringBuilder(); xml.Append(base.ToString()); xml.Append(MediaHeaderBox.ToString()); xml.Append(HandlerReferenceBox.ToString()); xml.Append(MediaInformationBox.ToString()); xml.Append("</box>"); return(xml.ToString()); }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); MediaHeaderBox = new MediaHeaderBox(this); HandlerReferenceBox = new HandlerReferenceBox(this); MediaInformationBox = new MediaInformationBox(this); MediaHeaderBox.Read(reader); HandlerReferenceBox.Read(reader); MediaInformationBox.Read(reader); } }
public override void Read(BoxReader reader) { using (new SizeChecker(this, reader)) { base.Read(reader); MediaHeaderBox = new MediaHeaderBox(this); HandlerReferenceBox = new HandlerReferenceBox(this); MediaInformationBox = new MediaInformationBox(this); MediaHeaderBox.Read(reader); HandlerReferenceBox.Read(reader); MediaInformationBox.Read(reader); } }
public MediaBox(IsochronousTrackInfo trackInfo) : this() { ulong scaledDuration = (ulong)TimeArithmetic.ConvertToTimeScale(trackInfo.TimeScale, trackInfo.DurationIn100NanoSecs); MediaHeaderBox = new MediaHeaderBox(this, scaledDuration, trackInfo.TimeScale); this.Size += MediaHeaderBox.Size; Codec codec = null; if (trackInfo.GetType() == typeof(RawAudioTrackInfo)) { RawAudioTrackInfo audioInfo = (RawAudioTrackInfo)trackInfo; codec = new Codec(CodecTypes.Audio); codec.PrivateCodecData = audioInfo.CodecPrivateData; } else if (trackInfo.GetType() == typeof(RawVideoTrackInfo)) { RawVideoTrackInfo videoInfo = (RawVideoTrackInfo)trackInfo; codec = new Codec(CodecTypes.Video); codec.PrivateCodecData = videoInfo.CodecPrivateData; } HandlerReferenceBox = new HandlerReferenceBox(this, codec); this.Size += HandlerReferenceBox.Size; MediaInformationBox = new MediaInformationBox(this, trackInfo); // MediaInformationBox.Size is indeterminate at this time; it is determined only during SampleTableBox.FinalizeBox }