2 * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
7 package eu.svjatoslav.meviz.encoder;
9 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
13 public class EncodingTask {
16 * Source file to encode
18 private final File source;
23 private final File target;
25 private final AbstractConverter converter;
26 private final String targetFormat;
27 private boolean useTerminal;
29 public EncodingTask(final File source, final File target, final AbstractConverter converter,
30 final String targetFormat) {
34 this.converter = converter;
35 this.targetFormat = targetFormat;
39 * @return the useTerminal
41 private boolean doUseTerminal() {
45 private String encodeApostrophes(final String input) {
46 final StringBuilder result = new StringBuilder();
48 for (final char c : input.toCharArray()) {
50 result.append("'\\''");
56 return result.toString();
59 public void execute(final EncodingOptions encodingOptions) {
61 String command = getCommand(encodingOptions);
64 command = "xterm -e '" + encodeApostrophes(command) + "'";
66 System.out.println("Executing command: " + command);
68 final Runtime runtime = Runtime.getRuntime();
69 final Process process = runtime.exec(new String[]{"/bin/bash", "-c", command});
73 } catch (final Exception e) {
74 System.out.println(e.toString());
80 private String getCommand(final EncodingOptions encodingOptions) {
81 return converter.getCommand(source, target, encodingOptions, targetFormat);
85 * @param useTerminal the useTerminal to set
87 public void setUseTerminal(final boolean useTerminal) {
88 this.useTerminal = useTerminal;