//Movie to Hyperstack macro //December 16, 2021 //Jeff Hardin, Univ. of Wiscomsin-Madison //Uses Stanislav Chizhak's Ffmpeg import plugin to read a QuickTime movie file //and import into a virtual HyperStack. Allows legacy 4d footage to //be imported into 64-bit systems now that QuickTime for Java is deprecated. //July 24, 2025: added call to detect if the FFmpeg plugin is installed List.setCommands; if (List.get("Import Movie Using FFmpeg...")!="") { // plugin is installed } else { showMessage("Plugin not found", "This script requires the Import Movie Using FFmpeg... plugin."); exit(); } path = File.openDialog("Select a File"); //print("Path:" + path); //open(path); // open the file dir = File.getParent(path); name = File.getName(path); //tries to retrieve an info file. Older ones had the name ",info"; newer ones had ".txt". infoPath = substring(path,0,lastIndexOf(path,".")) + ".info"; textPath = substring(path,0,lastIndexOf(path,".")) + ".txt"; fullTextPath = path + ".txt"; myPath = ""; if (File.exists(infoPath)) {myPath = infoPath;} else if (File.exists(textPath)) {myPath = textPath;} else if (File.exists(fullTextPath)) {myPath = fullTextPath;} //print("My path: " + myPath); focalPlanes = 1; if (myPath != "") { //print("Found focal planes:"); infoString = File.openAsString(myPath); // open the file lines=split(infoString,"\n"); //print(lines[1]); movieInfo = lines[0]; //The info files is sensitive to leading spaces in the focal plane line, //which I believe is due to the macro language. focalPlanes = parseInt(lines[1]); //print("Focal planes: ", focalPlanes); } else //if no info file with the appropriate root can be found, ask for focal planes { Dialog.create("Enter focal planes"); Dialog.addNumber("Couldn't get focal planes. Focal planes: ", 1); Dialog.show(); focalPlanes = Dialog.getNumber();; if (focalPlanes < 1) {focalPlanes = 1;} movieInfo = ""; } run("Import Movie Using FFmpeg...", "open=[" + path + "] frame=[leave as is]"); //print("Got to opening movie!"); //get total images, contained in the slices field in next line getDimensions(w, h, channels, slices, frames); close(); print("\\Clear"); print("Total images: " + slices); //now get time points timePoints = slices/focalPlanes; print("Time points: " + timePoints); String.show("Movie info", "Movie info:\n" + movieInfo + "\n" + "\n" + "Focal planes: " + focalPlanes + "\nTime points: " + timePoints); run("Import Movie Using FFmpeg...", "open=[" + path + "] frame_sequence=[transform to hyperstack] hyperstack_order=xyctz slices_(z)=" + focalPlanes + " frames_(t)=" + timePoints);