2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012 -- 2018, 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 class CommandlineHandler {
20 final Parser parser = new Parser();
22 private final StringParameters outputFormatParameter = parser.add(new StringParameters("Encoding output format."))
23 .addAliases("-o", "--output-format").setMandatory();
25 private final IntegerParameter targetFramerate = parser
26 .add(new IntegerParameter("Target framerate.").addAliases("-f", "--target-framerate"));
28 private final NullParameter deinterlaceParameter = parser.add(new NullParameter("Deinterlace video.")).addAliases("-d",
31 private final NullParameter testParameter = parser.add(new NullParameter("Simulate file encoding.")).addAliases("-t", "--test");
33 private final NullParameter recursiveParameter = parser.add(new NullParameter("Enable recursive mode.")).addAliases("-r",
36 private final NullParameter forPortableParameter = parser.add(new NullParameter("Encode for portable player.")).addAliases("-p",
39 private final StringParameters inputPatternParameter = parser.add(new StringParameters("File input pattern."))
40 .addAliases("-i", "--input-pattern").setMandatory();
42 private final DirectoryParameter workingDirectoryParameter = parser.add(new DirectoryParameter("Working directory."))
43 .addAliases("-w", "--working-directory").mustExist();
45 private final BitrateParameter videoBitrateParameter = parser.add(new BitrateParameter("Video bitrate")).addAliases("-v",
48 private final 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.isSpecified());
64 options.setDeinterlace(deinterlaceParameter.isSpecified());
66 options.setTestOnly(testParameter.isSpecified());
68 if (outputFormatParameter.isSpecified())
69 options.getOutputFormats().addAll(outputFormatParameter.getValue());
71 if (targetFramerate.isSpecified())
72 options.setTargetFps(targetFramerate.getValue());
74 if (workingDirectoryParameter.isSpecified())
75 options.setWorkingDirectory(workingDirectoryParameter.getValue());
77 if (inputPatternParameter.isSpecified())
78 options.getInputPatterns().addAll(inputPatternParameter.getValue());
80 options.setForPortablePlayer(forPortableParameter.isSpecified());
82 if (videoBitrateParameter.isSpecified())
83 options.setVideoBitrate(videoBitrateParameter.getValue());
85 if (audioBitrateParameter.isSpecified())
86 options.setAudioBitrate(audioBitrateParameter.getValue());