Refactored to remove code duplication.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 24 Dec 2013 19:09:19 +0000 (21:09 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 24 Dec 2013 19:09:19 +0000 (21:09 +0200)
Now single converter supports multiple source and target extensions.

25 files changed:
src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java
src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java
src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Avi2Ogv.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Converter.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java [new file with mode: 0644]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Jpeg2Png.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Mp42Ogv.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mkv.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Mp3.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Wav.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Png2Tiff.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Tif2Png.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Tiff2Png.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2flac.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2mp3.java [deleted file]
src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java

index 879c6da..e60140b 100755 (executable)
@@ -15,7 +15,7 @@ import java.util.List;
 import eu.svjatoslav.commons.file.FilePathParser;
 import eu.svjatoslav.commons.string.WildCardMatcher;
 import eu.svjatoslav.meviz.Module;
-import eu.svjatoslav.meviz.encoder.converters.Converter;
+import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
 
 public class Encoder implements Module {
 
@@ -69,7 +69,7 @@ public class Encoder implements Module {
 
                                        if (!targetFile.exists()) {
 
-                                               final List<eu.svjatoslav.meviz.encoder.converters.Converter> formats = encoderRegistry
+                                               final List<eu.svjatoslav.meviz.encoder.converters.AbstractConverter> formats = encoderRegistry
                                                                .getEncoders(sourceFileExtension, targetFormat);
 
                                                if (formats.size() == 0)
@@ -87,7 +87,7 @@ public class Encoder implements Module {
                                                                                        + targetFormat
                                                                                        + " format.");
                                                else {
-                                                       final Converter chosenFormat = formats.get(0);
+                                                       final AbstractConverter chosenFormat = formats.get(0);
                                                        final EncodingTask encodingTask = new EncodingTask(
                                                                        sourceFile, targetFile, chosenFormat);
 
index 54811c2..535f8f7 100755 (executable)
@@ -11,7 +11,7 @@ package eu.svjatoslav.meviz.encoder;
 
 import java.io.File;
 
-import eu.svjatoslav.meviz.encoder.converters.Converter;
+import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
 
 public class EncodingTask {
 
@@ -25,12 +25,12 @@ public class EncodingTask {
         */
        private final File target;
 
-       private final Converter converter;
+       private final AbstractConverter converter;
 
        private boolean useTerminal;
 
        public EncodingTask(final File source, final File destination,
-                       final eu.svjatoslav.meviz.encoder.converters.Converter converter) {
+                       final eu.svjatoslav.meviz.encoder.converters.AbstractConverter converter) {
 
                this.source = source;
                target = destination;
index a78ff95..0d8bc8e 100755 (executable)
@@ -12,58 +12,45 @@ package eu.svjatoslav.meviz.encoder;
 import java.util.ArrayList;
 import java.util.List;
 
-import eu.svjatoslav.meviz.encoder.converters.Avi2Ogv;
-import eu.svjatoslav.meviz.encoder.converters.Converter;
-import eu.svjatoslav.meviz.encoder.converters.Jpeg2Png;
-import eu.svjatoslav.meviz.encoder.converters.Mkv2Mp4;
-import eu.svjatoslav.meviz.encoder.converters.Mp42Ogv;
-import eu.svjatoslav.meviz.encoder.converters.Mts2Mkv;
-import eu.svjatoslav.meviz.encoder.converters.Mts2Mp4;
-import eu.svjatoslav.meviz.encoder.converters.Ogg2Mp3;
+import eu.svjatoslav.meviz.encoder.converters.Ffmpeg2theora;
+import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
+import eu.svjatoslav.meviz.encoder.converters.AvconvVideo;
+import eu.svjatoslav.meviz.encoder.converters.Ffmpeg;
+import eu.svjatoslav.meviz.encoder.converters.AvconvAudio;
 import eu.svjatoslav.meviz.encoder.converters.Ogg2Wav;
-import eu.svjatoslav.meviz.encoder.converters.Png2Tiff;
-import eu.svjatoslav.meviz.encoder.converters.Tif2Png;
-import eu.svjatoslav.meviz.encoder.converters.Tiff2Png;
-import eu.svjatoslav.meviz.encoder.converters.Wav2flac;
-import eu.svjatoslav.meviz.encoder.converters.Wav2mp3;
+import eu.svjatoslav.meviz.encoder.converters.Convert;
+import eu.svjatoslav.meviz.encoder.converters.Flac;
 
 public class FormatsRegistry {
 
-       public ArrayList<Converter> encoders = new ArrayList<Converter>();
+       public ArrayList<AbstractConverter> encoders = new ArrayList<AbstractConverter>();
 
        public FormatsRegistry() {
                // video conversion
-               registerEncoder(new Avi2Ogv());
-               registerEncoder(new Mp42Ogv());
-               registerEncoder(new Mts2Mp4());
-               registerEncoder(new Mts2Mkv());
-               registerEncoder(new Mkv2Mp4());
+               registerEncoder(new Ffmpeg2theora());
+               registerEncoder(new Ffmpeg());
+               registerEncoder(new AvconvVideo());
 
                // image conversion
-               registerEncoder(new Jpeg2Png());
-               registerEncoder(new Png2Tiff());
-               registerEncoder(new Tiff2Png());
-               registerEncoder(new Tif2Png());
+               registerEncoder(new Convert());
 
                // audio conversion
                registerEncoder(new Ogg2Wav());
-               registerEncoder(new Wav2mp3());
-               registerEncoder(new Wav2flac());
-               registerEncoder(new Ogg2Mp3());
+               registerEncoder(new Flac());
+               registerEncoder(new AvconvAudio());
        }
 
-       public List<Converter> getEncoders(final String sourceFormat,
+       public List<AbstractConverter> getEncoders(final String sourceFormat,
                        final String targetFormat) {
 
                final String sourceFormatLowerCase = sourceFormat.toLowerCase();
                final String targetFormatLowerCase = targetFormat.toLowerCase();
 
-               final ArrayList<Converter> encoders = new ArrayList<Converter>();
+               final ArrayList<AbstractConverter> encoders = new ArrayList<AbstractConverter>();
 
-               for (final Converter encoder : this.encoders)
-                       if (encoder.getSourceFileExtension().equals(sourceFormatLowerCase))
-                               if (encoder.getTargetFileExtension().equals(
-                                               targetFormatLowerCase)) {
+               for (final AbstractConverter encoder : this.encoders)
+                       if (encoder.supportsSource(sourceFormatLowerCase))
+                               if (encoder.supportsTarget(targetFormatLowerCase)) {
                                        encoders.add(encoder);
                                        return encoders;
                                }
@@ -71,7 +58,7 @@ public class FormatsRegistry {
                return encoders;
        }
 
-       public void registerEncoder(final Converter encoder) {
+       public void registerEncoder(final AbstractConverter encoder) {
                encoders.add(encoder);
        }
 
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java
new file mode 100755 (executable)
index 0000000..1e5d565
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Meviz - Various tools collection to work with multimedia.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.meviz.encoder.converters;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import eu.svjatoslav.meviz.encoder.EncodingOptions;
+
+public abstract class AbstractConverter {
+
+       public abstract String getCommand(File inputFile, File targetFile,
+                       EncodingOptions options);
+
+       public abstract List<String> getSourceFileExtensions();
+
+       public abstract List<String> getTargetFileExtensions();
+
+       /**
+        * For some reasons some encoders require terminal to run. Until this is
+        * resolved, encoder can request for terminal using this method.
+        */
+       public abstract boolean isTerminalMandatory();
+
+       public boolean supportsSource(final String format) {
+               return getSourceFileExtensions().contains(format);
+       }
+
+       public boolean supportsTarget(final String format) {
+               return getTargetFileExtensions().contains(format);
+       }
+
+       public List<String> toList(final String... strings) {
+               final ArrayList<String> result = new ArrayList<String>();
+
+               for (final String string : strings)
+                       result.add(string);
+
+               return result;
+       }
+}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java
new file mode 100755 (executable)
index 0000000..a87777f
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Meviz - Various tools collection to work with multimedia.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.meviz.encoder.converters;
+
+import java.io.File;
+import java.util.List;
+
+import eu.svjatoslav.meviz.encoder.EncodingOptions;
+
+public class AvconvAudio extends AbstractConverter {
+
+       @Override
+       public String getCommand(final File inputFile, final File targetFile,
+                       final EncodingOptions options) {
+
+               final String codecParams = "-b:a 192k";
+
+               return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
+                               + codecParams + " \"" + targetFile.getAbsolutePath() + "\"";
+       }
+
+       @Override
+       public List<String> getSourceFileExtensions() {
+               return toList("ogg", "wav");
+       }
+
+       @Override
+       public List<String> getTargetFileExtensions() {
+               return toList("mp3");
+       }
+
+       @Override
+       public boolean isTerminalMandatory() {
+               return false;
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java
new file mode 100644 (file)
index 0000000..c63837a
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Meviz - Various tools collection to work with multimedia.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.meviz.encoder.converters;
+
+import java.io.File;
+import java.util.List;
+
+import eu.svjatoslav.meviz.encoder.EncodingOptions;
+
+public class AvconvVideo extends AbstractConverter {
+
+       @Override
+       public String getCommand(final File inputFile, final File targetFile,
+                       final EncodingOptions options) {
+
+               int videoBitrate;
+               int audioBitrate;
+
+               switch (options.videoBitrate) {
+               case LOW:
+                       videoBitrate = 1000;
+                       audioBitrate = 128;
+                       break;
+
+               case MEDIUM:
+                       videoBitrate = 3500;
+                       audioBitrate = 128;
+                       break;
+
+               case HIGH:
+                       videoBitrate = 40000;
+                       audioBitrate = 500;
+                       break;
+
+               default:
+                       throw new RuntimeException("Video bitrate: " + options.videoBitrate
+                                       + " is not supported.");
+               }
+
+               // convert
+               final StringBuffer codecParams = new StringBuffer();
+
+               codecParams.append("-acodec libmp3lame -vcodec libx264");
+
+               codecParams.append(" -b " + videoBitrate + "k");
+               codecParams.append(" -b:a " + audioBitrate + "k");
+
+               if (options.deinterlace)
+                       codecParams.append(" -filter:v yadif");
+
+               return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
+                               + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
+                               + "\"";
+       }
+
+       @Override
+       public List<String> getSourceFileExtensions() {
+               return toList("mkv", "mts");
+       }
+
+       @Override
+       public List<String> getTargetFileExtensions() {
+               return toList("mp4");
+       }
+
+       @Override
+       public boolean isTerminalMandatory() {
+               return true;
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Avi2Ogv.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Avi2Ogv.java
deleted file mode 100755 (executable)
index acb3624..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Avi2Ogv implements Converter {
-
-       @Override
-       public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
-
-               return "ffmpeg2theora \"" + inputFile.getAbsolutePath() + "\" -o \""
-                               + targetFile.getAbsolutePath()
-                               + "\" --optimize --videobitrate 3000 --width 800";
-       }
-
-       @Override
-       public String getSourceFileExtension() {
-               return "avi";
-       }
-
-       @Override
-       public String getTargetFileExtension() {
-               return "ogv";
-       }
-
-       @Override
-       public boolean isTerminalMandatory() {
-
-               return false;
-       }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java
new file mode 100644 (file)
index 0000000..03639b4
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Meviz - Various tools collection to work with multimedia.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.meviz.encoder.converters;
+
+import java.io.File;
+import java.util.List;
+
+import eu.svjatoslav.meviz.encoder.EncodingOptions;
+
+public class Convert extends AbstractConverter {
+
+       @Override
+       public String getCommand(final File inputFile, final File targetFile,
+                       final EncodingOptions options) {
+               return "convert \"" + inputFile.getAbsolutePath() + "\" \""
+                               + targetFile.getAbsolutePath() + "\"";
+       }
+
+       @Override
+       public List<String> getSourceFileExtensions() {
+               return toList("tif", "tiff", "jpg", "jpeg");
+       }
+
+       @Override
+       public List<String> getTargetFileExtensions() {
+               return toList("png", "tiff");
+       }
+
+       @Override
+       public boolean isTerminalMandatory() {
+               return false;
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Converter.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Converter.java
deleted file mode 100755 (executable)
index d39cf79..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public interface Converter {
-
-    public String getCommand(File inputFile, File targetFile, EncodingOptions options);
-
-    public String getSourceFileExtension();
-
-    public String getTargetFileExtension();
-
-    /**
-     * For some reasons some encoders require terminal to run. Until this is
-     * resolved, encoder can request for terminal using this method.
-     */
-    public boolean isTerminalMandatory();
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg.java
new file mode 100644 (file)
index 0000000..d9efe3b
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Meviz - Various tools collection to work with multimedia.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.meviz.encoder.converters;
+
+import java.io.File;
+import java.util.List;
+
+import eu.svjatoslav.meviz.encoder.EncodingOptions;
+
+public class Ffmpeg extends AbstractConverter {
+
+       @Override
+       public String getCommand(final File inputFile, final File targetFile,
+                       final EncodingOptions options) {
+
+               return "ffmpeg -i \"" + inputFile.getAbsolutePath()
+                               + "\" -vcodec copy -acodec copy \""
+                               + targetFile.getAbsolutePath() + "\"";
+       }
+
+       @Override
+       public List<String> getSourceFileExtensions() {
+               return toList("mts");
+       }
+
+       @Override
+       public List<String> getTargetFileExtensions() {
+               return toList("mkv");
+       }
+
+       @Override
+       public boolean isTerminalMandatory() {
+               return true;
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java
new file mode 100755 (executable)
index 0000000..4df8c32
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Meviz - Various tools collection to work with multimedia.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.meviz.encoder.converters;
+
+import java.io.File;
+import java.util.List;
+
+import eu.svjatoslav.meviz.encoder.EncodingOptions;
+
+public class Ffmpeg2theora extends AbstractConverter {
+
+       @Override
+       public String getCommand(final File inputFile, final File targetFile,
+                       final EncodingOptions options) {
+               return "ffmpeg2theora \"" + inputFile.getAbsolutePath() + "\" -o \""
+                               + targetFile.getAbsolutePath()
+                               + "\" --optimize --videobitrate 3000 --width 800";
+       }
+
+       @Override
+       public List<String> getSourceFileExtensions() {
+               return toList("avi", "mp4");
+       }
+
+       @Override
+       public List<String> getTargetFileExtensions() {
+               return toList("ogv");
+       }
+
+       @Override
+       public boolean isTerminalMandatory() {
+               return true;
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java
new file mode 100644 (file)
index 0000000..f7c6785
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Meviz - Various tools collection to work with multimedia.
+ * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public License
+ * as published by the Free Software Foundation.
+ */
+
+package eu.svjatoslav.meviz.encoder.converters;
+
+import java.io.File;
+import java.util.List;
+
+import eu.svjatoslav.meviz.encoder.EncodingOptions;
+
+public class Flac extends AbstractConverter {
+
+       @Override
+       public String getCommand(final File inputFile, final File targetFile,
+                       final EncodingOptions options) {
+
+               return "flac -8 \"" + inputFile.getAbsolutePath() + "\" -o \""
+                               + targetFile.getAbsolutePath() + "\"";
+       }
+
+       @Override
+       public List<String> getSourceFileExtensions() {
+               return toList("wav");
+       }
+
+       @Override
+       public List<String> getTargetFileExtensions() {
+               return toList("flac");
+       }
+
+       @Override
+       public boolean isTerminalMandatory() {
+               return false;
+       }
+
+}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Jpeg2Png.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Jpeg2Png.java
deleted file mode 100755 (executable)
index cb66bf5..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Jpeg2Png implements Converter {
-
-    @Override
-    public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) {
-        return "convert \"" + inputFile.getAbsolutePath() + "\" \""
-        + targetFile.getAbsolutePath() + "\"";
-    }
-
-    @Override
-    public String getSourceFileExtension() {
-        return "jpeg";
-    }
-
-    @Override
-    public String getTargetFileExtension() {
-        return "png";
-    }
-
-    @Override
-    public boolean isTerminalMandatory() {
-        return false;
-    }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java
deleted file mode 100644 (file)
index dba7a1e..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Mkv2Mp4 implements Converter {
-
-       @Override
-       public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
-
-               int videoBitrate;
-               int audioBitrate;
-
-               switch (options.videoBitrate) {
-               case LOW:
-                       videoBitrate = 1000;
-                       audioBitrate = 128;
-                       break;
-
-               case MEDIUM:
-                       videoBitrate = 3500;
-                       audioBitrate = 128;
-                       break;
-
-               case HIGH:
-                       videoBitrate = 15000;
-                       audioBitrate = 500;
-                       break;
-
-               default:
-                       throw new RuntimeException("Video bitrate: " + options.videoBitrate
-                                       + " is not supported.");
-               }
-
-               // convert
-               final StringBuffer codecParams = new StringBuffer();
-
-               codecParams.append("-acodec libmp3lame -vcodec libx264");
-
-               codecParams.append(" -b " + videoBitrate + "k");
-               codecParams.append(" -b:a " + audioBitrate + "k");
-
-               if (options.deinterlace) {
-                       codecParams.append(" -filter:v yadif");
-               }
-
-               return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
-                               + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
-                               + "\"";
-       }
-
-       @Override
-       public String getSourceFileExtension() {
-               return "mkv";
-       }
-
-       @Override
-       public String getTargetFileExtension() {
-               return "mp4";
-       }
-
-       @Override
-       public boolean isTerminalMandatory() {
-               return true;
-       }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mp42Ogv.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mp42Ogv.java
deleted file mode 100755 (executable)
index 59f4922..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Mp42Ogv implements Converter {
-
-    @Override
-    public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) {
-        return "ffmpeg2theora \"" + inputFile.getAbsolutePath() + "\" -o \"" + targetFile.getAbsolutePath()
-                + "\" --optimize --videobitrate 3000 --width 800";
-    }
-
-    @Override
-    public String getSourceFileExtension() {
-        return "mp4";
-    }
-
-    @Override
-    public String getTargetFileExtension() {
-        return "ogv";
-    }
-
-    @Override
-    public boolean isTerminalMandatory() {
-        return true;
-    }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mkv.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mkv.java
deleted file mode 100644 (file)
index 1fdab94..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Mts2Mkv implements Converter {
-
-    @Override
-    public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) {
-
-        return "ffmpeg -i \"" + inputFile.getAbsolutePath() + "\" -vcodec copy -acodec copy \""
-                + targetFile.getAbsolutePath() + "\"";
-    }
-
-    @Override
-    public String getSourceFileExtension() {
-        return "mts";
-    }
-
-    @Override
-    public String getTargetFileExtension() {
-        return "mkv";
-    }
-
-    @Override
-    public boolean isTerminalMandatory() {
-        return true;
-    }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java
deleted file mode 100755 (executable)
index 9af415f..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.BitrateParameter;
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Mts2Mp4 implements Converter {
-
-       @Override
-       public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
-
-               int videoBitrate = 0;
-               int audioBitrate = 0;
-
-               switch (options.videoBitrate) {
-               case LOW:
-                       videoBitrate = 1000;
-                       audioBitrate = 128;
-                       break;
-
-               case MEDIUM:
-                       videoBitrate = 3500;
-                       audioBitrate = 128;
-                       break;
-
-               case HIGH:
-                       videoBitrate = 15000;
-                       audioBitrate = 500;
-                       break;
-
-               case COPY:
-                       break;
-
-               default:
-                       throw new RuntimeException("Video bitrate: " + options.videoBitrate
-                                       + " is not supported.");
-               }
-
-               // convert
-               final StringBuffer codecParams = new StringBuffer();
-
-               if (options.videoBitrate == BitrateParameter.bitrate.COPY) {
-                       // pass through
-                       codecParams.append("-acodec copy -vcodec copy");
-
-               } else {
-                       codecParams.append("-acodec libmp3lame -vcodec libx264");
-                       codecParams.append(" -b " + videoBitrate + "k");
-                       codecParams.append(" -b:a " + audioBitrate + "k");
-               }
-
-               if (options.deinterlace) {
-                       codecParams.append(" -filter:v yadif");
-               }
-
-               return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
-                               + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
-                               + "\"";
-       }
-
-       @Override
-       public String getSourceFileExtension() {
-               return "mts";
-       }
-
-       @Override
-       public String getTargetFileExtension() {
-               return "mp4";
-       }
-
-       @Override
-       public boolean isTerminalMandatory() {
-               return true;
-       }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Mp3.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Mp3.java
deleted file mode 100755 (executable)
index 1d5401d..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Ogg2Mp3 implements Converter {
-
-    @Override
-    public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) {
-        return "avconv -i \"" + inputFile.getAbsolutePath() + "\" \"" + targetFile.getAbsolutePath() + "\"";
-    }
-
-    @Override
-    public String getSourceFileExtension() {
-        return "ogg";
-    }
-
-    @Override
-    public String getTargetFileExtension() {
-        return "mp3";
-    }
-
-    @Override
-    public boolean isTerminalMandatory() {
-        return false;
-    }
-
-}
index 49b989b..618f616 100755 (executable)
 package eu.svjatoslav.meviz.encoder.converters;
 
 import java.io.File;
+import java.util.List;
 
 import eu.svjatoslav.meviz.encoder.EncodingOptions;
 
-public class Ogg2Wav implements Converter {
+public class Ogg2Wav extends AbstractConverter {
 
-    @Override
-    public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) {
+       @Override
+       public String getCommand(final File inputFile, final File targetFile,
+                       final EncodingOptions options) {
 
-        return "oggdec \"" + inputFile.getAbsolutePath() + "\" -o \"" + targetFile.getAbsolutePath() + "\"";
+               return "oggdec \"" + inputFile.getAbsolutePath() + "\" -o \""
+                               + targetFile.getAbsolutePath() + "\"";
 
-    }
+       }
 
-    @Override
-    public String getSourceFileExtension() {
-        return "ogg";
-    }
+       @Override
+       public List<String> getSourceFileExtensions() {
+               return toList("ogg");
+       }
 
-    @Override
-    public String getTargetFileExtension() {
-        return "wav";
-    }
+       @Override
+       public List<String> getTargetFileExtensions() {
+               return toList("wav");
+       }
 
-    @Override
-    public boolean isTerminalMandatory() {
-        return true;
-    }
+       @Override
+       public boolean isTerminalMandatory() {
+               return true;
+       }
 
 }
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Png2Tiff.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Png2Tiff.java
deleted file mode 100644 (file)
index ccf7e57..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Png2Tiff implements Converter {
-
-
-    @Override
-    public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) {
-        return "convert \"" + inputFile.getAbsolutePath() + "\" \""
-        + targetFile.getAbsolutePath() + "\"";
-    }
-
-    @Override
-    public String getSourceFileExtension() {
-        return "tiff";
-    }
-
-    @Override
-    public String getTargetFileExtension() {
-        return "png";
-    }
-
-    @Override
-    public boolean isTerminalMandatory() {
-        return false;
-    }
-
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Tif2Png.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Tif2Png.java
deleted file mode 100644 (file)
index 55df413..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Tif2Png implements Converter {
-
-       @Override
-       public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
-               return "convert \"" + inputFile.getAbsolutePath() + "\" \""
-                               + targetFile.getAbsolutePath() + "\"";
-       }
-
-       @Override
-       public String getSourceFileExtension() {
-               return "tif";
-       }
-
-       @Override
-       public String getTargetFileExtension() {
-               return "png";
-       }
-
-       @Override
-       public boolean isTerminalMandatory() {
-               return false;
-       }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Tiff2Png.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Tiff2Png.java
deleted file mode 100644 (file)
index f717ff6..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Tiff2Png implements Converter {
-
-       @Override
-       public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
-               return "convert \"" + inputFile.getAbsolutePath() + "\" \""
-                               + targetFile.getAbsolutePath() + "\"";
-       }
-
-       @Override
-       public String getSourceFileExtension() {
-               return "tiff";
-       }
-
-       @Override
-       public String getTargetFileExtension() {
-               return "png";
-       }
-
-       @Override
-       public boolean isTerminalMandatory() {
-               return false;
-       }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2flac.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2flac.java
deleted file mode 100644 (file)
index 9a09d25..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Wav2flac implements Converter {
-
-       @Override
-       public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
-
-               return "flac -8 \"" + inputFile.getAbsolutePath() + "\" -o \""
-                               + targetFile.getAbsolutePath() + "\"";
-       }
-
-       @Override
-       public String getSourceFileExtension() {
-               return "wav";
-       }
-
-       @Override
-       public String getTargetFileExtension() {
-               return "flac";
-       }
-
-       @Override
-       public boolean isTerminalMandatory() {
-               return false;
-       }
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2mp3.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2mp3.java
deleted file mode 100755 (executable)
index ec67f0f..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.meviz.encoder.converters;
-
-import java.io.File;
-
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-
-public class Wav2mp3 implements Converter {
-
-       @Override
-       public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
-
-               final String codecParams = "-b:a 192k";
-
-               return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
-                               + codecParams + " \"" + targetFile.getAbsolutePath() + "\"";
-       }
-
-       @Override
-       public String getSourceFileExtension() {
-               return "wav";
-       }
-
-       @Override
-       public String getTargetFileExtension() {
-               return "mp3";
-       }
-
-       @Override
-       public boolean isTerminalMandatory() {
-               return false;
-       }
-
-}
index 9e779c8..101cc3f 100755 (executable)
@@ -21,8 +21,8 @@ import eu.svjatoslav.meviz.encoder.BitrateParameter;
 import eu.svjatoslav.meviz.encoder.EncodingOptions;
 import eu.svjatoslav.meviz.encoder.EncodingPlan;
 import eu.svjatoslav.meviz.encoder.EncodingTask;
-import eu.svjatoslav.meviz.encoder.converters.Converter;
-import eu.svjatoslav.meviz.encoder.converters.Mts2Mp4;
+import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
+import eu.svjatoslav.meviz.encoder.converters.Ffmpeg;
 
 public class Main implements Module {
 
@@ -36,18 +36,16 @@ public class Main implements Module {
                                + "/AVCHD/BDMV/STREAM/";
                final File videosDirectory = new File(videosPath);
 
-               if (!videosDirectory.exists()) {
+               if (!videosDirectory.exists())
                        return new File[0];
-               }
 
                return videosDirectory.listFiles();
        }
 
        public String getDoubleDigit(final int value) {
                String valueString = Integer.toString(value);
-               if (valueString.length() == 1) {
+               if (valueString.length() == 1)
                        valueString = "0" + valueString;
-               }
                return valueString;
        };
 
@@ -88,7 +86,7 @@ public class Main implements Module {
                final File targetDirectory = getTargetDirectory();
                targetDirectory.mkdirs();
 
-               final Converter converter = new Mts2Mp4();
+               final AbstractConverter converter = new Ffmpeg();
                final EncodingPlan encodingPlan = new EncodingPlan();
 
                final String userName = System.getProperty("user.name");