Beispiel #1
0
        /// <summary>
        /// 分析amf文件
        /// </summary>
        public void AnalyzeAmfFile()
        {
            try
            {
                //初始化文件读取对象
                _reader = new FileStream(_filePath, FileMode.Open, FileAccess.Read);

                //读取并分析文件头
                _buffer = new byte[_amfHeaderSize];
                int res = _reader.Read(_buffer, 0, _amfHeaderSize);
                if (res != _amfHeaderSize)
                    throw new FileFormatException("amf文件格式不正确");
                this._headerInfo = AmfMediaDecoder.AnalyzeFileHeader(_buffer);

                //读取并分析文件帧信息
                UInt32 tagOffset = _headerInfo.DataSize + 76 + 8;
                UInt32 tagLength = _headerInfo.FileSize - tagOffset;
                _buffer = new byte[tagLength];
                _reader.Position = tagOffset;
                res = _reader.Read(_buffer, 0, (int)tagLength);
                if (res != (int)tagLength)
                    throw new FileFormatException("amf文件格式不正确");
                this._frames = AmfMediaDecoder.AnalyzeFileFrame(_buffer, ref _videoLength);
            }
            catch (Exception ex)
            {
                throw new Exception("解析amf文件异常", ex);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 释放申请的资源
 /// </summary>
 public void Dispose()
 {
     try
     {
         _headerInfo = null;
         _frames.Clear();
         if (_reader != null)
         {
             _reader.Close();
             _reader = null;
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.ToString());
     }
 }
Beispiel #3
0
        /// <summary>
        /// 分析amf文件头部
        /// </summary>
        /// <param name="header">文件头字符数组</param>
        /// <returns></returns>
        public static AmfHeadInfo AnalyzeFileHeader(Byte[] header)
        {
            try
            {
                if (header.Length != 76)
                    return null;

                System.IO.MemoryStream ms = new System.IO.MemoryStream(header);
                var temp = new AmfHeadInfo
                {
                    Format = AmfTools.Byte2String(ms.ReadBytesExtend(0, 4)),
                    FileSize = AmfTools.ConvertToInt32(header, 4) + 8,
                    AudioFlag = AmfTools.SubArray(header, 8, 4),
                    AudioHeadSize = AmfTools.ConvertToInt32(header, 12),
                    AudioCodec = new Char4 { Value = AmfTools.Byte2String(ms.ReadBytesExtend(16, 4)) },//AmfTools.SubArray(header,16,4)},
                    AudioBitRate = AmfTools.ConvertToInt32(header, 20),
                    ChannelCount = AmfTools.ConvertToInt32(header, 24),
                    SamplingRate = AmfTools.ConvertToInt32(header, 28),
                    SamplingTime = AmfTools.ConvertToInt32(header, 32),
                    AudioFrameCount = AmfTools.ConvertToInt32(header, 36),
                    VideoFlag = AmfTools.SubArray(header, 40, 4),
                    VideoHeadSize = AmfTools.ConvertToInt32(header, 44),
                    VideoCodec = new Char4 { Value = AmfTools.Byte2String(ms.ReadBytesExtend(48, 4)) },//AmfTools.SubArray(header, 48, 4),
                    Width = AmfTools.ConvertToInt32(header, 52),
                    Height = AmfTools.ConvertToInt32(header, 56),
                    VideoFrameRate = AmfTools.ConvertToInt32(header, 60),
                    VideoFrameCount = AmfTools.ConvertToInt32(header, 64),
                    DataBlockFlag = AmfTools.SubArray(header, 68, 4),
                    DataSize = AmfTools.ConvertToInt32(header, 72)
                };
                ms.Close();
                return temp;
            }
            catch 
            {
                throw;
            }
        }