added webm support
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 28 Apr 2015 18:55:39 +0000 (21:55 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 28 Apr 2015 18:55:39 +0000 (21:55 +0300)
+ sorted members
+ formatted code

24 files changed:
src/main/java/eu/svjatoslav/meviz/Module.java
src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java
src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java
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/converters/AbstractConverter.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Midi2Wav.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Wav.java
src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/ImageFormatError.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/MevizSpecialFile.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java
src/main/java/eu/svjatoslav/meviz/renamer/RenamingOptions.java
src/main/java/eu/svjatoslav/meviz/replace/CommandlineHandler.java
src/main/java/eu/svjatoslav/meviz/replace/CommandlineOptions.java
src/main/java/eu/svjatoslav/meviz/texttruncate/CommandlineHandler.java

index 797aa1d..026ec6a 100755 (executable)
@@ -11,12 +11,12 @@ package eu.svjatoslav.meviz;
 
 public interface Module {
 
-    public String getDescription();
+       public String getDescription();
 
-    public String getModuleCommand();
+       public String getModuleCommand();
 
-    public void run(String args[]) throws Exception;
+       public void run(String args[]) throws Exception;
 
-    public void showCommandlineHelp();
+       public void showCommandlineHelp();
 
 }
index fdfc3c9..46750a3 100755 (executable)
@@ -26,7 +26,7 @@ public class CommandlineHandler {
 
        StringParameters inputPatternParameter = parser.add(
                        new StringParameters("File input pattern.")).addAliases("-i",
-                                       "--input-pattern");
+                       "--input-pattern");
 
        DirectoryParameter workingDirectoryParameter = parser
                        .add(new DirectoryParameter("Working directory."))
index ff4b8ec..1f38b17 100755 (executable)
@@ -28,7 +28,7 @@ public class CommandlineHandler {
 
        NullParameter testParameter = parser.add(
                        new NullParameter("Simulate file encoding.")).addAliases("-t",
-                                       "--test");
+                       "--test");
 
        NullParameter recursiveParameter = parser.add(
                        new NullParameter("Enable recursive mode.")).addAliases("-r",
@@ -36,7 +36,7 @@ public class CommandlineHandler {
 
        NullParameter forPortableParameter = parser.add(
                        new NullParameter("Encode for portable player.")).addAliases("-p",
-                                       "--portable");
+                       "--portable");
 
        StringParameters inputPatternParameter = parser
                        .add(new StringParameters("File input pattern."))
@@ -52,7 +52,7 @@ public class CommandlineHandler {
 
        BitrateParameter audioBitrateParameter = parser.add(
                        new BitrateParameter("Audio bitrate")).addAliases("-a",
-                                       "--audio-bitrate");
+                       "--audio-bitrate");
 
        /**
         * @return {@link EncodingOptions} if commandline arguments were
index e60140b..4b56b13 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -87,9 +87,11 @@ public class Encoder implements Module {
                                                                                        + targetFormat
                                                                                        + " format.");
                                                else {
-                                                       final AbstractConverter chosenFormat = formats.get(0);
+                                                       final AbstractConverter chosenFormat = formats
+                                                                       .get(0);
                                                        final EncodingTask encodingTask = new EncodingTask(
-                                                                       sourceFile, targetFile, chosenFormat);
+                                                                       sourceFile, targetFile, chosenFormat,
+                                                                       targetFormat);
 
                                                        if (chosenFormat.isTerminalMandatory())
                                                                encodingTask.setUseTerminal(true);
index 535f8f7..816fba7 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -29,13 +29,18 @@ public class EncodingTask {
 
        private boolean useTerminal;
 
-       public EncodingTask(final File source, final File destination,
-                       final eu.svjatoslav.meviz.encoder.converters.AbstractConverter converter) {
+       private String targetFormat;
+
+       public EncodingTask(
+                       final File source,
+                       final File destination,
+                       final eu.svjatoslav.meviz.encoder.converters.AbstractConverter converter,
+                       String targetFormat) {
 
                this.source = source;
                target = destination;
                this.converter = converter;
-
+               this.targetFormat = targetFormat;
        }
 
        /**
@@ -82,7 +87,8 @@ public class EncodingTask {
        }
 
        public String getCommand(final EncodingOptions encodingOptions) {
-               return converter.getCommand(source, target, encodingOptions);
+               return converter.getCommand(source, target, encodingOptions,
+                               targetFormat);
        }
 
        /**
index 1e5d565..6d61f91 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -18,7 +18,7 @@ import eu.svjatoslav.meviz.encoder.EncodingOptions;
 public abstract class AbstractConverter {
 
        public abstract String getCommand(File inputFile, File targetFile,
-                       EncodingOptions options);
+                       EncodingOptions options, String targetFormat);
 
        public abstract List<String> getSourceFileExtensions();
 
index a87777f..5dd258a 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -18,7 +18,7 @@ public class AvconvAudio extends AbstractConverter {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
+                       final EncodingOptions options, String targetFormat) {
 
                final String codecParams = "-b:a 192k";
 
index f0d80bf..ea08e5d 100644 (file)
@@ -18,10 +18,11 @@ import eu.svjatoslav.meviz.encoder.EncodingOptions;
 
 public class AvconvVideo extends AbstractConverter {
 
-       private void constructCodecParamsString(final EncodingOptions options,
+       private String constructCodecParamsString(final EncodingOptions options,
                        final int videoBitrate, final int audioBitrate,
-                       final StringBuffer codecParams, final String videoCodec,
-                       final String audioCodec) {
+                       final String videoCodec, final String audioCodec) {
+
+               StringBuffer codecParams = new StringBuffer();
 
                if (audioCodec == null)
                        codecParams.append("-an ");
@@ -38,6 +39,8 @@ public class AvconvVideo extends AbstractConverter {
 
                if (options.deinterlace)
                        codecParams.append("-filter:v yadif ");
+
+               return codecParams.toString();
        }
 
        private int getAudioBitrateValue(final BitrateParameter.bitrate bitRate) {
@@ -65,7 +68,7 @@ public class AvconvVideo extends AbstractConverter {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
+                       final EncodingOptions options, String targetFormat) {
 
                int videoBitrate = getVideoBitrateValue(options.getVideoBitrate());
                int audioBitrate = getAudioBitrateValue(options.getAudioBitrate());
@@ -76,6 +79,11 @@ public class AvconvVideo extends AbstractConverter {
                String videoCodec = "libx264";
                String audioCodec = "libmp3lame";
 
+               if (targetFormat.equals("webm")) {
+                       videoCodec = "vp9";
+                       audioCodec = "opus";
+               }
+
                if (options.getVideoBitrate() == bitrate.COPY)
                        videoCodec = "copy";
 
@@ -92,8 +100,8 @@ public class AvconvVideo extends AbstractConverter {
                        codecParams.append("-s 640x480 ");
                }
 
-               constructCodecParamsString(options, videoBitrate, audioBitrate,
-                               codecParams, videoCodec, audioCodec);
+               codecParams.append(constructCodecParamsString(options, videoBitrate,
+                               audioBitrate, videoCodec, audioCodec));
 
                return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
                                + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
@@ -102,12 +110,14 @@ public class AvconvVideo extends AbstractConverter {
 
        @Override
        public List<String> getSourceFileExtensions() {
-               return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v");
+               return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v",
+                               "webm");
        }
 
        @Override
        public List<String> getTargetFileExtensions() {
-               return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v");
+               return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v",
+                               "webm");
        }
 
        private int getVideoBitrateValue(final BitrateParameter.bitrate bitRate) {
index 418cd51..e7abf57 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -18,7 +18,7 @@ public class Convert extends AbstractConverter {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
+                       final EncodingOptions options, String targetFormat) {
                return "convert \"" + inputFile.getAbsolutePath() + "\" \""
                                + targetFile.getAbsolutePath() + "\"";
        }
index a9d86ee..b2afedb 100755 (executable)
@@ -18,7 +18,7 @@ public class Ffmpeg2theora extends AbstractConverter {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
+                       final EncodingOptions options, String targetFormat) {
                return "ffmpeg2theora \"" + inputFile.getAbsolutePath() + "\" -o \""
                                + targetFile.getAbsolutePath()
                                + "\" --optimize --videobitrate 3000 --width 800";
index f7c6785..bf239cc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -18,7 +18,7 @@ public class Flac extends AbstractConverter {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
+                       final EncodingOptions options, String targetFormat) {
 
                return "flac -8 \"" + inputFile.getAbsolutePath() + "\" -o \""
                                + targetFile.getAbsolutePath() + "\"";
index 972780f..d823761 100644 (file)
@@ -18,7 +18,7 @@ public class Midi2Wav extends AbstractConverter {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
+                       final EncodingOptions options, String targetFormat) {
 
                return "timidity \"" + inputFile.getAbsolutePath() + "\" -Ow -o \""
                                + targetFile.getAbsolutePath() + "\"";
index 618f616..f89927b 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -18,7 +18,7 @@ public class Ogg2Wav extends AbstractConverter {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options) {
+                       final EncodingOptions options, String targetFormat) {
 
                return "oggdec \"" + inputFile.getAbsolutePath() + "\" -o \""
                                + targetFile.getAbsolutePath() + "\"";
index d6d194c..dac58fd 100755 (executable)
@@ -108,7 +108,7 @@ public class Main implements Module {
                                final File targetFile = new File(targetFilePath.toString());
 
                                final EncodingTask encodingTask = new EncodingTask(sourceFile,
-                                               targetFile, converter);
+                                               targetFile, converter, "mp4");
                                encodingPlan.scheduleTask(encodingTask);
                        }
                }
index f7cb130..061163e 100755 (executable)
@@ -144,7 +144,7 @@ public class FilesystemIndexer extends AbstractIndexer {
                validMetadataFiles.add(thumbnailFileName);
                final File thumbnailFile = new File(
                                Utils.getThumbnailsDirectoryPath(directoryToIndex)
-                               + thumbnailFileName);
+                                               + thumbnailFileName);
 
                if (!thumbnailFile.exists()) {
 
@@ -156,7 +156,7 @@ public class FilesystemIndexer extends AbstractIndexer {
                                        desiredDimension.getAwtDimension());
                }
                return Constants.THUMBNAILS_DIRECTORY_NAME + "/"
-               + UrlParamEncoder.encode(thumbnailFileName);
+                               + UrlParamEncoder.encode(thumbnailFileName);
        }
 
        public void initializeLayouts() {
@@ -182,7 +182,7 @@ public class FilesystemIndexer extends AbstractIndexer {
 
                metadataFile = new File(
                                Utils.getThumbnailsDirectoryPath(directoryToIndex)
-                               + Constants.METADATA_FILE_NAME);
+                                               + Constants.METADATA_FILE_NAME);
 
                metadata = MetadadaHelper.initDirectoryMetadata(metadataFile);
        }
index 7d40bf4..783f802 100755 (executable)
@@ -11,9 +11,9 @@ package eu.svjatoslav.meviz.htmlindexer;
 
 public class ImageFormatError extends Exception {
 
-    private static final long serialVersionUID = 4037233564457071385L;
+       private static final long serialVersionUID = 4037233564457071385L;
 
-    public ImageFormatError(final String message) {
-        super(message);
-    }
+       public ImageFormatError(final String message) {
+               super(message);
+       }
 }
index 9da4656..6200e06 100755 (executable)
@@ -24,6 +24,10 @@ import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout;
 
 public class Utils {
 
+       private static File lastLoadedFile;
+
+       private static BufferedImage lastLoadedBufferedImage;
+
        /**
         * Load image into {@link BufferedImage} and return it. Caches last loaded
         * image to speed up subsequent loading attempts.
@@ -121,8 +125,4 @@ public class Utils {
                return isMevizFile;
        }
 
-       private static File lastLoadedFile;
-
-       private static BufferedImage lastLoadedBufferedImage;
-
 }
index ddacb56..fd70b10 100755 (executable)
@@ -29,6 +29,8 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
 
 public class MixedLayout implements Layout {
 
+       public static final String encoding = "UTF-8";
+
        Logger logger = Logger.getLogger(MixedLayout.class);
 
        StringBuffer dirHtml = new StringBuffer();
@@ -39,8 +41,6 @@ public class MixedLayout implements Layout {
 
        List<String> path;
 
-       public static final String encoding = "UTF-8";
-
        private AbstractIndexer indexer;
 
        private IndexingContext indexingContext;
@@ -82,7 +82,7 @@ public class MixedLayout implements Layout {
                                        "Error generating thumbnails for image file: "
                                                        + e.toString()
                                                        + ", thumbnail generation skipped, enlisting as ordinary file instead.",
-                                                       e);
+                                       e);
                        enlistFile(picture, parentDirectoryMetadata);
                }
        }
@@ -135,7 +135,7 @@ public class MixedLayout implements Layout {
        @Override
        public void enlistOgv(final AbstractFile abstractFile,
                        final DirectoryMetadata parentDirectoryMetadata)
-                                       throws UnsupportedEncodingException {
+                       throws UnsupportedEncodingException {
 
                final GeneralFile file = (GeneralFile) abstractFile;
 
@@ -143,22 +143,22 @@ public class MixedLayout implements Layout {
 
                // watchable video
                filesHtml
-               .append("<video preload=\"metadata\" controls=\"controls\" tabindex=\"0\">\n");
+                               .append("<video preload=\"metadata\" controls=\"controls\" tabindex=\"0\">\n");
                filesHtml
-               .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
-                               + indexingContext.getGlobalUrl()
-                               + UrlParamEncoder.encode(indexingContext.getLocalUrl()
-                                               + "/" + file.fileName) + "\">\n");
+                               .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
+                                               + indexingContext.getGlobalUrl()
+                                               + UrlParamEncoder.encode(indexingContext.getLocalUrl()
+                                                               + "/" + file.fileName) + "\">\n");
                filesHtml.append("</source>\n");
                filesHtml.append("</video>\n");
                filesHtml.append("<br/>\n");
 
                // video title
                filesHtml
-               .append("Video: <b>"
-                               + FilePathParser
-                               .getFileNameWithoutExtension(file.fileName)
-                               + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
+                               .append("Video: <b>"
+                                               + FilePathParser
+                                                               .getFileNameWithoutExtension(file.fileName)
+                                               + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
 
                // video download link
                filesHtml.append("<a href=\""
index fa692d6..2d3f29d 100644 (file)
@@ -7,10 +7,10 @@ import eu.svjatoslav.commons.file.IOHelper;
 
 public class MevizSpecialFile extends AbstractFile {
 
-       private String fileContent;
-
        private static final long serialVersionUID = -8749190459653455640L;
 
+       private String fileContent;
+
        public MevizSpecialFile(final File parentDirectory, final String fileName)
                        throws Exception {
                super(parentDirectory, fileName);
index 2b9b802..274b8ca 100755 (executable)
@@ -32,6 +32,8 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
 
 public class Picture extends AbstractFile {
 
+       private static final long serialVersionUID = -4156533490858298387L;
+
        private static void ensureNonzeroImageArea(final java.awt.Dimension result) {
                if (result.width < 1)
                        result.width = 1;
@@ -142,9 +144,7 @@ public class Picture extends AbstractFile {
                final Image newImage = Toolkit.getDefaultToolkit().createImage(prod);
 
                return new ImageIcon(newImage).getImage();
-       }
-
-       private static final long serialVersionUID = -4156533490858298387L;;
+       };
 
        /**
         * Picture dimensions.
index a9a1c04..6b74c86 100755 (executable)
@@ -14,14 +14,14 @@ import java.util.ArrayList;
 
 public class RenamingOptions {
 
-    public ArrayList<String> inputPatterns = new ArrayList<String>();
+       public ArrayList<String> inputPatterns = new ArrayList<String>();
 
-    public boolean recursive = false;
+       public boolean recursive = false;
 
-    public boolean testOnly = false;
+       public boolean testOnly = false;
 
-    public String outputPattern;
+       public String outputPattern;
 
-    public File targetDirectory;
+       public File targetDirectory;
 
 }
index 3f153c9..3c4cc56 100755 (executable)
@@ -30,7 +30,7 @@ public class CommandlineHandler {
 
        StringParameter replaceWithPattern = parser.add(
                        new StringParameter("String to place instead")).addAliases("-p",
-                                       "--replace-pattern");
+                       "--replace-pattern");
 
        DirectoryParameter directoryParameter = parser
                        .add(new DirectoryParameter("Working directory."))
index ab46832..3e93006 100755 (executable)
@@ -17,7 +17,6 @@ public class CommandlineOptions {
 
        public String replaceWithPattern;
 
-
        public boolean recursive = false;
 
        public File targetDirectory;
index e77e822..303c607 100755 (executable)
@@ -26,7 +26,7 @@ public class CommandlineHandler {
 
        StringParameters inputPatternParameter = parser.add(
                        new StringParameters("File input pattern.")).addAliases("-i",
-                                       "--input-pattern");
+                       "--input-pattern");
 
        DirectoryParameter workingDirectoryParameter = parser.add(
                        new DirectoryParameter("Working directory.")).addAliases("-w",