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.IntegerParameter;
15 import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
16 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
18 public class CommandlineHandler {
20 Parser parser = new Parser();
22 StringParameters outputFormatParameter = parser.add(new StringParameters("Encoding output format."))
23 .addAliases("-o", "--output-format").setMandatory();
25 IntegerParameter targetFramerate = parser
26 .add(new IntegerParameter("Target framerate.").addAliases("-f", "--target-framerate"));
28 NullParameter deinterlaceParameter = parser.add(new NullParameter("Deinterlace video.")).addAliases("-d",
31 NullParameter testParameter = parser.add(new NullParameter("Simulate file encoding.")).addAliases("-t", "--test");
33 NullParameter recursiveParameter = parser.add(new NullParameter("Enable recursive mode.")).addAliases("-r",
36 NullParameter forPortableParameter = parser.add(new NullParameter("Encode for portable player.")).addAliases("-p",
39 StringParameters inputPatternParameter = parser.add(new StringParameters("File input pattern."))
40 .addAliases("-i", "--input-pattern").setMandatory();
42 DirectoryParameter workingDirectoryParameter = parser.add(new DirectoryParameter("Working directory."))
43 .addAliases("-w", "--working-directory").mustExist();
45 BitrateParameter videoBitrateParameter = parser.add(new BitrateParameter("Video bitrate")).addAliases("-v",
48 BitrateParameter audioBitrateParameter = parser.add(new BitrateParameter("Audio bitrate")).addAliases("-a",
52 * @return {@link EncodingOptions} if commandline arguments were
53 * successfully parsed, or <code>null</code> if parsing error
56 public EncodingOptions parseCommandlineArguments(final String[] args) {
58 final EncodingOptions options = new EncodingOptions();
62 options.setRecursive(recursiveParameter.isParameterSpecified());
64 options.setDeinterlace(deinterlaceParameter.isParameterSpecified());
66 options.setTestOnly(testParameter.isParameterSpecified());
68 if (outputFormatParameter.isParameterSpecified())
69 options.getOutputFormats().addAll(outputFormatParameter.getValue());
71 if (targetFramerate.isParameterSpecified())
72 options.setTargetFps(targetFramerate.getValue());
74 if (workingDirectoryParameter.isParameterSpecified())
75 options.setWorkingDirectory(workingDirectoryParameter.getValue());
77 if (inputPatternParameter.isParameterSpecified())
78 options.getInputPatterns().addAll(inputPatternParameter.getValue());
80 options.setForPortablePlayer(forPortableParameter.isParameterSpecified());
82 if (videoBitrateParameter.isParameterSpecified())
83 options.setVideoBitrate(videoBitrateParameter.getValue());
85 if (audioBitrateParameter.isParameterSpecified())
86 options.setAudioBitrate(audioBitrateParameter.getValue());