Beispiel #1
0
        public static AviMainHeader Read(FourCCHeader fcc, BinaryReader br)
        {
            var r = new AviMainHeader();

            r.fcc = fcc.fourcc;
            r.cb  = fcc.bytes;

            if (0 != r.fcc.CompareTo("avih") ||
                56 != r.cb)
            {
                throw new ArgumentException("AviMainHeader fourcc/size mismatch");
            }

            r.dwMicroSecPerFrame   = br.ReadUInt32();
            r.dwMaxBytesPersec     = br.ReadUInt32();
            r.dwPaddingGranularity = br.ReadUInt32();
            r.dwFlags = br.ReadUInt32();

            r.dwTotalFrames         = br.ReadUInt32();
            r.dwInitialFrames       = br.ReadUInt32();
            r.dwStreams             = br.ReadUInt32();
            r.dwSuggestedBufferSize = br.ReadUInt32();
            r.dwWidth = br.ReadUInt32();

            r.dwHeight    = br.ReadUInt32();
            r.dwReserved0 = br.ReadUInt32();
            r.dwReserved1 = br.ReadUInt32();
            r.dwReserved2 = br.ReadUInt32();
            r.dwReserved3 = br.ReadUInt32();
            return(r);
        }
Beispiel #2
0
        /* RIFF "AVI "
         *   LIST "hdrl"
         *     avih AviMainHeader
         *     LIST "strl"
         *       strh AviStreamHeader
         *       strf BitmapInfoHeader
         *   LIST "movi"
         *     00db
         *     00db
         *     ...
         * RIFF "AVIX"
         *   LIST "movi"
         *     00db
         *     00db
         *     ...
         */

        public bool Open(string path)
        {
            mImagePos.Clear();

            mBr = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read));

            var riffHeader = RiffHeader.Read(mBr);

            if (0 != riffHeader.riff.CompareTo("RIFF") ||
                0 != riffHeader.type.CompareTo("AVI "))
            {
                Console.WriteLine("E: this is not AVI");
                return(false);
            }

            try {
                do
                {
                    var fcc = FourCCHeader.Read(mBr);
                    Console.WriteLine("{0}", fcc.fourcc);
                    switch (fcc.fourcc)
                    {
                    case "RIFF":
                        var riffType = Common.ReadFourCC(mBr);
                        if (0 != riffType.CompareTo("AVIX"))
                        {
                            Console.WriteLine("D: Unknown Riff {0}", riffType);
                        }
                        break;

                    case "LIST":
                        var lst = ListHeader.Read(fcc, mBr);
                        break;

                    case "avih":
                        mAviMainHeader = AviMainHeader.Read(fcc, mBr);
                        break;

                    case "strh":
                        mAviStreamHeader = AviStreamHeader.Read(fcc, mBr);
                        break;

                    case "strf":
                        if (0 == mAviStreamHeader.fccType.CompareTo("vids"))
                        {
                            mBmpih = BitmapInfoHeader.Read(fcc, mBr);
                        }
                        else
                        {
                            SkipUnknownHeader(fcc);
                        }
                        break;

                    case "00db":
                    case "00dc":
                        ReadOneImage(fcc);
                        break;

                    default:
                        SkipUnknownHeader(fcc);
                        break;
                    }
                } while (true);
            } catch (EndOfStreamException) {
                // OK
            }

            Console.WriteLine("Total {0} images", mImagePos.Count);

            if (mImagePos.Count == 0)
            {
                Close();
                return(false);
            }

            return(true);
        }