use of org.fagu.fmv.core.project.Project in project fmv by f-agu.
the class Bootstrap method newProject.
/**
* @param printStream
* @return
*/
private static Project newProject(PrintStream printStream) {
try (Scanner scanner = new Scanner(new UnclosedInputStream(System.in))) {
// name
printStream.print("Name: ");
String name = scanner.nextLine();
// save file
final File defaultSaveFile = new File(name);
printStream.print("SaveFolder: [" + defaultSaveFile.getAbsolutePath() + "] ");
File saveFile = null;
String ssavefile = scanner.nextLine();
if (StringUtils.isBlank(ssavefile)) {
saveFile = defaultSaveFile;
} else {
saveFile = new File(ssavefile);
}
saveFile = new File(saveFile, name + ".fmv");
saveFile.getParentFile().mkdirs();
// format
final String defaultFormat = "mp4";
printStream.print("Format: [" + defaultFormat + "] ");
String format = scanner.nextLine();
if (StringUtils.isBlank(format)) {
format = defaultFormat;
}
// size
final Size defaultSize = Size.HD720;
printStream.print("Size: [" + defaultSize + "] ");
Size size = null;
while (size == null) {
String ssize = scanner.nextLine();
if (StringUtils.isBlank(ssize)) {
size = defaultSize;
} else {
try {
size = Size.parse(ssize);
} catch (IllegalArgumentException e) {
printStream.println("Don't understand: " + ssize);
}
}
}
// rate
final FrameRate defaultRate = FrameRate.valueOf(30, 1);
printStream.print("Rate: [" + defaultRate + "] ");
FrameRate frameRate = null;
while (frameRate == null) {
String srate = scanner.nextLine();
if (StringUtils.isBlank(srate)) {
frameRate = defaultRate;
} else {
try {
frameRate = FrameRate.parse(srate);
} catch (IllegalArgumentException e) {
printStream.println("Don't understand: " + srate);
}
}
}
OutputInfos outputInfos = new OutputInfos();
outputInfos.setSize(size);
outputInfos.setFrameRate(frameRate);
// TODO
outputInfos.setAudioSampling(44100);
outputInfos.setFormat(format);
Project project = new Project(saveFile, outputInfos);
project.setName(name);
try {
project.save();
} catch (IOException e) {
throw new RuntimeException(e);
}
return project;
}
}
use of org.fagu.fmv.core.project.Project in project fmv by f-agu.
the class DefaultCommandBuilder method add.
/**
* @see org.fagu.fmv.cli.CommandBuilder#add(java.lang.Class)
*/
@Override
public void add(final Class<? extends Command> cmdClass) {
final org.fagu.fmv.cli.annotation.Command cmd = cmdClass.getAnnotation(org.fagu.fmv.cli.annotation.Command.class);
if (cmd == null) {
throw new RuntimeException("Annotation @Command not found: " + cmdClass.getName());
}
add(new CommandFactory() {
/**
* @see org.fagu.fmv.cli.CommandFactory#getCommandName()
*/
@Override
public String getCommandName() {
return cmd.value();
}
/**
* @see org.fagu.fmv.cli.CommandFactory#create(jline.console.ConsoleReader, org.fagu.fmv.cli.CommandBuilder,
* org.fagu.fmv.core.project.Project, java.lang.String, String[])
*/
@Override
public Command create(ConsoleReader consoleReader, CommandBuilder commandBuilder, Project project, String executable, String[] args) throws LineParseException {
return build(cmdClass);
}
});
// alias
List<Alias> aliases = new ArrayList<>();
Aliases aliasesAnno = cmdClass.getAnnotation(Aliases.class);
if (aliasesAnno != null) {
aliases.addAll(Arrays.asList(aliasesAnno.value()));
}
Alias aliasAnno = cmdClass.getAnnotation(Alias.class);
if (aliasAnno != null) {
aliases.add(aliasAnno);
}
if (!aliases.isEmpty()) {
for (Alias alias : aliases) {
String aliasCommand = alias.command();
if (StringUtils.isBlank(aliasCommand)) {
aliasCommand = cmd.value();
}
for (String aliasName : alias.value()) {
addAlias(aliasName, aliasCommand);
}
}
}
// completion
Completion completion = cmdClass.getAnnotation(Completion.class);
if (completion != null) {
try {
@SuppressWarnings("unchecked") Class<CompleterFactory> completerFactoryClass = (Class<CompleterFactory>) Class.forName(completion.value());
CompleterFactory completerFactory = completerFactoryClass.newInstance();
Completer completer = completerFactory.create(cmd.value());
completerMap.add(cmd.value(), completer);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
use of org.fagu.fmv.core.project.Project in project fmv by f-agu.
the class Bootstrap method loadProject.
/**
* @param saveFile
* @return
*/
private static Project loadProject(File saveFile) {
System.out.println("Loading " + saveFile.getName() + " ...");
Project project = new Project(saveFile);
try {
project.load();
} catch (LoadException e) {
throw new RuntimeException(e);
}
return project;
}
use of org.fagu.fmv.core.project.Project in project fmv by f-agu.
the class Bootstrap method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
if (!FFMpeg.search().isFound()) {
System.out.println("FFMpeg not found !");
return;
}
if (!FFProbe.search().isFound()) {
System.out.println("FFProbe not found !");
return;
}
CommandLineParser parser = new GnuParser();
Options options = new Options();
options.addOption("c", "conf", true, "Conf properties");
CommandLine commandLine = parser.parse(options, args);
FMVCLIConfig fmvcliConfig;
if (commandLine.hasOption('c')) {
String conf = commandLine.getOptionValue('c');
fmvcliConfig = openFMVCLIConfig(conf);
} else {
fmvcliConfig = new FMVCLIConfig();
}
System.out.println("FMV " + FMV.getVersion());
System.out.println();
Project project;
String[] args2 = commandLine.getArgs();
if (args2.length > 0) {
project = loadProject(new File(args2[0]));
} else {
project = menu(System.out);
}
Console console = new Console(new Environnement(project, fmvcliConfig));
console.run();
}
Aggregations