From 565d9c726de9b50709027f9455d39499a17f4b25 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 24 Dec 2013 21:09:19 +0200 Subject: [PATCH] Refactored to remove code duplication. Now single converter supports multiple source and target extensions. --- .../eu/svjatoslav/meviz/encoder/Encoder.java | 6 +- .../meviz/encoder/EncodingTask.java | 6 +- .../meviz/encoder/FormatsRegistry.java | 53 +++++------ .../encoder/converters/AbstractConverter.java | 49 +++++++++++ .../{Wav2mp3.java => AvconvAudio.java} | 11 +-- .../{Mkv2Mp4.java => AvconvVideo.java} | 16 ++-- .../converters/{Tif2Png.java => Convert.java} | 11 +-- .../meviz/encoder/converters/Converter.java | 29 ------- .../converters/{Tiff2Png.java => Ffmpeg.java} | 17 ++-- .../{Avi2Ogv.java => Ffmpeg2theora.java} | 15 ++-- .../converters/{Wav2flac.java => Flac.java} | 11 +-- .../meviz/encoder/converters/Jpeg2Png.java | 39 --------- .../meviz/encoder/converters/Mp42Ogv.java | 39 --------- .../meviz/encoder/converters/Mts2Mkv.java | 40 --------- .../meviz/encoder/converters/Mts2Mp4.java | 87 ------------------- .../meviz/encoder/converters/Ogg2Mp3.java | 38 -------- .../meviz/encoder/converters/Ogg2Wav.java | 37 ++++---- .../meviz/encoder/converters/Png2Tiff.java | 41 --------- .../eu/svjatoslav/meviz/grabmemcard/Main.java | 12 ++- 19 files changed, 143 insertions(+), 414 deletions(-) create mode 100755 src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java rename src/main/java/eu/svjatoslav/meviz/encoder/converters/{Wav2mp3.java => AvconvAudio.java} (78%) rename src/main/java/eu/svjatoslav/meviz/encoder/converters/{Mkv2Mp4.java => AvconvVideo.java} (84%) rename src/main/java/eu/svjatoslav/meviz/encoder/converters/{Tif2Png.java => Convert.java} (75%) delete mode 100755 src/main/java/eu/svjatoslav/meviz/encoder/converters/Converter.java rename src/main/java/eu/svjatoslav/meviz/encoder/converters/{Tiff2Png.java => Ffmpeg.java} (68%) rename src/main/java/eu/svjatoslav/meviz/encoder/converters/{Avi2Ogv.java => Ffmpeg2theora.java} (77%) rename src/main/java/eu/svjatoslav/meviz/encoder/converters/{Wav2flac.java => Flac.java} (78%) delete mode 100755 src/main/java/eu/svjatoslav/meviz/encoder/converters/Jpeg2Png.java delete mode 100755 src/main/java/eu/svjatoslav/meviz/encoder/converters/Mp42Ogv.java delete mode 100644 src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mkv.java delete mode 100755 src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java delete mode 100755 src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Mp3.java delete mode 100644 src/main/java/eu/svjatoslav/meviz/encoder/converters/Png2Tiff.java diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java b/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java index 879c6da..e60140b 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java @@ -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 formats = encoderRegistry + final List 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); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java index 54811c2..535f8f7 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java @@ -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; diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java index a78ff95..0d8bc8e 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java @@ -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 encoders = new ArrayList(); + public ArrayList encoders = new ArrayList(); 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 getEncoders(final String sourceFormat, + public List getEncoders(final String sourceFormat, final String targetFormat) { final String sourceFormatLowerCase = sourceFormat.toLowerCase(); final String targetFormatLowerCase = targetFormat.toLowerCase(); - final ArrayList encoders = new ArrayList(); + final ArrayList encoders = new ArrayList(); - 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 index 0000000..1e5d565 --- /dev/null +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java @@ -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 getSourceFileExtensions(); + + public abstract List 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 toList(final String... strings) { + final ArrayList result = new ArrayList(); + + for (final String string : strings) + result.add(string); + + return result; + } +} diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2mp3.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java similarity index 78% rename from src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2mp3.java rename to src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java index ec67f0f..a87777f 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2mp3.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java @@ -10,10 +10,11 @@ package eu.svjatoslav.meviz.encoder.converters; import java.io.File; +import java.util.List; import eu.svjatoslav.meviz.encoder.EncodingOptions; -public class Wav2mp3 implements Converter { +public class AvconvAudio extends AbstractConverter { @Override public String getCommand(final File inputFile, final File targetFile, @@ -26,13 +27,13 @@ public class Wav2mp3 implements Converter { } @Override - public String getSourceFileExtension() { - return "wav"; + public List getSourceFileExtensions() { + return toList("ogg", "wav"); } @Override - public String getTargetFileExtension() { - return "mp3"; + public List getTargetFileExtensions() { + return toList("mp3"); } @Override diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java similarity index 84% rename from src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java rename to src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java index dba7a1e..c63837a 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java @@ -10,10 +10,11 @@ package eu.svjatoslav.meviz.encoder.converters; import java.io.File; +import java.util.List; import eu.svjatoslav.meviz.encoder.EncodingOptions; -public class Mkv2Mp4 implements Converter { +public class AvconvVideo extends AbstractConverter { @Override public String getCommand(final File inputFile, final File targetFile, @@ -34,7 +35,7 @@ public class Mkv2Mp4 implements Converter { break; case HIGH: - videoBitrate = 15000; + videoBitrate = 40000; audioBitrate = 500; break; @@ -51,9 +52,8 @@ public class Mkv2Mp4 implements Converter { codecParams.append(" -b " + videoBitrate + "k"); codecParams.append(" -b:a " + audioBitrate + "k"); - if (options.deinterlace) { + if (options.deinterlace) codecParams.append(" -filter:v yadif"); - } return "avconv -i \"" + inputFile.getAbsolutePath() + "\" " + codecParams.toString() + " \"" + targetFile.getAbsolutePath() @@ -61,13 +61,13 @@ public class Mkv2Mp4 implements Converter { } @Override - public String getSourceFileExtension() { - return "mkv"; + public List getSourceFileExtensions() { + return toList("mkv", "mts"); } @Override - public String getTargetFileExtension() { - return "mp4"; + public List getTargetFileExtensions() { + return toList("mp4"); } @Override diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Tif2Png.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java similarity index 75% rename from src/main/java/eu/svjatoslav/meviz/encoder/converters/Tif2Png.java rename to src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java index 55df413..03639b4 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Tif2Png.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java @@ -10,10 +10,11 @@ package eu.svjatoslav.meviz.encoder.converters; import java.io.File; +import java.util.List; import eu.svjatoslav.meviz.encoder.EncodingOptions; -public class Tif2Png implements Converter { +public class Convert extends AbstractConverter { @Override public String getCommand(final File inputFile, final File targetFile, @@ -23,13 +24,13 @@ public class Tif2Png implements Converter { } @Override - public String getSourceFileExtension() { - return "tif"; + public List getSourceFileExtensions() { + return toList("tif", "tiff", "jpg", "jpeg"); } @Override - public String getTargetFileExtension() { - return "png"; + public List getTargetFileExtensions() { + return toList("png", "tiff"); } @Override 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 index d39cf79..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Converter.java +++ /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/Tiff2Png.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg.java similarity index 68% rename from src/main/java/eu/svjatoslav/meviz/encoder/converters/Tiff2Png.java rename to src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg.java index f717ff6..d9efe3b 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Tiff2Png.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg.java @@ -10,31 +10,34 @@ package eu.svjatoslav.meviz.encoder.converters; import java.io.File; +import java.util.List; import eu.svjatoslav.meviz.encoder.EncodingOptions; -public class Tiff2Png implements Converter { +public class Ffmpeg extends AbstractConverter { @Override public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) { - return "convert \"" + inputFile.getAbsolutePath() + "\" \"" + + return "ffmpeg -i \"" + inputFile.getAbsolutePath() + + "\" -vcodec copy -acodec copy \"" + targetFile.getAbsolutePath() + "\""; } @Override - public String getSourceFileExtension() { - return "tiff"; + public List getSourceFileExtensions() { + return toList("mts"); } @Override - public String getTargetFileExtension() { - return "png"; + public List getTargetFileExtensions() { + return toList("mkv"); } @Override public boolean isTerminalMandatory() { - return false; + return true; } } diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Avi2Ogv.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java similarity index 77% rename from src/main/java/eu/svjatoslav/meviz/encoder/converters/Avi2Ogv.java rename to src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java index acb3624..4df8c32 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Avi2Ogv.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java @@ -10,34 +10,33 @@ package eu.svjatoslav.meviz.encoder.converters; import java.io.File; +import java.util.List; import eu.svjatoslav.meviz.encoder.EncodingOptions; -public class Avi2Ogv implements Converter { +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 String getSourceFileExtension() { - return "avi"; + public List getSourceFileExtensions() { + return toList("avi", "mp4"); } @Override - public String getTargetFileExtension() { - return "ogv"; + public List getTargetFileExtensions() { + return toList("ogv"); } @Override public boolean isTerminalMandatory() { - - return false; + return true; } } diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2flac.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java similarity index 78% rename from src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2flac.java rename to src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java index 9a09d25..f7c6785 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Wav2flac.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java @@ -10,10 +10,11 @@ package eu.svjatoslav.meviz.encoder.converters; import java.io.File; +import java.util.List; import eu.svjatoslav.meviz.encoder.EncodingOptions; -public class Wav2flac implements Converter { +public class Flac extends AbstractConverter { @Override public String getCommand(final File inputFile, final File targetFile, @@ -24,13 +25,13 @@ public class Wav2flac implements Converter { } @Override - public String getSourceFileExtension() { - return "wav"; + public List getSourceFileExtensions() { + return toList("wav"); } @Override - public String getTargetFileExtension() { - return "flac"; + public List getTargetFileExtensions() { + return toList("flac"); } @Override 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 index cb66bf5..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Jpeg2Png.java +++ /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/Mp42Ogv.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mp42Ogv.java deleted file mode 100755 index 59f4922..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mp42Ogv.java +++ /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 index 1fdab94..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mkv.java +++ /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 index 9af415f..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java +++ /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 index 1d5401d..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Mp3.java +++ /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; - } - -} diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Wav.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Wav.java index 49b989b..618f616 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Wav.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Wav.java @@ -10,31 +10,34 @@ 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 getSourceFileExtensions() { + return toList("ogg"); + } - @Override - public String getTargetFileExtension() { - return "wav"; - } + @Override + public List 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 index ccf7e57..0000000 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Png2Tiff.java +++ /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/grabmemcard/Main.java b/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java index 9e779c8..101cc3f 100755 --- a/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java +++ b/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java @@ -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"); -- 2.20.1