use of argparser.DoubleHolder in project artisynth_core by artisynth.
the class MovieMaker method render.
/**
* Renders captured data to a movie with the specified file name.
*/
public void render(String fn) throws Exception {
if (lastFrameCount == 0) {
Main.getMain().getLogger().info("No frames grabbed, no movie to make");
return;
}
// wait for all frames to be done writing
myViewer.awaitScreenShotCompletion();
Method method = myMethodMap.get(myMethodName);
if (myMethodName.equals(INTERNAL_METHOD)) {
String[] frameFileNames = new String[lastFrameCount];
for (int i = 1; i <= lastFrameCount; i++) {
frameFileNames[i - 1] = getFrameFileName(i);
}
new MakeMovieFromData(frameFileNames, dataPath, fn + ".mov");
} else if (myMethodName.equals(ANIMATED_GIF_METHOD)) {
String opts = method.command;
opts = opts.replaceAll("\\$FPS", "" + frameRate);
String[] frameFileNames = new String[lastFrameCount];
for (int i = 1; i <= lastFrameCount; i++) {
frameFileNames[i - 1] = getFrameFileName(i);
}
File outFile = new File(dataPath + File.separator + fn + ".gif");
DoubleHolder delayHolder = new DoubleHolder(0);
IntHolder loopHolder = new IntHolder(0);
AnimatedGifWriter.parseArgs(opts, delayHolder, loopHolder);
AnimatedGifWriter.write(outFile, frameFileNames, delayHolder.value, loopHolder.value);
} else {
// Custom method, execute the specified command in data directory.
String cmd = method.command;
cmd = cmd.replaceAll("\\$FPS", "" + frameRate);
cmd = cmd.replaceAll("\\$FMT", myFormat);
String[] cmdArray = cmd.split("\\s+");
// Substitute $OUT later because file name might contain white space
String finalCmd = "";
for (int i = 0; i < cmdArray.length; i++) {
cmdArray[i] = cmdArray[i].replaceAll("\\$OUT", fn);
finalCmd = finalCmd + " " + cmdArray[i];
}
// Map<String, String> env = System.getenv();
// File dataFile = new File(dataPath);
// Process proc = Runtime.getRuntime().exec (
// cmdArray, /*env=*/null, null);
Main.getMain().getLogger().info("Executing " + finalCmd);
ProcessBuilder procBuild = new ProcessBuilder(cmdArray);
procBuild.directory(new File(dataPath));
Process proc = procBuild.start();
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), System.err, ">>");
// any output?
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), System.out, ">>");
// start gobblers
outputGobbler.start();
errorGobbler.start();
int exitVal = proc.waitFor();
if (exitVal != 0) {
Main.getMain().getLogger().error("\nMovie creation failed with exit value: " + exitVal + "\n");
}
}
}
use of argparser.DoubleHolder in project artisynth_core by artisynth.
the class AnimatedGifWriter method parseArgs.
/**
* Parses options, fills in the delay and loop values
* @param args list of arguments
* @param delayHolder output delay time (s)
* @param loopHolder output loop count
*/
public static String[] parseArgs(String[] args, DoubleHolder delayHolder, IntHolder loopHolder) {
ArgParser parser = new ArgParser("java java.core.moviemaker.AnimatedGifWriter [options] " + "<list of input files> < output file>");
DoubleHolder fpsHolder = new DoubleHolder(0);
parser.addOption("-help %h #prints help message", null);
parser.addOption("-delay %f #delay between frames (s)", delayHolder);
parser.addOption("-fps %f #frames per second", fpsHolder);
parser.addOption("-loop %d #number of times to play (-1 for infinite)", loopHolder);
String[] left = parser.matchAllArgs(args, 0, 0);
// favour fps
if (fpsHolder.value > 0) {
delayHolder.value = 1.0 / fpsHolder.value;
}
return left;
}
use of argparser.DoubleHolder in project artisynth_core by artisynth.
the class AnimatedGifWriter method main.
/**
* Main function
* Usage: java artisynth.core.moviemaker.AnimatedGifWriter [options] <list of input files> <output file>
*/
public static void main(String[] args) throws Exception {
DoubleHolder delayHolder = new DoubleHolder(0);
IntHolder loopHolder = new IntHolder(1);
String[] left = parseArgs(args, delayHolder, loopHolder);
if (left == null || left.length < 2) {
return;
}
ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>(left.length);
for (int i = 0; i < left.length - 1; i++) {
try {
BufferedImage image = ImageIO.read(new File(left[i]));
imageList.add(image);
} catch (Exception e) {
System.err.println("Cannot read " + left[i] + ", ignoring");
}
}
String outputFile = left[left.length - 1];
if (imageList.size() > 0) {
write(new File(outputFile), imageList, delayHolder.value, loopHolder.value);
}
}
Aggregations