Ejemplo n.º 1
0
 void avi_write_fourcc(avi_t a, string fcc)
 {
     a.f.WriteByte((byte)fcc[0]);
     a.f.WriteByte((byte)fcc[1]);
     a.f.WriteByte((byte)fcc[2]);
     a.f.WriteByte((byte)fcc[3]);
 }
Ejemplo n.º 2
0
 void avi_write_int32(avi_t a, int dw)
 {
     //a.f.Write(BitConverter.GetBytes(dw), 0, 4);
     a.f.WriteByte((byte)(dw & 0xff));
     a.f.WriteByte((byte)((dw >> 8) & 0xff));
     a.f.WriteByte((byte)((dw >> 16) & 0xff));
     a.f.WriteByte((byte)((dw >> 24) & 0xff));
 }
Ejemplo n.º 3
0
        void avi_write_idx(avi_t a)
        {
            avi_write_fourcc(a, "idx1");
            avi_write_uint32(a, (uint)a.i_frame * 16);

            byte[] buffer = new byte[(a.i_frame * 16) * 1];
            Marshal.Copy(new IntPtr(a.idx), buffer, 0, buffer.Length);
            a.f.Write(buffer, 0, buffer.Length);
        }
Ejemplo n.º 4
0
        void avi_end(avi_t a)
        {
            a.i_movi_end = a.f.Position;

            /* write index */
            avi_write_idx(a);

            a.i_riff = a.f.Position;

            /* Fix header */
            a.f.Seek(0, SeekOrigin.Begin);
            avi_write_header(a);
        }
Ejemplo n.º 5
0
        void avi_write(avi_t a, vbuf_t v, int b_key)
        {
            int i = 0;

            if (!a.f.CanWrite)
            {
                return;
            }
            long i_pos = a.f.Position;

            /* chunk header */
            avi_write_fourcc(a, "00dc");
            avi_write_uint32(a, (uint)v.i_data);

            byte[] buffer = new byte[v.i_data * 1];
            Marshal.Copy(new IntPtr(v.p_data), buffer, 0, buffer.Length);
            a.f.Write(buffer, 0, buffer.Length);

            if ((v.i_data & 0x01) != 0)
            {
                /* pad */
                a.f.WriteByte(0);
            }

            /* Append idx chunk */
            if (a.i_idx_max <= a.i_frame)
            {
                a.i_idx_max += 1000;
                if (a.idx == null)
                {
                    a.idx = (uint *)Marshal.AllocHGlobal(a.i_idx_max * 16).ToPointer();
                }
                else
                {
                    a.idx = (uint *)Marshal.ReAllocHGlobal(new IntPtr(a.idx), new IntPtr(a.i_idx_max * 16)).ToPointer();
                }
            }

            IntPtr tmpPtr = Marshal.StringToHGlobalAnsi("00dc");

            memcpy(&a.idx[4 * a.i_frame + 0], tmpPtr.ToPointer(), 4);
            Marshal.FreeHGlobal(tmpPtr);
            avi_set_dw(&a.idx[4 * a.i_frame + 1], b_key != 0 ? (int)AVIIF_KEYFRAME : 0);
            avi_set_dw(&a.idx[4 * a.i_frame + 2], (int)i_pos);
            avi_set_dw(&a.idx[4 * a.i_frame + 3], v.i_data);

            a.i_frame++;
        }
Ejemplo n.º 6
0
        void avi_init(avi_t a, FileStream f, float f_fps, string fcc)
        {
            a.f          = f;
            a.f_fps      = f_fps;
            a.fcc        = fcc;
            a.i_width    = 0;
            a.i_height   = 0;
            a.i_frame    = 0;
            a.i_movi     = 0;
            a.i_riff     = 0;
            a.i_movi_end = 0;
            a.i_idx_max  = 0;
            a.idx        = null;

            avi_write_header(a);

            a.i_movi = a.f.Position;
        }
Ejemplo n.º 7
0
        int ParseNAL(nal_t nal, avi_t a, h264_t h, int *pb_slice)
        {
            int b_flush = 0;
            int b_start;

            h264_parser_parse(h, nal, &b_start);

            if (b_start != 0 && *pb_slice != 0)
            {
                b_flush = 1;
                *pb_slice = 0;
            }

            if (nal.i_type >= (int)nal_unit_type_e.NAL_SLICE && nal.i_type <= (int)nal_unit_type_e.NAL_SLICE_IDR)
            {
                *pb_slice = 1;
            }

            return(b_flush);
        }
Ejemplo n.º 8
0
        public CAvcToAvi()
        {
            cfg       = new cfg_t();
            cfg.f_fps = 24;
            cfg.fcc   = "h264";

            /* Init data */
            b_eof   = 0;
            b_key   = 0;
            b_slice = 0;
            i_frame = 0;
            i_data  = 0;

            avi           = new avi_t();
            h264          = new h264_t();
            nal           = new nal_t();
            nal.p_payload = (byte *)Marshal.AllocHGlobal(DATA_MAX).ToPointer();
            vb            = new vbuf_t();

            data = (byte *)Marshal.AllocHGlobal(DATA_MAX).ToPointer();
        }
Ejemplo n.º 9
0
 void avi_write_uint16(avi_t a, short w)
 {
     //a.f.Write(BitConverter.GetBytes(w), 0, 2);
     a.f.WriteByte((byte)(w & 0xff));
     a.f.WriteByte((byte)((w >> 8) & 0xff));
 }
Ejemplo n.º 10
0
        void avi_write_header(avi_t a)
        {
            avi_write_fourcc(a, "RIFF");
            avi_write_uint32(a, a.i_riff > 0 ? (uint)a.i_riff - 8 : 0xFFFFFFFF);
            avi_write_fourcc(a, "AVI ");

            avi_write_fourcc(a, "LIST");
            avi_write_uint32(a, 4 + 4 * 16 + 12 + 4 * 16 + 4 * 12);
            avi_write_fourcc(a, "hdrl");

            avi_write_fourcc(a, "avih");
            avi_write_uint32(a, 4 * 16 - 8);
            avi_write_uint32(a, 1000000 / (uint)a.f_fps);
            avi_write_uint32(a, 0xffffffff);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, AVIF_HASINDEX | AVIF_ISINTERLEAVED | AVIF_TRUSTCKTYPE);
            avi_write_uint32(a, (uint)a.i_frame);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 1);
            avi_write_uint32(a, 1000000);
            avi_write_uint32(a, (uint)a.i_width);
            avi_write_uint32(a, (uint)a.i_height);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 0);

            avi_write_fourcc(a, "LIST");
            avi_write_uint32(a, 4 + 4 * 16 + 4 * 12);
            avi_write_fourcc(a, "strl");

            avi_write_fourcc(a, "strh");
            avi_write_uint32(a, 4 * 16 - 8);
            avi_write_fourcc(a, "vids");
            avi_write_fourcc(a, a.fcc);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 1000);
            avi_write_uint32(a, (uint)a.f_fps * 1000);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, (uint)a.i_frame);
            avi_write_uint32(a, 1024 * 1024);
            avi_write_int32(a, -1);
            avi_write_uint32(a, (uint)(a.i_width * a.i_height));
            avi_write_uint32(a, 0);
            avi_write_uint16(a, (short)a.i_width);
            avi_write_uint16(a, (short)a.i_height);

            avi_write_fourcc(a, "strf");
            avi_write_uint32(a, 4 * 12 - 8);
            avi_write_uint32(a, 4 * 12 - 8);
            avi_write_uint32(a, (uint)a.i_width);
            avi_write_uint32(a, (uint)a.i_height);
            avi_write_uint16(a, 1);
            avi_write_uint16(a, 24);
            avi_write_fourcc(a, a.fcc);
            avi_write_uint32(a, (uint)(a.i_width * a.i_height));
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 0);
            avi_write_uint32(a, 0);

            avi_write_fourcc(a, "LIST");
            avi_write_uint32(a, a.i_movi_end > 0 ? (uint)a.i_movi_end - (uint)a.i_movi + 4 : 0xFFFFFFFF);
            avi_write_fourcc(a, "movi");
        }