Handling very high page count MultiPage Tiffs
Posted: 2019-02-08T16:03:23-07:00
I need to process some very large MultipageTiff documents (some in excess of 10k frames/images/pages). MagickImageCollection appears to populate the pixel caches for every single frame of the image when the collection is opened (using ~25MB per image) which quickly consumes vast quantities of disk space, and in some cases fills the disk completely causing crashes (this generally happens if there are multiple high page count documents that get processed around the same time).
Is there method in Magick.Net to get the total frame count from the file prior having MagickImageCollection process/open it (I haven't been able to find one)? I would like to handle the pages in batches to minimize the disk impact - and have the following code which works quite well as long as I know the frame count up front, With a batch size of 25 - it doesn't generate any cache files at all (which is ideal) If I go to 50, it does generate 15 to 20 caches depending on source material used.
Also open to any other suggestions on how to address this.
Thanks!
Is there method in Magick.Net to get the total frame count from the file prior having MagickImageCollection process/open it (I haven't been able to find one)? I would like to handle the pages in batches to minimize the disk impact - and have the following code which works quite well as long as I know the frame count up front, With a batch size of 25 - it doesn't generate any cache files at all (which is ideal) If I go to 50, it does generate 15 to 20 caches depending on source material used.
Code: Select all
var fileName = "testFile.tiff";
var batchSize = 25;
var frameCount = this.GetFrameCount(fileName); // How do I do this part?
for (var i = 0; i < frameCount; i += batchSize)
{
var settings = new MagickReadSettings();
settings.FrameCount = i + batchSize >= frameCount ? frameCount - i : batchSize;
settings.FrameIndex = i;
using (var imageCollection = new MagickImageCollection(fileName, settings))
{
foreach (var image in imageCollection)
{
// Do Stuff Here.
}
}
}
Thanks!