Working with uncompressed 4k .avi files in Fiji

Hi there,
I’m fairly new to macro-programming in FIJI and programming in general so bear with me here pls.

I’m working with uncompressed 4k .avi-files for image analysis in the macroscale. The version of ImageJ is 1.52p. Each image is opened as a virtual stack first, then duplicated to split the color channels and in the end only save one of them to save space. All of this is being done with a macro, which works well.

Except for files bigger than ~8 GB. With this file size it’s not possible for Fiji to do all these steps on my machine with ~50 GB of ram allocated, always crashing Fiji with the “out of memory” prompt.

So my idea would be to only duplicate 1/4 of every stack at once, do the processing and later put them back together. And here is where I’m struggling:

I can’t find a way to store the frame number or stackSize as a variable, since the “getSliceNumber()” command doesn’t work for .avi, and Fiji only outputs “1” as an error.

Would be really nice to know the command, or if anyone here has another idea to solve my problem.

Thanks in advance!


So i think i found a workaround:

In my macro i had to duplicate the avi-stacks to work with them in another workflow and just stuck to this instead of trying to split the color channels without duplicating first. So it turns out that I indeed can split the color channels of my uncompressed avi-stack (converted from 4k H.265 to H.264 via ffmpeg) directly after opening as an virtual-stack in FIJI.

So for now my RAM-problems are solved, because splitting is apparently CPU-heavy. That is until i will have a file that exceeds RAM-limitations while opening.

So if anyone can tell me, how to get the frame number out of my .avi-files or otherwise optimize my workflow, this would be highly appreciated!

I looked into the .avi-Reader from ImageJ and I found somethink with “totalFramesFromIndex” and “dwTotalFrames” but I have no idea, if I can use this information to read the frame numbers of my videos and store it as a variable.


I found another factor in my macro:

I already said, that I’m new to programming and i was opening the files with the AVI-reader NOT in a virtual stack the whole time with:

run(“AVI…”, “select=inputPath”)

In another blog-post i found out that you have to use ‘use’ as an argument to open as a virtual stack:

run(“AVI…”, “select=inputPath use”)

So nooooow I’m not only saving a bunch of RAM while the macro is running, but i also don’t have to wait for FIJI to open up the images in a non-virtual stack, which took way too long and where i noticed that something is different between doing it manually vs. the macro.

So I guess this thread can be seen as answered.

Just out of curiosity i would really like to know the answer to my original question!

Thanks everyone anyway because I found the answer to my problems with the help of this forum in particular!


Hi Jan,

sorry, I don’t use Fiji, only plain ImageJ. There I can select which images to open when importing an AVI as virtual stack. The command recorder gives me something like this:

run("AVI...", "open="+filepathandname+" first=101 last=200 use");

By the way, if you want, you can also delete slices of a virtual stack to free memory.

Without writing a plugin, I see no direct way to combine stacks into one big avi if you can’t have the whole stack in memory. What you can do, however, is saving all the individual images in one directory, import it as Image Sequence into a virtual stack, and write that into an AVI.

The macro command getSliceNumber() does work on stacks from AVI files (no matter whether a virtual stack or not), but the first slice will be always 1, the next one 2, etc, irrespective of whether you have started reading at frame 1 or 101 (as in the example above). Also deleted slices don’t count.

You can store a “label” for each slice with setMetadata("Label", string), and retrieve it with getMetadata("Label") when the particular slice is selected. When saving the avi as image sequence, you can select that you want these labels as filenames.

– Michael

Hi Michael,

thanks for your insight anyway.

Just to set things straigth, i have no intention to combine stacks back to an avi but rather directly to a TIFF-stack. I also thought about the process of saving each frame as an individual file, processing every image, saving them again and then recombine them. But i think, without having it tried out, that this process would be rather timeconsuming and definitely more complicated than doing the processing on the entire stack in the first place.

Unfortunately, processing only selected slices in an automated way, ist not possible for my use case, because the desired process in the video which i want to analyse starts at different frames for each video^^

But i really appreciate you taking the time and giving some ideas for my process =)