From 0679806fed21137dc0d10f1ef99dc1bba73ddb95 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 28 Apr 2015 21:55:39 +0300 Subject: [PATCH] added webm support + sorted members + formatted code --- src/main/java/eu/svjatoslav/meviz/Module.java | 8 +++--- .../meviz/bomremove/CommandlineHandler.java | 2 +- .../meviz/encoder/CommandlineHandler.java | 6 ++--- .../eu/svjatoslav/meviz/encoder/Encoder.java | 8 +++--- .../meviz/encoder/EncodingTask.java | 16 ++++++++---- .../encoder/converters/AbstractConverter.java | 4 +-- .../meviz/encoder/converters/AvconvAudio.java | 4 +-- .../meviz/encoder/converters/AvconvVideo.java | 26 +++++++++++++------ .../meviz/encoder/converters/Convert.java | 4 +-- .../encoder/converters/Ffmpeg2theora.java | 2 +- .../meviz/encoder/converters/Flac.java | 4 +-- .../meviz/encoder/converters/Midi2Wav.java | 2 +- .../meviz/encoder/converters/Ogg2Wav.java | 4 +-- .../eu/svjatoslav/meviz/grabmemcard/Main.java | 2 +- .../meviz/htmlindexer/FilesystemIndexer.java | 6 ++--- .../meviz/htmlindexer/ImageFormatError.java | 8 +++--- .../svjatoslav/meviz/htmlindexer/Utils.java | 8 +++--- .../htmlindexer/layouts/MixedLayout.java | 26 +++++++++---------- .../metadata/fileTypes/MevizSpecialFile.java | 4 +-- .../metadata/fileTypes/Picture.java | 6 ++--- .../meviz/renamer/RenamingOptions.java | 10 +++---- .../meviz/replace/CommandlineHandler.java | 2 +- .../meviz/replace/CommandlineOptions.java | 1 - .../texttruncate/CommandlineHandler.java | 2 +- 24 files changed, 91 insertions(+), 74 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/Module.java b/src/main/java/eu/svjatoslav/meviz/Module.java index 797aa1d..026ec6a 100755 --- a/src/main/java/eu/svjatoslav/meviz/Module.java +++ b/src/main/java/eu/svjatoslav/meviz/Module.java @@ -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(); } diff --git a/src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java index fdfc3c9..46750a3 100755 --- a/src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java @@ -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.")) diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java index ff4b8ec..1f38b17 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java @@ -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 diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java b/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java index e60140b..4b56b13 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java @@ -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); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java index 535f8f7..816fba7 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingTask.java @@ -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); } /** diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java index 1e5d565..6d61f91 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AbstractConverter.java @@ -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 getSourceFileExtensions(); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java index a87777f..5dd258a 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvAudio.java @@ -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"; diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java index f0d80bf..ea08e5d 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java @@ -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 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 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) { diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java index 418cd51..e7abf57 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java @@ -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() + "\""; } diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java index a9d86ee..b2afedb 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ffmpeg2theora.java @@ -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"; diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java index f7c6785..bf239cc 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Flac.java @@ -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() + "\""; diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Midi2Wav.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Midi2Wav.java index 972780f..d823761 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Midi2Wav.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Midi2Wav.java @@ -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() + "\""; 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 618f616..f89927b 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Wav.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Ogg2Wav.java @@ -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() + "\""; diff --git a/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java b/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java index d6d194c..dac58fd 100755 --- a/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java +++ b/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java @@ -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); } } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java index f7cb130..061163e 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java @@ -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); } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/ImageFormatError.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/ImageFormatError.java index 7d40bf4..783f802 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/ImageFormatError.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/ImageFormatError.java @@ -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); + } } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java index 9da4656..6200e06 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java @@ -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; - } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java index ddacb56..fd70b10 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java @@ -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 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("