示例#1
0
        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);
        }
示例#2
0
 public MovieMetadataBox(List<IsochronousTrackInfo> trackInfos, float rate, float volume, uint[] matrix)
     : base(BoxTypes.Movie)
 {
     // initialize movie duration to zero, then increment it for every slice that is written
       ulong scaledDuration = (ulong)TimeArithmetic.ConvertToTimeScale(trackInfos[0].MovieTimeScale, trackInfos[0].MovieDurationIn100NanoSecs);
       MovieHeaderBox = new MovieHeaderBox(trackInfos[0].MovieTimeScale, scaledDuration, rate, volume, matrix);
       this.Size += MovieHeaderBox.Size;
       TrackBoxes = new TrackBox[trackInfos.Count];  // may have more than 2 tracks
       // MovieExtendsBox should only exist if this is a fragment
       if (trackInfos[0].IsFragment)
       {
     MovieExtendsBox = new MovieExtendsBox(this, trackInfos);
     this.Size += MovieExtendsBox.Size;
       }
 }
示例#3
0
        public MovieMetadataBox(List <IsochronousTrackInfo> trackInfos, float rate, float volume, uint[] matrix)
            : base(BoxTypes.Movie)
        {
            // initialize movie duration to zero, then increment it for every slice that is written
            ulong scaledDuration = (ulong)TimeArithmetic.ConvertToTimeScale(trackInfos[0].MovieTimeScale, trackInfos[0].MovieDurationIn100NanoSecs);

            MovieHeaderBox = new MovieHeaderBox(trackInfos[0].MovieTimeScale, scaledDuration, rate, volume, matrix);
            this.Size     += MovieHeaderBox.Size;
            TrackBoxes     = new TrackBox[trackInfos.Count]; // may have more than 2 tracks
            // MovieExtendsBox should only exist if this is a fragment
            if (trackInfos[0].IsFragment)
            {
                MovieExtendsBox = new MovieExtendsBox(this, trackInfos);
                this.Size      += MovieExtendsBox.Size;
            }
        }
示例#4
0
 public MovieMetadataBox() : base(BoxTypes.Movie)
 {
     MovieHeaderBox = new MovieHeaderBox();
 }
示例#5
0
 public MovieMetadataBox()
     : base(BoxTypes.Movie)
 {
     MovieHeaderBox = new MovieHeaderBox();
 }