NODEJS Canvas to base64 png stream

Imagine that i have a client that only can read base64 images and i want to show that images like a realtime movie (as less latency as possible).

This images are created on server side using nodejs canvas lib. For each image that i send to the client i see the difference between them with imagediff nodejs lib and i only send the difference match image.

In the client side i show it putting the last image exactly over the previous ones (layers).

The problem is that in server side i have the following values that slow down the process:

  1. 16ms: after draw canvas:

  2. 42ms: imagediff (imagediff nodejs lib)

  3. [100 to 250ms] - toDataUrl (canvas to png base64 - canvas nodejs lib toBuffer().toString('base64'))

The big issue is in 3.

Do you have a different solution for this?

Thanks for your time.

Eduardo