public MovieExtendsBox(MovieMetadataBox inParent, List <IsochronousTrackInfo> trackInfos) : this(inParent) { MovieExtendsHeaderBox = new MovieExtendsHeaderBox((uint)0); // initial duration should be zero. prev: trackInfos[0].MovieDuration); this.Size += MovieExtendsHeaderBox.Size; if (TrackExtendBoxes == null) { TrackExtendBoxes = new TrackExtendsBox[trackInfos.Count]; } //TrackBox[] tracks = parent.TrackBoxes; int i = 0; foreach (IsochronousTrackInfo tri in trackInfos) { if (tri.GetType() == typeof(RawAudioTrackInfo)) { RawAudioTrackInfo rati = (RawAudioTrackInfo)tri; TrackExtendBoxes[i] = new TrackExtendsBox((uint)(i + 1), 1, 0, 0, 0); // trackID for audio is 1, sample description index within audio track is 1 this.Size += TrackExtendBoxes[i].Size; } else if (tri.GetType() == typeof(RawVideoTrackInfo)) { RawVideoTrackInfo rvti = (RawVideoTrackInfo)tri; TrackExtendBoxes[i] = new TrackExtendsBox((uint)(i + 1), 1, 0, 0, 0); // trackID for video is 2, sample description index within video track is 1 this.Size += TrackExtendBoxes[i].Size; } i++; } }
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 }
/// <summary> /// InitializeForWriting /// Setup moov boxes, except ctts, stco, stsc, stss, stsz, and stts boxes /// </summary> /// <param name="tracksInfo">input media tracks</param> public override void InitializeForWriting(List <IsochronousTrackInfo> mediaTracksInfo) { string[] brands; if (mediaTracksInfo[0].Brands != null) { brands = mediaTracksInfo[0].Brands.Split(','); } else { brands = new string[3]; brands[0] = "mp42"; brands[1] = "isom"; brands[2] = "mp42"; } this.ftb = new FileTypeBox(brands); uint[] matrix = new uint[9]; matrix[0] = 0x10000; // 1.0 matrix[4] = 0x10000; // 1.0 matrix[8] = 0x40000000; // 1.0 (see description of RenderMatrix class) RawVideoTrackInfo rvti = (RawVideoTrackInfo)mediaTracksInfo.FirstOrDefault(ti => ti is RawVideoTrackInfo); //RawVideoTrackInfo rvti = (RawVideoTrackInfo)tracksInfo.First(info => info.HandlerType == "Video"); this.mmb = new MovieMetadataBox(mediaTracksInfo, 1.0f, 1.0f, matrix); if (rvti != null) { if (rvti.ObjectDescriptor != null) { this.mmb.ObjectDescriptorBox = new ObjectDescriptorBox(rvti.ObjectDescriptor); } if (rvti.UserData != null) { this.mmb.UserDataBox = new UserDataBox(rvti.UserData); } } if (!IsMediaStreamFragmented) { CreateTracksForWriting <MP4TrackFormat>(mediaTracksInfo); } state = WriteState.MoovReady; base.InitializeForWriting(mediaTracksInfo); }
/// <summary> /// InitializeForWriting /// What we do here is initialize a couple of properties. /// </summary> /// <param name="mediaTracks">This is with the item type of whatever is the source media stream.</param> public virtual void InitializeForWriting(List <IsochronousTrackInfo> mediaTracks) { this.SourceTrackInfo = mediaTracks; if (this.SourceTrackInfo.Any(rbt => rbt.HandlerType == "Video")) { RawVideoTrackInfo rvt = (RawVideoTrackInfo)mediaTracks.First(rbt => rbt.HandlerType == "Video"); this.DurationIn100NanoSecs = rvt.MovieDurationIn100NanoSecs; this.Hints.StreamTimeScale = rvt.MovieTimeScale; } else if (this.SourceTrackInfo.Any(rbt => rbt.HandlerType == "Audio")) { RawAudioTrackInfo rati = (RawAudioTrackInfo)mediaTracks.First(rbt => rbt.HandlerType == "Audio"); this.DurationIn100NanoSecs = rati.MovieDurationIn100NanoSecs; this.Hints.StreamTimeScale = rati.MovieTimeScale; } if (CachingEnabled) { _cacheManager.SetupForWrite(mediaTracks); } }
public TrackBox(IsochronousTrackInfo trackInfo) : this() { float height = 0.0f; float width = 0.0f; if (trackInfo is RawVideoTrackInfo) { // set the TRACK width, which may differ from SampleDescription width and height, depending on Aspect Ratio RawVideoTrackInfo rvti = (RawVideoTrackInfo)trackInfo; height = rvti.Height; width = rvti.Width * ((float)rvti.AspectRatioX / (float)rvti.AspectRatioY); } ulong scaledDuration = (ulong)TimeArithmetic.ConvertToTimeScale(trackInfo.MovieTimeScale, trackInfo.DurationIn100NanoSecs); TrackHeaderBox = new TrackHeaderBox((uint)trackInfo.TrackID, scaledDuration, height, width); // TrackHeaderBox = new TrackHeaderBox((uint)trackInfo.TrackID, (trackInfo.Duration * oneSecondTicks) / trackInfo.TimeScale, height, width); this.Size += TrackHeaderBox.Size; // skip the TrackReferenceBox for now //TrackReferenceBox = new TrackReferenceBox((uint)trackInfo.TrackID); //this.Size += TrackReferenceBox.Size; #if EDTS_OUT EdtsBox = (EdtsBox)trackInfo.GetEdtsBox(); if (EdtsBox != null) { this.Size += EdtsBox.Size; EdtsBox.ScaleToTarget(trackInfo.MovieTimeScale, trackInfo.TimeScale); } #endif MediaBox = new MediaBox(trackInfo); // MediaBox.Size can only be determined during FinalizeBox // NOTE: NO Esds Box }
public VisualSampleEntry(BoxType inType, RawVideoTrackInfo trackInfo) : base(inType) { Width = (ushort)trackInfo.Width; Height = (ushort)trackInfo.Height; HorizResolution = (uint)0x00480000; // 72 dpi VertResolution = (uint)0x00480000; FrameCount = (ushort)1; this.Size += 34UL; CompressorName = ""; // "Orions Digital MP4 Recoding"; Depth = (ushort)0x18; // images in color with no alpha this.Size += 36UL; // compressor name is 30 bytes plus 2 for length, 2 for depth, 2 for reserved if (trackInfo.PayloadType == VideoPayloadType.avc1) { AvcCBox = new AvcCBox(); AvcCBox.CodecPrivateData = trackInfo.CodecPrivateData; this.Size += AvcCBox.Size; } else if (trackInfo.PayloadType == VideoPayloadType.vc1) { PrivDataBox = new AnyPrivBox(BoxTypes.Dvc1, trackInfo.CodecPrivateData); // MS ISMV this.Size += PrivDataBox.Size; } else if (trackInfo.PayloadType == VideoPayloadType.mp4v) { //CleanApertureBox = new CleanApertureBox(); // We won't be putting a CleanApertureBox for now PrivDataFullBox = new AnyPrivFullBox(BoxTypes.Esds, trackInfo.CodecPrivateData); // 3gp mp4v --> esds this.Size += PrivDataFullBox.Size; } if (trackInfo.AspectRatioX != trackInfo.AspectRatioY) { PixelAspectRatioBox = new PixelAspectRatioBox(); PixelAspectRatioBox.hSpacing = (uint)trackInfo.AspectRatioX; PixelAspectRatioBox.vSpacing = (uint)trackInfo.AspectRatioY; this.Size += PixelAspectRatioBox.Size; } }