From 5d6cdd532d23ef8a0e8aa379e6170d382740717e Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 9 Mar 2021 18:55:24 +0200 Subject: [PATCH] Added WebP support --- .../meviz/encoder/FormatsRegistry.java | 1 + .../meviz/encoder/converters/Convert.java | 10 +--- .../meviz/encoder/converters/Cwebp.java | 56 +++++++++++++++++++ 3 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java index d03b2e0..c0de0fd 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java @@ -22,6 +22,7 @@ public class FormatsRegistry { // image conversion registerEncoder(new Convert()); + registerEncoder(new Cwebp()); // image to text (OCR) registerEncoder(new Ocr()); 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 9de771f..1b02131 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Convert.java @@ -1,11 +1,7 @@ /* - * Meviz - Various tools collection to work with multimedia. - * Copyright (C) 2012 -- 2017-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later as published by the Free Software Foundation. -*/ + * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. + */ package eu.svjatoslav.meviz.encoder.converters; diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java new file mode 100644 index 0000000..ca329e0 --- /dev/null +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Cwebp.java @@ -0,0 +1,56 @@ +/* + * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. + */ + +package eu.svjatoslav.meviz.encoder.converters; + +import eu.svjatoslav.meviz.encoder.EncodingOptions; + +import java.io.File; +import java.util.List; + +public class Cwebp extends AbstractConverter { + + @Override + public String getCommand(final File inputFile, final File targetFile, + final EncodingOptions options, String targetFormat) { + + String quality; + + switch (options.getVideoBitrate()) { + case LOW: + quality = " -q 10 "; + break; + case MEDIUM: + quality = " -q 50 "; + break; + case HIGH: + quality = " -q 80 "; + break; + case COPY: + case LOSSLESS: + default: + quality = " -lossless "; + } + + return "cwebp \"" + inputFile.getAbsolutePath() + "\"" + quality + " -o \"" + + targetFile.getAbsolutePath() + "\""; + } + + @Override + public List getSourceFileExtensions() { + return toList("tif", "tiff", "png", "jpg", "jpeg", "bmp", "gif"); + } + + @Override + public List getTargetFileExtensions() { + return toList("webp"); + } + + @Override + public boolean isTerminalMandatory() { + return false; + } + +} -- 2.20.1