public IMediaTrack this[CodecTypes type, int id] { get { if (MediaTracks.Count == 0) { return(null); } GenericMediaTrack track = null; if (id == 0) // get the first track with the given type { if (MediaTracks.Any(trk => trk.Codec.CodecType == type)) { track = (GenericMediaTrack)MediaTracks.First(trk => trk.Codec.CodecType == type); } } else // get specific track with the given type and track ID { if (MediaTracks.Any(trk => trk.Codec.CodecType == type && trk.TrackID == id)) { track = (GenericMediaTrack)MediaTracks.First(trk => trk.Codec.CodecType == type && trk.TrackID == id); } } return(track); } }
/// <summary> /// WriteSamples /// Write several samples to the output file. /// </summary> /// <param name="slices"></param> /// <param name="codecType"></param> public override void WriteSamples(IEnumerable <Slice> slices, CodecTypes codecType) { if (codecType == CodecTypes.Audio) { // ignore audio } else if (codecType == CodecTypes.Video) { IMediaTrack trak = MediaTracks.First(t => t.Codec.CodecType == CodecTypes.Video); foreach (Slice sample in slices) { // convert to bit-stream format (prefix with 0001) Stream mstrm = new MemoryStream(sample.SliceBytes); Stream ostr = H264.H264Utilities.H264Stream(firstSample, trak.Codec.PrivateCodecData, mstrm, 0, (uint)sample.SliceBytes.Length); firstSample = false; mstrm.Close(); ostr.Position = 0L; byte[] buf = new byte[ostr.Length]; ostr.Read(buf, 0, (int)ostr.Length); ostr.Close(); sample.SliceBytes = buf; Stream.Write(sample.SliceBytes, 0, sample.SliceBytes.Length); } } else { throw new Exception("WriteSamples: unknown codec type"); } }
/// <summary> /// PrepareSampleWriting /// This overloaded method accepts slices and codec type as params. /// </summary> /// <param name="slicesInfo">The list of slices to be written, in StreamDataBlockInfo format</param> /// <param name="codecType">A member of the CodecTypes enum</param> public void PrepareSampleWriting(List <StreamDataBlockInfo> slicesInfo, CodecTypes codecType) { IMediaTrack track = this[codecType, 0]; if ((track != null) && (track.TrackFormat != null)) { track.TrackFormat.PrepareSampleWriting(slicesInfo, ref _currMDatOffset); } }
public override void WriteSamples(IEnumerable<Slice> slices, CodecTypes codecType) { GenericMediaTrack track = (GenericMediaTrack)this[codecType, 0]; ISMVTrackFormat format = (ISMVTrackFormat)track.TrackFormat; format.CurrentFragment.Write(m_writer); format.CurrentFragment.CheckFilePosition(m_writer); foreach (Slice sample in slices) { m_writer.Write(sample.SliceBytes, 0, sample.SliceBytes.Length); } format.CurrentFragment = null; // release }
/// <summary> /// QBoxTrackFormat /// Constructor to use when writing out to a stream. /// </summary> /// <param name="trackInfo"></param> public QBoxTrackFormat(IsochronousTrackInfo trackInfo) : this() { _qBoxes = new List <QBox>(); firstQB = new QBox(trackInfo); CodecTypes codecType = (trackInfo.HandlerType == "Audio") ? CodecTypes.Audio : (trackInfo.HandlerType == "Video") ? CodecTypes.Video : CodecTypes.Unknown; Codec = new Codec(codecType); Codec.PrivateCodecData = trackInfo.CodecPrivateData; DurationIn100NanoSecs = trackInfo.DurationIn100NanoSecs; }
public override void WriteSamples(IEnumerable <Slice> slices, CodecTypes codecType) { GenericMediaTrack track = (GenericMediaTrack)this[codecType, 0]; ISMVTrackFormat format = (ISMVTrackFormat)track.TrackFormat; format.CurrentFragment.Write(m_writer); format.CurrentFragment.CheckFilePosition(m_writer); foreach (Slice sample in slices) { m_writer.Write(sample.SliceBytes, 0, sample.SliceBytes.Length); } format.CurrentFragment = null; // release }
public override void WriteSamples(IEnumerable<Slice> slices, CodecTypes codecType) { if (codecType == CodecTypes.Audio) { // ignore audio } else if (codecType == CodecTypes.Video) { int i = 0; foreach (Slice sample in slices) { string fileName = string.Format("{0}{1}{2}", RootName, i, ".jpg"); FileStream stream = File.Create(fileName); stream.Write(sample.SliceBytes, 12, sample.SliceBytes.Length - 12); stream.Close(); i++; } } else throw new Exception("WriteSamples: unknown codec type"); }
/// <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"); } }
/// <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 (tempMdat == null) { tempMdatFilePath = Path.GetTempFileName(); tempMdat = File.Create(tempMdatFilePath); } foreach (Slice sample in slices) { //Common.Logger.Instance.Info("[MP4StreamWriter::WriteSamples] writes " + sample + ", " + (sample != null ? sample.GetType().Name : string.Empty)); tempMdat.Write(sample.SliceBytes, 0, sample.SliceBytes.Length); } // use current offset into mdat to verify file position AFTER writing all samples in this batch // do this check here ONLY if caching is enabled if (CachingEnabled) { base.CheckMDatOffset(tempMdat.Position); } }
public override void WriteSamples(IEnumerable <Slice> slices, CodecTypes codecType) { if (codecType == CodecTypes.Audio) { // ignore audio } else if (codecType == CodecTypes.Video) { int i = 0; foreach (Slice sample in slices) { string fileName = string.Format("{0}{1}{2}", RootName, i, ".jpg"); FileStream stream = File.Create(fileName); stream.Write(sample.SliceBytes, 12, sample.SliceBytes.Length - 12); stream.Close(); i++; } } else { throw new Exception("WriteSamples: unknown codec type"); } }
public void AddCodec <T>() where T : ICodec { CodecTypes.Add(typeof(T)); }
/// <summary> /// PrepareSampleWriting /// This overloaded method accepts slices and codec type as params. /// </summary> /// <param name="slicesInfo">The list of slices to be written, in StreamDataBlockInfo format</param> /// <param name="codecType">A member of the CodecTypes enum</param> public void PrepareSampleWriting(List<StreamDataBlockInfo> slicesInfo, CodecTypes codecType) { IMediaTrack track = this[codecType, 0]; if ((track != null) && (track.TrackFormat != null)) track.TrackFormat.PrepareSampleWriting(slicesInfo, ref _currMDatOffset); }
public virtual void WriteSamples(IEnumerable<Slice> slices, CodecTypes codecType) { throw new NotImplementedException("Have to implement WriteSamples(List<StreamDataBlockInfo> slices, CodecTypes codecType) in derived class"); }
public virtual void WriteSamples(IEnumerable <Slice> slices, CodecTypes codecType) { throw new NotImplementedException("Have to implement WriteSamples(List<StreamDataBlockInfo> slices, CodecTypes codecType) in derived class"); }
public IMediaTrack this[CodecTypes type, int id] { get { if (MediaTracks.Count == 0) return null; GenericMediaTrack track = null; if (id == 0) // get the first track with the given type { if (MediaTracks.Any(trk => trk.Codec.CodecType == type)) track = (GenericMediaTrack)MediaTracks.First(trk => trk.Codec.CodecType == type); } else // get specific track with the given type and track ID { if (MediaTracks.Any(trk => trk.Codec.CodecType == type && trk.TrackID == id)) track = (GenericMediaTrack)MediaTracks.First(trk => trk.Codec.CodecType == type && trk.TrackID == id); } return track; } }
/// <summary> /// WriteSamples /// Write several samples to the output file. /// </summary> /// <param name="slices"></param> /// <param name="codecType"></param> public override void WriteSamples(IEnumerable<Slice> slices, CodecTypes codecType) { if (codecType == CodecTypes.Audio) { // ignore audio } else if (codecType == CodecTypes.Video) { IMediaTrack trak = MediaTracks.First(t => t.Codec.CodecType == CodecTypes.Video); foreach (Slice sample in slices) { // convert to bit-stream format (prefix with 0001) Stream mstrm = new MemoryStream(sample.SliceBytes); Stream ostr = H264.H264Utilities.H264Stream(firstSample, trak.Codec.PrivateCodecData, mstrm, 0, (uint)sample.SliceBytes.Length); firstSample = false; mstrm.Close(); ostr.Position = 0L; byte[] buf = new byte[ostr.Length]; ostr.Read(buf, 0, (int)ostr.Length); ostr.Close(); sample.SliceBytes = buf; Stream.Write(sample.SliceBytes, 0, sample.SliceBytes.Length); } } else throw new Exception("WriteSamples: unknown codec type"); }
public Codec(CodecTypes expectedType) { CodecType = expectedType; }
public void WriteSamples(IMediaTrack sourceTrack) { CodecTypes codecType = sourceTrack.Codec.CodecType; WriteSamples(sourceTrack, codecType); }
/// <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"); }