2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, 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.commons.commandline.parameterparser.Parameter;
13 import eu.svjatoslav.commons.commandline.parameterparser.Parser;
14 import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument;
16 public class CommandlineHandler {
18 Parameter outputFormatParameter = new Parameter(true, true, true,
19 new StringArgument(), "Encoding output format.", "-o",
22 Parameter terminalParameter = new Parameter("Enable popup terminal.",
25 Parameter deinterlaceParameter = new Parameter("Deinterlace video.",
26 "--deinterlace", "-d");
28 Parameter testParameter = new Parameter("Simulate file encoding.", "-t",
31 Parameter recursiveParameter = new Parameter("Enable recursive mode.",
34 Parameter inputPatternParameter = new Parameter(true, true, true,
35 new StringArgument(), "File input pattern.", "-i",
38 Parameter workingDirectoryParameter = new Parameter(
42 new eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory(),
43 "Working directory.", "-w", "--working-directory");
45 Parameter videoBitrateParameter = new Parameter(false, true, false,
46 new Bitrate(), "Video bitrate.", "-v", "--video-bitrate");
48 public Parser initParser() {
49 final Parser parser = new Parser();
51 parser.addParameter(recursiveParameter);
53 parser.addParameter(deinterlaceParameter);
55 parser.addParameter(testParameter);
57 parser.addParameter(terminalParameter);
59 parser.addParameter(outputFormatParameter);
61 parser.addParameter(inputPatternParameter);
63 parser.addParameter(workingDirectoryParameter);
65 parser.addParameter(videoBitrateParameter);
71 * @return {@link EncodingOptions} if commandline arguments were
72 * successfully parsed, or <code>null</code> if parsing error
75 public EncodingOptions parseCommandlineArguments(final String[] args) {
77 final EncodingOptions options = new EncodingOptions();
79 final Parser parser = initParser();
82 if (recursiveParameter.isParameterSpecified())
83 options.recursive = true;
85 if (deinterlaceParameter.isParameterSpecified())
86 options.deinterlace = true;
88 if (terminalParameter.isParameterSpecified())
89 options.terminal = true;
91 if (testParameter.isParameterSpecified())
92 options.testOnly = true;
94 if (outputFormatParameter.isParameterSpecified())
95 options.outputFormats.addAll(outputFormatParameter
96 .getArgumentsAsStrings());
98 if (workingDirectoryParameter.isParameterSpecified())
99 options.workingDirectory = workingDirectoryParameter
100 .getArgumentsAsFiles().get(0);
102 if (inputPatternParameter.isParameterSpecified())
103 options.inputPatterns.addAll(inputPatternParameter
104 .getArgumentsAsStrings());
106 if (videoBitrateParameter.isParameterSpecified())
108 options.videoBitrate = Bitrate.bitrate
109 .valueOf(videoBitrateParameter.getArgumentAsString()
111 } catch (final Exception e) {
113 .println("Invalid video bitrate. Valid values are: LOW, MEDIUM, HIGH.");