Example #1
0
        //public override void Write()
        //{
        //  if (state == WriteState.MoovReady)
        //  {
        //    // write out moov only
        //    this.ftb.Write(m_writer);
        //    this.mmb.Write(m_writer);
        //    state = WriteState.MoovDone;
        //  }
        //  else if (state == WriteState.MoovDone)
        //  {
        //    // write out samples
        //  }
        //  else throw new Exception(string.Format("Cannot write to destination file (bad state = {0})", state));
        //}

        /// <summary>
        /// CreateTracksForWriting
        /// Generic method for creating tracks given a list of RawBaseTrackInfo.
        /// </summary>
        /// <typeparam name="T">must be MP4TrackFormat or any type derived from it</typeparam>
        /// <param name="tracksInfo">list of RawBaseTrackInfo</param>
        protected void CreateTracksForWriting <T>(List <IsochronousTrackInfo> tracksInfo) where T : MP4TrackFormat, new()
        {
            // We can't just use the input tracksInfo and assign it to our _MediaTracks (that would not work because the types won't match).
            // The input or source media tracks will normally have different types than our _MediaTracks (although they are derived from the same GenericMediaTrack).
            foreach (IsochronousTrackInfo rawTrack in tracksInfo)
            {
                T trackFormat = new T();
                trackFormat.TrackBox = new TrackBox(this.mmb, rawTrack);
                this.mmb.AddTrackBox(trackFormat.TrackBox);
                switch (rawTrack.HandlerType)
                {
                case "Audio":
                    GenericAudioTrack audioTrack = new GenericAudioTrack(trackFormat, this);
                    base.AddTrack(audioTrack);
                    break;

                case "Video":
                    GenericVideoTrack videoTrack = new GenericVideoTrack(trackFormat, this);
                    base.AddTrack(videoTrack);
                    break;

                default:
                    throw new Exception("Unknown source handler type");
                }
                //if (trackFormat.TrackID != (mmb.MovieHeaderBox.NextTrackID - 1))
                //  throw new Exception("MP4StreamWriter: TrackID broken");
            }
        }
Example #2
0
        /// <summary>
        /// CreateTracksForWriting
        /// Method for creating tracks given a list of RawBaseTrackInfo.
        /// </summary>
        /// <param name="tracksInfo">list of RawBaseTrackInfo</param>
        private void CreateTracksForWriting(List <IsochronousTrackInfo> tracksInfo)
        {
            // We can't just use the input tracksInfo and assign it to our _MediaTracks (that would not work because the types won't match).
            // The input or source media tracks will normally have different types than our _MediaTracks (although they are derived from the same GenericMediaTrack).
            foreach (IsochronousTrackInfo rawTrack in tracksInfo)
            {
                QBoxTrackFormat trackFormat = new QBoxTrackFormat(rawTrack);
                trackFormat.WriteFirstQBox(_binaryWriter);
                switch (rawTrack.HandlerType)
                {
                case "Audio":
                    GenericAudioTrack audioTrack = new GenericAudioTrack(trackFormat, this);
                    base.AddTrack(audioTrack);
                    break;

                case "Video":
                    GenericVideoTrack videoTrack = new GenericVideoTrack(trackFormat, this);
                    base.AddTrack(videoTrack);
                    break;

                default:
                    throw new Exception("Unknown source handler type");
                }
            }
        }
Example #3
0
 /// <summary>
 /// WriteSamples
 /// Overloaded method for writing slices directly.
 /// </summary>
 /// <param name="slices">A List of Sample(s)</param>
 /// <param name="codecType">Member of CodecTypes enum</param>
 public override void WriteSamples(IEnumerable <Slice> slices, CodecTypes codecType)
 {
     if (codecType == CodecTypes.Audio)
     {
         GenericAudioTrack audioTrack  = (GenericAudioTrack)MediaTracks.First(tr => tr.Codec.CodecType == codecType);
         QBoxTrackFormat   trackFormat = (QBoxTrackFormat)audioTrack.TrackFormat;
         trackFormat.WriteSamples(_binaryWriter, slices);
     }
     else if (codecType == CodecTypes.Video)
     {
         GenericVideoTrack videoTrack  = (GenericVideoTrack)MediaTracks.First(tr => tr.Codec.CodecType == codecType);
         QBoxTrackFormat   trackFormat = (QBoxTrackFormat)videoTrack.TrackFormat;
         trackFormat.WriteSamples(_binaryWriter, slices);
     }
     else
     {
         throw new Exception("WriteSamples: unknown codec type");
     }
 }
Example #4
0
 public RawTrackInfo(GenericAudioTrack audio, GenericVideoTrack video)
 {
     AudioTrackInfo = new RawAudioTrackInfo(audio);
     VideoTrackInfo = new RawVideoTrackInfo(video);
 }