Пример #1
0
        public void Write(MetaData meta)
        {
            MetaCue[] metaCue = meta.MetaCue;
            FlvReader reader  = new FlvReader(this._file, false);
            FlvWriter writer  = new FlvWriter(this._output, false);
            ITag      tag     = null;

            if (reader.HasMoreTags())
            {
                tag = reader.ReadTag();
                if ((tag.DataType == IOConstants.TYPE_METADATA) && !reader.HasMoreTags())
                {
                    throw new IOException("File we're writing is metadata only?");
                }
            }
            meta.Duration     = ((double)reader.Duration) / 1000.0;
            meta.VideoCodecId = reader.VideoCodecId;
            meta.AudioCodecId = reader.AudioCodecId;
            ITag tag2 = this.InjectMetaData(meta, tag);

            tag2.PreviousTagSize = 0;
            tag.PreviousTagSize  = tag2.BodySize;
            writer.WriteHeader();
            writer.WriteTag(tag2);
            writer.WriteTag(tag);
            int timeInMilliseconds = 0;
            int index = 0;

            if (metaCue != null)
            {
                Array.Sort <MetaCue>(metaCue);
                timeInMilliseconds = this.GetTimeInMilliseconds(metaCue[0]);
            }
            while (reader.HasMoreTags())
            {
                tag = reader.ReadTag();
                if (index < metaCue.Length)
                {
                    while (tag.Timestamp > timeInMilliseconds)
                    {
                        tag2 = this.InjectMetaCue(metaCue[index], tag);
                        writer.WriteTag(tag2);
                        tag.PreviousTagSize = tag2.BodySize;
                        index++;
                        if (index > (metaCue.Length - 1))
                        {
                            break;
                        }
                        timeInMilliseconds = this.GetTimeInMilliseconds(metaCue[index]);
                    }
                }
                if (tag.DataType != IOConstants.TYPE_METADATA)
                {
                    writer.WriteTag(tag);
                }
            }
            writer.Close();
        }
Пример #2
0
        public Flv(FileInfo file, bool generateMetadata)
        {
            _file = file;
            _generateMetadata = generateMetadata;
            int count = 0;

            if (!_generateMetadata)
            {
                try
                {
                    FlvReader reader = new FlvReader(_file);
                    ITag tag = null;
                    while (reader.HasMoreTags() && (++count < 5))
                    {
                        tag = reader.ReadTag();
                        if (tag.DataType == IOConstants.TYPE_METADATA)
                        {
                            if (_metaService == null) _metaService = new MetaService(_file);
                            _metaData = _metaService.ReadMetaData(tag.Body);
                        }
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
#if !SILVERLIGHT
                    log.Error("An error occured looking for metadata:", ex);
#endif
                }
            }
        }
Пример #3
0
        public Flv(FileInfo file, bool generateMetadata)
        {
            this._file             = file;
            this._generateMetadata = generateMetadata;
            int num = 0;

            if (!this._generateMetadata)
            {
                try
                {
                    FlvReader reader = new FlvReader(this._file);
                    ITag      tag    = null;
                    while (reader.HasMoreTags() && (++num < 5))
                    {
                        tag = reader.ReadTag();
                        if (tag.DataType == IOConstants.TYPE_METADATA)
                        {
                            if (this._metaService == null)
                            {
                                this._metaService = new FluorineFx.IO.FLV.MetaService(this._file);
                            }
                            this._metaData = this._metaService.ReadMetaData(tag.Body);
                        }
                    }
                    reader.Close();
                }
                catch (Exception exception)
                {
                    log.Error("An error occured looking for metadata:", exception);
                }
            }
        }
Пример #4
0
        public Flv(FileInfo file, bool generateMetadata)
        {
            _file             = file;
            _generateMetadata = generateMetadata;
            int count = 0;

            if (!_generateMetadata)
            {
                try
                {
                    FlvReader reader = new FlvReader(_file);
                    ITag      tag    = null;
                    while (reader.HasMoreTags() && (++count < 5))
                    {
                        tag = reader.ReadTag();
                        if (tag.DataType == IOConstants.TYPE_METADATA)
                        {
                            if (_metaService == null)
                            {
                                _metaService = new MetaService(_file);
                            }
                            _metaData = _metaService.ReadMetaData(tag.Body);
                        }
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
#if LOGGING && !SILVERLIGHT
                    log.Error("An error occured looking for metadata:", ex);
#endif
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Initiates writing of the Metadata.
        /// </summary>
        /// <param name="meta">Metadata to write.</param>
        public void Write(MetaData meta)
        {
            // Get cue points, FLV reader and writer
            MetaCue[] metaArr = meta.MetaCue;
            FlvReader reader  = new FlvReader(_file, false);
            FlvWriter writer  = new FlvWriter(_output, false);
            ITag      tag     = null;

            // Read first tag
            if (reader.HasMoreTags())
            {
                tag = reader.ReadTag();
                if (tag.DataType == IOConstants.TYPE_METADATA)
                {
                    if (!reader.HasMoreTags())
                    {
                        throw new IOException("File we're writing is metadata only?");
                    }
                }
            }

            meta.Duration     = (double)reader.Duration / 1000;
            meta.VideoCodecId = reader.VideoCodecId;
            meta.AudioCodecId = reader.AudioCodecId;

            ITag injectedTag = InjectMetaData(meta, tag);

            injectedTag.PreviousTagSize = 0;
            tag.PreviousTagSize         = injectedTag.BodySize;

            writer.WriteHeader();
            writer.WriteTag(injectedTag);
            writer.WriteTag(tag);

            int cuePointTimeStamp = 0;
            int counter           = 0;

            if (metaArr != null)
            {
                Array.Sort(metaArr);
                cuePointTimeStamp = GetTimeInMilliseconds(metaArr[0]);
            }

            while (reader.HasMoreTags())
            {
                tag = reader.ReadTag();

                // if there are cuePoints in the array
                if (counter < metaArr.Length)
                {
                    // If the tag has a greater timestamp than the
                    // cuePointTimeStamp, then inject the tag
                    while (tag.Timestamp > cuePointTimeStamp)
                    {
                        injectedTag = InjectMetaCue(metaArr[counter], tag);
                        writer.WriteTag(injectedTag);

                        tag.PreviousTagSize = injectedTag.BodySize;

                        // Advance to the next CuePoint
                        counter++;

                        if (counter > (metaArr.Length - 1))
                        {
                            break;
                        }

                        cuePointTimeStamp = GetTimeInMilliseconds(metaArr[counter]);
                    }
                }

                if (tag.DataType != IOConstants.TYPE_METADATA)
                {
                    writer.WriteTag(tag);
                }
            }
            writer.Close();
        }
Пример #6
0
        /// <summary>
        /// Initiates writing of the Metadata.
        /// </summary>
        /// <param name="meta">Metadata to write.</param>
        public void Write(MetaData meta)
        {
            // Get cue points, FLV reader and writer
            MetaCue[] metaArr = meta.MetaCue;
            FlvReader reader = new FlvReader(_file, false);
            FlvWriter writer = new FlvWriter(_output, false);
            ITag tag = null;

            // Read first tag
            if (reader.HasMoreTags())
            {
                tag = reader.ReadTag();
                if (tag.DataType == IOConstants.TYPE_METADATA)
                {
                    if (!reader.HasMoreTags())
                        throw new IOException("File we're writing is metadata only?");
                }
            }

            meta.Duration = (double)reader.Duration / 1000;
            meta.VideoCodecId = reader.VideoCodecId;
            meta.AudioCodecId = reader.AudioCodecId;

            ITag injectedTag = InjectMetaData(meta, tag);
            injectedTag.PreviousTagSize = 0;
            tag.PreviousTagSize = injectedTag.BodySize;

            writer.WriteHeader();
            writer.WriteTag(injectedTag);
            writer.WriteTag(tag);

            int cuePointTimeStamp = 0;
            int counter = 0;

            if (metaArr != null)
            {
                Array.Sort(metaArr);
                cuePointTimeStamp = GetTimeInMilliseconds(metaArr[0]);
            }

            while (reader.HasMoreTags())
            {
                tag = reader.ReadTag();

                // if there are cuePoints in the array 
                if (counter < metaArr.Length)
                {

                    // If the tag has a greater timestamp than the
                    // cuePointTimeStamp, then inject the tag
                    while (tag.Timestamp > cuePointTimeStamp)
                    {

                        injectedTag = InjectMetaCue(metaArr[counter], tag);
                        writer.WriteTag(injectedTag);

                        tag.PreviousTagSize = injectedTag.BodySize;

                        // Advance to the next CuePoint
                        counter++;

                        if (counter > (metaArr.Length - 1))
                        {
                            break;
                        }

                        cuePointTimeStamp = GetTimeInMilliseconds(metaArr[counter]);

                    }
                }

                if (tag.DataType != IOConstants.TYPE_METADATA)
                {
                    writer.WriteTag(tag);
                }

            }
            writer.Close();
        }