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.StringParameters;
17 public class CommandlineHandler {
19 Parser parser = new Parser();
21 StringParameters outputFormatParameter = parser
22 .add(new StringParameters("Encoding output format."))
23 .addAliases("-o", "--output-format").setMandatory();
25 NullParameter deinterlaceParameter = parser.add(
26 new NullParameter("Deinterlace video.")).addAliases(
27 "--deinterlace", "-d");
29 NullParameter testParameter = parser.add(
30 new NullParameter("Simulate file encoding.")).addAliases("-t",
33 NullParameter recursiveParameter = parser.add(
34 new NullParameter("Enable recursive mode.")).addAliases("-r",
37 NullParameter forPortableParameter = parser.add(
38 new NullParameter("Encode for portable player.")).addAliases("-p",
41 StringParameters inputPatternParameter = parser
42 .add(new StringParameters("File input pattern."))
43 .addAliases("-i", "--input-pattern").setMandatory();
45 DirectoryParameter workingDirectoryParameter = parser
46 .add(new DirectoryParameter("Working directory."))
47 .addAliases("-w", "--working-directory").mustExist();
49 BitrateParameter videoBitrateParameter = parser.add(
50 new BitrateParameter("Video bitrate")).addAliases("-v",
53 BitrateParameter audioBitrateParameter = parser.add(
54 new BitrateParameter("Audio bitrate")).addAliases("-a",
58 * @return {@link EncodingOptions} if commandline arguments were
59 * successfully parsed, or <code>null</code> if parsing error
62 public EncodingOptions parseCommandlineArguments(final String[] args) {
64 final EncodingOptions options = new EncodingOptions();
68 options.recursive = recursiveParameter.isParameterSpecified();
70 options.deinterlace = deinterlaceParameter.isParameterSpecified();
72 options.testOnly = testParameter.isParameterSpecified();
74 if (outputFormatParameter.isParameterSpecified())
75 options.outputFormats.addAll(outputFormatParameter.getValue());
77 if (workingDirectoryParameter.isParameterSpecified())
78 options.workingDirectory = workingDirectoryParameter.getValue();
80 if (inputPatternParameter.isParameterSpecified())
81 options.inputPatterns.addAll(inputPatternParameter.getValue());
83 options.forPortablePlayer = forPortableParameter.isParameterSpecified();
85 if (videoBitrateParameter.isParameterSpecified())
87 options.setVideoBitrate(videoBitrateParameter.getValue());
88 } catch (final Exception e) {
90 .println("Invalid video bitrate. Valid values are: LOW, MEDIUM, HIGH.");