Skip to content

Support for true streaming #60

Open
@jcupitt

Description

@jcupitt

Hello all,

git master libvips has a new feature which might be relevant to the image_processing gem: true streaming. There's a short note about it here:

https://libvips.github.io/libvips/2019/11/29/True-streaming-for-libvips.html

You can now connect libvips image processing pipelines directly to any source or destination and it'll process data in a fully streaming manner. For example, you could fetch bytes from one URI (perhaps an S3 bucket), process, and write to another URI (perhaps a different bucket) in parallel and with no buffering.

We don't have any benchmarks yet, but we hope that this will produce a useful drop in latency. It should be fun to experiment with anyway. I don't think (as far as I know) anyone has done this before.

This branch of ruby-vips adds support:

https://github.com/libvips/ruby-vips/tree/add-stream

You can see examples of the proposed API here:

https://github.com/libvips/ruby-vips/blob/add-stream/spec/stream_spec.rb

Sample:

      streami = Vips::Streami.new_from_descriptor 12
      image = Vips::Image.new_from_stream streami, '', access: :sequential
      streamo = Vips::Streamo.new_to_descriptor 13 
      image.write_to_stream streamo, '.png'

So that'll stream pixels between file descriptors 12 and 13 (perhaps they are pipes connected to S3 URIs), reading any supported image format, and writing as PNG.

You can do anything in the pipeline (blur, rotate, composite, etc.). There's thumbnail_stream which can efficiently thumbnail images directly from a stream source. You can also open streams multiple times, examine the header and adjust parameters without actually processing pixels.

Questions!

  1. Does this look interesting?
  2. How does image_processing hook up to storage systems like S3 at the moment?
  3. Is the proposed API enough, or do you need to be able to make a custom stream class? That would require a little more work on ruby-vips.
  4. I've no idea if support could be added without breaking your API. Perhaps you could allow URIs where you now allow filenames?
  5. Any comments, changes or fixes would be extremely welcome, of course.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions