+ private String constructCodecParamsString(final EncodingOptions options,
+ final int videoBitrate, final int audioBitrate,
+ final String videoCodec, final String audioCodec) {
+
+ final StringBuilder codecParams = new StringBuilder();
+
+ if (audioCodec == null)
+ codecParams.append("-an ");
+ else
+ codecParams.append("-acodec " + audioCodec + " ");
+
+ codecParams.append("-vcodec " + videoCodec + " ");
+
+ if (videoBitrate != -1)
+ codecParams.append("-b " + videoBitrate + "k ");
+
+ if (audioBitrate != -1)
+ codecParams.append("-b:a " + audioBitrate + "k ");
+
+ if (options.isDeinterlace())
+ codecParams.append("-filter:v yadif ");
+
+ if (options.getTargetFps() != null)
+ codecParams.append("-r " + options.getTargetFps() + " ");
+
+ return codecParams.toString();
+ }
+
+ private int getAudioBitrateValue(final Bitrate bitRate) {
+ switch (bitRate) {
+ case LOW:
+ return 128;
+
+ case MEDIUM:
+ return 160;
+
+ case HIGH:
+ return 320;
+
+ case COPY:
+ return -1;
+
+ case NONE:
+ return -1;
+
+ default:
+ throw new RuntimeException("Audio bitrate: " + bitRate
+ + " is not supported.");
+ }
+ }
+
+ @Override
+ public String getCommand(final File inputFile, final File targetFile,
+ final EncodingOptions options, final String targetFormat) {
+
+ int videoBitrate = getVideoBitrateValue(options.getVideoBitrate());
+ int audioBitrate = getAudioBitrateValue(options.getAudioBitrate());
+
+ // convert
+ final StringBuilder codecParams = new StringBuilder();
+
+ String videoCodec = "libx264";
+ String audioCodec = "libmp3lame";
+
+ if (targetFormat.equals("webm")) {
+ videoCodec = "vp8";
+ audioCodec = "opus";
+ codecParams.append("-s 800x450 ");
+ }
+
+ if (options.getVideoBitrate() == Bitrate.COPY)
+ videoCodec = "copy";
+
+ if (options.getAudioBitrate() == Bitrate.COPY)
+ audioCodec = "copy";
+
+ if (options.getAudioBitrate() == Bitrate.NONE)
+ audioCodec = null;
+
+ if (options.isForPortablePlayer()) {
+ videoBitrate = 1000;
+ audioBitrate = 128;
+ videoCodec = "libxvid";