コード例 #1
0
        public bool ReadFrame(out byte[] frame)
        {
            frame = null;
            byte[] sourceFrame;

            if (!m_source.ReadFrame(out sourceFrame))
            {
                return(false);
            }

            frame = new byte[FrameSize];

            fixed(AVPicture *pOutPict = &m_outPict)
            fixed(byte *pOrig = sourceFrame)
            {
                AVPicture sourcePict;
                int       size = FFmpeg.avpicture_fill(out sourcePict, sourceFrame, m_source.PixelFormat, m_source.Width, m_source.Height);

                Debug.Assert(size == sourceFrame.Length);

                if (FFmpeg.sws_scale(m_scalingContext, (byte **)&sourcePict.data[0], sourcePict.linesize, 0, m_source.Height,
                                     (byte **)&pOutPict->data[0], pOutPict->linesize) < 0)
                {
                    throw new DecoderException("Error scaling output");
                }

                // copy data into our managed buffer
                if (pOutPict->data[0] == null)
                {
                    frame = null;
                    return(true);
                }

                if (FFmpeg.avpicture_layout((AVPicture *)pOutPict, PixelFormat, Width, Height, frame, frame.Length) < 0)
                {
                    throw new DecoderException("Error copying decoded frame into managed memory");
                }
            }

            return(true);
        }
コード例 #2
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            if (m_stream != null)
            {
                byte[] frame;
                if (m_stream.ReadFrame(out frame))
                {
                    Bitmap image = new Bitmap(m_stream.Width, m_stream.Height);

                    BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                                     ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);

                    Marshal.Copy(frame, 0, data.Scan0, frame.Length);

                    image.UnlockBits(data);

                    pe.Graphics.DrawImage(image, ClientRectangle);
                }
            }
        }