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.Parser;
13 import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter;
14 import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
15 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
17 public class CommandlineHandler {
19 Parser parser = new Parser();
21 StringParameter outputFormatParameter = parser
22 .createStringParameter("Encoding output format.")
23 .addAliases("-o", "--output-format").setMandatory();
25 NullParameter deinterlaceParameter = parser.createNullParameter(
26 "Deinterlace video.").addAliases("--deinterlace", "-d");
28 NullParameter testParameter = parser.createNullParameter(
29 "Simulate file encoding.").addAliases("-t", "--test");
31 NullParameter recursiveParameter = parser.createNullParameter(
32 "Enable recursive mode.").addAliases("-r", "--recursive");
34 NullParameter forPortableParameter = parser.createNullParameter(
35 "Encode for portable player.").addAliases("-p", "--portable");
37 StringParameter inputPatternParameter = parser
38 .createStringParameter("File input pattern.")
39 .addAliases("-i", "--input-pattern").setMandatory();
41 DirectoryParameter workingDirectoryParameter = parser
42 .createDirectoryParameter("Working directory.")
43 .addAliases("-w", "--working-directory").mustExist();
45 BitrateParameter videoBitrateParameter = new BitrateParameter(
48 public CommandlineHandler() {
49 videoBitrateParameter.addAliases("-v", "--video-bitrate");
50 parser.addParameter(videoBitrateParameter);
54 * @return {@link EncodingOptions} if commandline arguments were
55 * successfully parsed, or <code>null</code> if parsing error
58 public EncodingOptions parseCommandlineArguments(final String[] args) {
60 final EncodingOptions options = new EncodingOptions();
64 options.recursive = recursiveParameter.isParameterSpecified();
66 options.deinterlace = deinterlaceParameter.isParameterSpecified();
68 options.testOnly = testParameter.isParameterSpecified();
70 if (outputFormatParameter.isParameterSpecified())
71 options.outputFormats.addAll(outputFormatParameter
72 .getArgumentsAsStrings());
74 if (workingDirectoryParameter.isParameterSpecified())
75 options.workingDirectory = workingDirectoryParameter
76 .getArgumentsAsFiles().get(0);
78 if (inputPatternParameter.isParameterSpecified())
79 options.inputPatterns.addAll(inputPatternParameter
80 .getArgumentsAsStrings());
82 options.forPortablePlayer = forPortableParameter.isParameterSpecified();
84 if (videoBitrateParameter.isParameterSpecified())
86 options.videoBitrate = videoBitrateParameter.getValue();
87 } catch (final Exception e) {
89 .println("Invalid video bitrate. Valid values are: LOW, MEDIUM, HIGH.");