jpeg-decoder icon indicating copy to clipboard operation
jpeg-decoder copied to clipboard

Reusing memory between frames

Open Boscop opened this issue 7 years ago • 2 comments

It would be useful if one could reuse memory between frames for decoding MJPEG from a webcam at FullHD, 30 fps. Also it would be great if one could reuse the rayon threads across frames. Not restart them for every frame. Currently I always have to compile in release mode to get realtime decoding.. In debug mode I don't even get 2 fps :(

Boscop avatar Sep 27 '17 22:09 Boscop

Memory allocations and thread spawning are not the bottlenecks in jpeg-decoder. Spawning threads is really cheap (my mid-range desktop can spawn 50,000 of them a second) and reducing the amount of allocations didn't measurably impact performance.

Rust version 1.41 introduced the possibility to override the profile of a dependency. This would allow you to compile jpeg-decoder in release mode and the rest in debug. Assuming you need to debug only inside your own code this should give you the best of both worlds: fast image loading and the usual debug symbols. Try this:

[profile.dev.package.jpeg-decoder] 
opt-level = 2

More info: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1410-2020-01-30

Shnatsel avatar Nov 20 '20 14:11 Shnatsel

@Shnatsel Thanks for the response :) I ended up using mozjpeg instead (at first), it was much faster. But in the end I then actually switched to using a ffmpeg sub process for Webcam input, so that it works with any frame encoding (just by specifying which combination of fps and resolution I want from the Webcam) and it gives me rgb data over a pipe into my process. Do you see any way to improve this too? :)

Boscop avatar Nov 22 '20 12:11 Boscop