85 lines
2.5 KiB
Java
85 lines
2.5 KiB
Java
package org.jcodec.movtool;
|
|
|
|
import java.io.File;
|
|
import java.nio.channels.FileChannel;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import org.jcodec.containers.mp4.boxes.MovieBox;
|
|
|
|
public class QTEdit {
|
|
protected final EditFactory[] factories;
|
|
|
|
private final List<Flatten.ProgressListener> listeners;
|
|
|
|
public static abstract class BaseCommand implements MP4Edit {
|
|
public void applyRefs(MovieBox movie, FileChannel[][] refs) {
|
|
apply(movie);
|
|
}
|
|
|
|
public abstract void apply(MovieBox param1MovieBox);
|
|
}
|
|
|
|
public QTEdit(EditFactory[] editFactories) {
|
|
this.listeners = new ArrayList<>();
|
|
this.factories = editFactories;
|
|
}
|
|
|
|
public void addProgressListener(Flatten.ProgressListener listener) {
|
|
this.listeners.add(listener);
|
|
}
|
|
|
|
public void execute(String[] args) throws Exception {
|
|
LinkedList<String> aa = new LinkedList<>(Arrays.asList(args));
|
|
List<MP4Edit> commands = new LinkedList<>();
|
|
while (aa.size() > 0) {
|
|
int i;
|
|
for (i = 0; i < this.factories.length; i++) {
|
|
if (aa.get(0).equals(this.factories[i].getName())) {
|
|
aa.remove(0);
|
|
try {
|
|
commands.add(this.factories[i].parseArgs(aa));
|
|
} catch (Exception e) {
|
|
System.err.println("ERROR: " + e.getMessage());
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (i == this.factories.length)
|
|
break;
|
|
}
|
|
if (aa.size() == 0) {
|
|
System.err.println("ERROR: A movie file should be specified");
|
|
help();
|
|
}
|
|
if (commands.size() == 0) {
|
|
System.err.println("ERROR: At least one command should be specified");
|
|
help();
|
|
}
|
|
File input = new File((String)aa.remove(0));
|
|
if (!input.exists()) {
|
|
System.err.println("ERROR: Input file '" + input.getAbsolutePath() + "' doesn't exist");
|
|
help();
|
|
}
|
|
new ReplaceMP4Editor().replace(input, new CompoundMP4Edit(commands));
|
|
}
|
|
|
|
protected void help() {
|
|
System.out.println("Quicktime movie editor");
|
|
System.out.println("Syntax: qtedit <command1> <options> ... <commandN> <options> <movie>");
|
|
System.out.println("Where options:");
|
|
for (EditFactory commandFactory : this.factories)
|
|
System.out.println("\t" + commandFactory.getHelp());
|
|
System.exit(-1);
|
|
}
|
|
|
|
public static interface EditFactory {
|
|
String getName();
|
|
|
|
MP4Edit parseArgs(List<String> param1List);
|
|
|
|
String getHelp();
|
|
}
|
|
}
|