I have a programme that handles thousands of images as well as videos. I want to be able to read date-time metadata from them without having to save the whole image in memory. Currently the images are passed through my programme using an assortment of streams.
Eg. creating a thumbnail image:
public static void createThumbnailImage(Media media, TmpMedia tmpMedia) throws IOException {
PipedInputStream mediaIn = new PipedInputStream();
PipedOutputStream mediaOut = new PipedOutputStream(mediaIn);
new Thread(() -> {
try {
App.storage.getMedia(media, mediaOut);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Error getting Media for thumbnail", e);
}
}).start();
// Rest of code...
}
For one of my steps I require the date-time information. I hope that I only have to feed metadata-extractor a necessary number of bytes while storing them in a buffer, before getting the information and continuing as normal. Just saving all the data in a buffer is definitely not an option as my programme would run out of memory.
By default the metadata-extractor only reads the necessary segment bytes, therefore it is possible to simply store all the bytes that it uses in a buffer until the metadata-extractor finishes.
Using this class you get the metadata from an
InputStreamafter which you can do with the remaining bytes what you want to.