Example #1
0
 private static bool IsSuitableToMerge(FLVContext flvCtx1, FLVContext flvCtx2)
 {
     return((flvCtx1.soundFormat == flvCtx2.soundFormat) &&
            (flvCtx1.soundRate == flvCtx2.soundRate) &&
            (flvCtx1.soundSize == flvCtx2.soundSize) &&
            (flvCtx1.soundType == flvCtx2.soundType) &&
            (flvCtx1.videoCodecID == flvCtx2.videoCodecID));
 }
Example #2
0
        private static FLVContext GetFLVFileInfo(FileStream fs)
        {
            bool hasAudioParams, hasVideoParams;
            int  skipSize, readLen;
            int  dataSize;
            byte tagType;

            byte[] tmp = new byte[FLV_TAG_HEADER_SIZE + 1];
            if (fs == null)
            {
                return(null);
            }

            FLVContext flvCtx = new FLVContext();

            fs.Position    = 0;
            skipSize       = 9;
            fs.Position   += skipSize;
            hasVideoParams = hasAudioParams = false;
            skipSize       = 4;
            while (!hasVideoParams || !hasAudioParams)
            {
                fs.Position += skipSize;

                if (FLV_TAG_HEADER_SIZE + 1 != fs.Read(tmp, 0, tmp.Length))
                {
                    return(null);
                }

                tagType = (byte)(tmp[0] & 0x1f);
                switch (tagType)
                {
                case 8:
                    flvCtx.soundFormat = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0xf0) >> 4);
                    flvCtx.soundRate   = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0x0c) >> 2);
                    flvCtx.soundSize   = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0x02) >> 1);
                    flvCtx.soundType   = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0x01) >> 0);
                    hasAudioParams     = true;
                    break;

                case 9:
                    flvCtx.videoCodecID = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0x0f));
                    hasVideoParams      = true;
                    break;

                default:
                    break;
                }

                dataSize = FromInt24StringBe(tmp[1], tmp[2], tmp[3]);
                skipSize = dataSize - 1 + 4;
            }

            return(flvCtx);
        }