コード例 #1
0
        private bool ReadTag()
        {
            uint tagType, dataSize, timeStamp, streamID, mediaInfo;

            byte[] data;

            if (_fileLength - _fileOffset < 11)
            {
                return(false);
            }

            // Read tag header
            tagType    = ReadUInt8();
            dataSize   = ReadUInt24();
            timeStamp  = ReadUInt24();
            timeStamp |= ReadUInt8() << 24;
            streamID   = ReadUInt24();

            // Read tag data
            if (dataSize == 0)
            {
                return(true);
            }
            if (_fileLength - _fileOffset < dataSize)
            {
                return(false);
            }
            mediaInfo = ReadUInt8();
            dataSize -= 1;
            data      = ReadBytes((int)dataSize);

            if (tagType == 0x8)
            {              // Audio
                if (_audioWriter == null)
                {
                    _audioWriter   = _extractAudio ? GetAudioWriter(mediaInfo) : new DummyAudioWriter();
                    ExtractedAudio = !(_audioWriter is DummyAudioWriter);
                }
                _audioWriter.WriteChunk(data, timeStamp);
            }
            else if (tagType == 0x9 && mediaInfo >> 4 != 5)
            {             // Video
                if (_videoWriter == null)
                {
                    _videoWriter   = _extractVideo ? GetVideoWriter(mediaInfo) : new DummyVideoWriter();
                    ExtractedVideo = !(_videoWriter is DummyVideoWriter);
                }
                if (_timeCodeWriter == null)
                {
                    var path = _outputPathBase + ".txt";
                    _timeCodeWriter    = new TimeCodeWriter(_extractTimeCodes && CanWriteTo(path) ? path : null);
                    ExtractedTimeCodes = _extractTimeCodes;
                }
                _videoTimeStamps.Add(timeStamp);
                _videoWriter.WriteChunk(data, timeStamp, (int)((mediaInfo & 0xF0) >> 4));
                _timeCodeWriter.Write(timeStamp);
            }

            return(true);
        }
コード例 #2
0
ファイル: FlvFile.cs プロジェクト: quangfox/FlvExtract
        private bool ReadTag()
        {
            uint tagType, dataSize, timeStamp, mediaInfo;

            if ((_fileLength - _fileOffset) < 11)
            {
                return(false);
            }

            // Read tag header
            tagType    = ReadUInt8();
            dataSize   = ReadUInt24();
            timeStamp  = ReadUInt24();
            timeStamp |= ReadUInt8() << 24;
            ReadUInt24();

            // Read tag data
            if (dataSize == 0)
            {
                return(true);
            }
            if ((_fileLength - _fileOffset) < dataSize)
            {
                return(false);
            }
            mediaInfo = ReadUInt8();
            dataSize -= 1;
            byte[] data = ReadBytes((int)dataSize);

            if (tagType == 0x8 && this.audioOutputStream != null)
            {
                // Audio
                if (_audioWriter == null)
                {
                    _audioWriter     = this.GetAudioWriter(mediaInfo);
                    this.AudioFormat = this._audioWriter.AudioFormat;
                }

                _audioWriter.WriteChunk(data, timeStamp);
            }

            else if ((tagType == 0x9) && ((mediaInfo >> 4) != 5) && this.videoOutputStream != null)
            {
                // Video
                if (_videoWriter == null)
                {
                    _videoWriter     = this.GetVideoWriter(mediaInfo);
                    this.VideoFormat = this._videoWriter.VideoFormat;
                }

                _videoTimeStamps.Add(timeStamp);
                _videoWriter.WriteChunk(data, timeStamp, (int)((mediaInfo & 0xF0) >> 4));
            }

            return(true);
        }