Beispiel #1
0
 public static void UpdateBitmap(ref Bitmap bitmap, ref VideoFrame frame)
 {
     var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
     BitmapData data = bitmap.LockBits(rect, ImageLockMode.WriteOnly, bitmap.PixelFormat);
     Marshal.Copy(frame.Data, 0, data.Scan0, frame.Data.Length);
     bitmap.UnlockBits(data);
 }
Beispiel #2
0
        public unsafe bool TryDecode(ref VideoPacket packet, out VideoFrame frame)
        {
            if (_videoDecoder == null) _videoDecoder = new VideoDecoder();


            fixed (byte* pData = &packet.Data[0])
            {
                _avPacket.data = pData;
                _avPacket.size = packet.Data.Length;
                if (_videoDecoder.TryDecode(ref _avPacket, ref _avFrame))
                {
                    if (_videoConverter == null) _videoConverter = new VideoConverter(_pixelFormat.ToAVPixelFormat());

                    byte[] data = _videoConverter.ConvertFrame(ref _avFrame);

                    frame = new VideoFrame();
                    frame.Timestamp = packet.Timestamp;
                    frame.Number = packet.FrameNumber;
                    frame.Width = packet.Width;
                    frame.Height = packet.Height;
                    frame.Depth = data.Length/(packet.Width*packet.Height);
                    frame.PixelFormat = _pixelFormat;
                    frame.Data = data;
                    return true;
                }
            }
            frame = null;
            return false;
        }
Beispiel #3
0
 public static Bitmap CreateBitmap(ref VideoFrame frame)
 {
     PixelFormat pixelFormat = ConvertPixelFormat(frame.PixelFormat);
     var bitmap = new Bitmap(frame.Width, frame.Height, pixelFormat);
     if (pixelFormat == PixelFormat.Format8bppIndexed)
     {
         ColorPalette palette = bitmap.Palette;
         for (int i = 0; i < palette.Entries.Length; i++)
         {
             palette.Entries[i] = Color.FromArgb(i, i, i);
         }
         bitmap.Palette = palette;
     }
     UpdateBitmap(ref bitmap, ref frame);
     return bitmap;
 }
Beispiel #4
0
 private void OnVideoPacketDecoded(VideoFrame frame)
 {
     _frame = frame;
 }
Beispiel #5
0
        /// <summary>
        /// Stop video processing
        /// </summary>
        private void StopVideo()
        {
            timerVideoUpdate.Enabled = false;

            videoPacketDecoderWorker.Stop();
            videoPacketDecoderWorker.Join();
            frame = null;
            frameBitmap = null;
        }
 /// <summary>
 /// Determines what happens if a video packet is decoded.
 /// </summary>
 /// <param name="frame">Frame.</param>
 private void OnVideoPacketDecoded(VideoFrame frame)
 {
     data = frame.Data;
 }
Beispiel #7
0
 private void OnVideoPacketDecoded(VideoFrame videoFrame)
 {
     frame = videoFrame;
 }