Skip to content
Snippets Groups Projects
exportAvi.ijm 1.1 KiB
Newer Older
//Batch macro to export avi files from supplied tiff stacks.
// Arguments string should be a list of absolute file paths to process.

//This macro can be called in Fiji's headless mode e.g.
// imagej --headless -macro /path-to-macro.ijm /path-to-file.tif
Marius Hintsche's avatar
Marius Hintsche committed
// or by runMacro(macro, arg)

outExtension = ".avi";
fileList = split(getArgument());
Marius Hintsche's avatar
Marius Hintsche committed

setBatchMode(true);
for (i = 0; i < fileList.length; i++) {
    //parse file name
    dotIndex = lastIndexOf(fileList[i], ".");
    if (dotIndex >= 0) {
        baseName = substring(fileList[i], 0, dotIndex);
    }
    outFile = baseName+outExtension;

    // escape spaces in path with \ and "" // does not work!
    //outFile = "\"" + outFile + "\"";
    //outFile = replace(outFile, " ", "\\\\\\\\ ");
    if ( indexOf(outFile," ") >= 0 ) {
        exit("Input path must no contain whitespace!");
    }
    //print("will export to "+outFile);

    open(fileList[i]);

    //processing steps
    //frameRate = Stack.getFrameRate();
    run("8-bit");
    run("AVI... ", "compression=JPEG frame="+frameRate+" save="+outFile);

    close();
}
Marius Hintsche's avatar
Marius Hintsche committed
setBatchMode(false);