What is a fast way to generate and draw video in WPF?

前端 未结 1 373
萌比男神i
萌比男神i 2021-01-03 03:49

I am writing a video player to play back frames captured by our ASIC. They are in a custom format, and I have been provided with a function that decodes the ASIC states. The

相关标签:
1条回答
  • 2021-01-03 04:10

    If I understand correctly you receive a 16*16 pixel block as a capture, and in the example above you are then updating the writeable bitmap on each of these updates.

    This looks like a lot of churn as a render is being triggered on each block.

    Would it not be better to:

    • Maintain a single byte buffer that represents an entire frame.
    • Update the buffer with your 16*16 blocks as you receive them.
    • When you have received all blocks for a frame, write the buffer to the bitmap.
    • Re-use the frame buffer for the next frame by over-writing it.

    In this way you will have far less churn on rendering as you will not trigger a render for each block you receive, but only for each frame.

    Update 1

    I would also consider using Bgr24 as your pixel format if you are not using an alpha channel. That way you will have 3 bytes per pixel, instead of 4, so quite a lot less overhead.

    Update 2

    If things are still too slow for larger frame sizes, you could also consider the following which adds complexity though.

    Consider maintaining and flipping two frame buffers. In this way you could composite frames on a background thread and then blit the finished frame on the UI thread. Whist the UI thread is rendering the frame, you can continue compositing on the alternative buffer.

    Update 3

    If your pixel colour info array from your capture is in the correct format, you could try using Buffer.BlockCopy to bulk copy the source pixel array into the frame buffer array. You would have to keep your bitmap format as bgr32 though. This low level array copying technique could yield some performance gains.

    0 讨论(0)
提交回复
热议问题