2 * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
7 package eu.svjatoslav.meviz.encoder;
9 import eu.svjatoslav.commons.commandline.parameterparser.Parser;
10 import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter;
11 import eu.svjatoslav.commons.commandline.parameterparser.parameter.IntegerParameter;
12 import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
13 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
15 class CommandlineHandler {
17 final Parser parser = new Parser();
19 private final StringParameters outputFormatParameter = parser.add(new StringParameters("Encoding output format."))
20 .addAliases("-o", "--output-format").setMandatory();
22 private final IntegerParameter targetFramerate = parser
23 .add(new IntegerParameter("Target framerate.").addAliases("-f", "--target-framerate"));
25 private final NullParameter deinterlaceParameter = parser.add(new NullParameter("Deinterlace video.")).addAliases("-d",
28 private final NullParameter testParameter = parser.add(new NullParameter("Simulate file encoding.")).addAliases("-t", "--test");
30 private final NullParameter recursiveParameter = parser.add(new NullParameter("Enable recursive mode.")).addAliases("-r",
33 private final NullParameter forPortableParameter = parser.add(new NullParameter("Encode for portable player.")).addAliases("-p",
36 private final StringParameters inputPatternParameter = parser.add(new StringParameters("File input pattern."))
37 .addAliases("-i", "--input-pattern").setMandatory();
39 private final DirectoryParameter workingDirectoryParameter = parser.add(new DirectoryParameter("Working directory."))
40 .addAliases("-w", "--working-directory").mustExist();
42 private final BitrateParameter videoBitrateParameter = parser.add(new BitrateParameter("Video bitrate")).addAliases("-v",
45 private final BitrateParameter audioBitrateParameter = parser.add(new BitrateParameter("Audio bitrate")).addAliases("-a",
49 * @return {@link EncodingOptions} if commandline arguments were
50 * successfully parsed, or <code>null</code> if parsing error
53 public EncodingOptions parseCommandlineArguments(final String[] args) {
55 final EncodingOptions options = new EncodingOptions();
59 options.setRecursive(recursiveParameter.isSpecified());
61 options.setDeinterlace(deinterlaceParameter.isSpecified());
63 options.setTestOnly(testParameter.isSpecified());
65 if (outputFormatParameter.isSpecified())
66 options.getOutputFormats().addAll(outputFormatParameter.getValue());
68 if (targetFramerate.isSpecified())
69 options.setTargetFps(targetFramerate.getValue());
71 if (workingDirectoryParameter.isSpecified())
72 options.setWorkingDirectory(workingDirectoryParameter.getValue());
74 if (inputPatternParameter.isSpecified())
75 options.getInputPatterns().addAll(inputPatternParameter.getValue());
77 options.setForPortablePlayer(forPortableParameter.isSpecified());
79 if (videoBitrateParameter.isSpecified())
80 options.setVideoBitrate(videoBitrateParameter.getValue());
82 if (audioBitrateParameter.isSpecified())
83 options.setAudioBitrate(audioBitrateParameter.getValue());