2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012 -- 2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.meviz.encoder;
12 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
16 public class EncodingTask {
19 * Source file to encode
21 private final File source;
26 private final File target;
28 private final AbstractConverter converter;
29 private final String targetFormat;
30 private boolean useTerminal;
32 public EncodingTask(final File source, final File target, final AbstractConverter converter,
33 final String targetFormat) {
37 this.converter = converter;
38 this.targetFormat = targetFormat;
42 * @return the useTerminal
44 private boolean doUseTerminal() {
48 private String encodeApostrophes(final String input) {
49 final StringBuilder result = new StringBuilder();
51 for (final char c : input.toCharArray()) {
53 result.append("'\\''");
59 return result.toString();
62 public void execute(final EncodingOptions encodingOptions) {
64 String command = getCommand(encodingOptions);
67 command = "xterm -e '" + encodeApostrophes(command) + "'";
69 System.out.println("Executing command: " + command);
71 final Runtime runtime = Runtime.getRuntime();
72 final Process process = runtime.exec(new String[]{"/bin/bash", "-c", command});
76 } catch (final Exception e) {
77 System.out.println(e.toString());
83 private String getCommand(final EncodingOptions encodingOptions) {
84 return converter.getCommand(source, target, encodingOptions, targetFormat);
88 * @param useTerminal the useTerminal to set
90 public void setUseTerminal(final boolean useTerminal) {
91 this.useTerminal = useTerminal;