Enabled deprication warnings, fixed some of the warnings

This commit is contained in:
Ziver Koc 2025-12-18 01:00:03 +01:00
parent 5f02f65ead
commit 986ec8958a
17 changed files with 235 additions and 109 deletions

View file

@ -80,6 +80,10 @@ java {
withJavadocJar() withJavadocJar()
} }
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
sourceSets { sourceSets {
main { main {
java { java {

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2020 Ziver Koc * Copyright (c) 2020-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -31,6 +31,7 @@ import javax.naming.InitialContext;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.Closeable; import java.io.Closeable;
import java.lang.reflect.InvocationTargetException;
import java.sql.*; import java.sql.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -110,10 +111,10 @@ public class DBConnection implements Closeable{
* @param db is the DB type * @param db is the DB type
* @return the protocol name of the DBMS * @return the protocol name of the DBMS
*/ */
public static String initDriver(DBMS db) throws InstantiationException, IllegalAccessException, ClassNotFoundException{ public static String initDriver(DBMS db) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
switch(db) { switch(db) {
case MySQL: case MySQL:
Class.forName("com.mysql.jdbc.Driver").newInstance(); Class.forName("com.mysql.jdbc.Driver").getDeclaredConstructor().newInstance();
DriverManager.setLoginTimeout(10); DriverManager.setLoginTimeout(10);
return "mysql"; return "mysql";
case SQLite: case SQLite:

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2020 Ziver Koc * Copyright (c) 2020-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -27,6 +27,7 @@ package zutil.image;
import zutil.ProgressListener; import zutil.ProgressListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
/** /**
* This is a abstract class for all the effects * This is a abstract class for all the effects
@ -74,8 +75,8 @@ public abstract class ImageFilterProcessor {
* @param img The image to process * @param img The image to process
* @return The processed image * @return The processed image
*/ */
public static ImageFilterProcessor getProcessor(String effect, BufferedImage img) throws InstantiationException, IllegalAccessException, ClassNotFoundException { public static ImageFilterProcessor getProcessor(String effect, BufferedImage img) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
ImageFilterProcessor processor = (ImageFilterProcessor)Class.forName(effect).newInstance(); ImageFilterProcessor processor = (ImageFilterProcessor)Class.forName(effect).getDeclaredConstructor().newInstance();
processor.img = img; processor.img = img;
return processor; return processor;
} }

View file

@ -1,3 +1,27 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2025 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package zutil.net.acme; package zutil.net.acme;
import org.shredzone.acme4j.toolbox.AcmeUtils; import org.shredzone.acme4j.toolbox.AcmeUtils;
@ -12,6 +36,9 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
/**
* A file based datastore for storing ACME protocol needed data.
*/
public class AcmeFileDataStore implements AcmeDataStore { public class AcmeFileDataStore implements AcmeDataStore {
private final File accountLocationFile; private final File accountLocationFile;

View file

@ -189,9 +189,9 @@ public class HttpURL {
for (String key : parameters.keySet()) { for (String key : parameters.keySet()) {
if (param.length() > 0) if (param.length() > 0)
param.append('&'); param.append('&');
param.append(URLEncoder.encode(key)); param.append(URLEncoder.encode(key, StandardCharsets.UTF_8));
param.append('='); param.append('=');
param.append(URLEncoder.encode(parameters.get(key))); param.append(URLEncoder.encode(parameters.get(key), StandardCharsets.UTF_8));
} }
return param.toString(); return param.toString();
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2020 Ziver Koc * Copyright (c) 2020-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -32,6 +32,7 @@ import zutil.net.http.HttpPrintStream;
import zutil.net.http.HttpURL; import zutil.net.http.HttpURL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -111,7 +112,7 @@ public class OAuth2AuthorizationPage implements HttpPage {
} }
try { try {
url = new HttpURL(URLDecoder.decode(request.get("redirect_uri"))); url = new HttpURL(URLDecoder.decode(request.get("redirect_uri"), StandardCharsets.UTF_8));
} catch(Exception e) {} } catch(Exception e) {}
if (url == null || !"HTTPS".equalsIgnoreCase(url.getProtocol())) { if (url == null || !"HTTPS".equalsIgnoreCase(url.getProtocol())) {

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2020 Ziver Koc * Copyright (c) 2020-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -165,6 +165,7 @@ public class HttpServletRequestImpl implements HttpServletRequest {
} }
@Override @Override
@Deprecated
public boolean isRequestedSessionIdFromUrl() { public boolean isRequestedSessionIdFromUrl() {
return false; return false;
} }
@ -325,6 +326,7 @@ public class HttpServletRequestImpl implements HttpServletRequest {
} }
@Override @Override
@Deprecated
public String getRealPath(String s) { public String getRealPath(String s) {
return null; return null;
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2020 Ziver Koc * Copyright (c) 2020-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -56,11 +56,13 @@ public class HttpServletResponseImpl implements HttpServletResponse {
} }
@Override @Override
@Deprecated
public String encodeUrl(String s) { public String encodeUrl(String s) {
return null; return null;
} }
@Override @Override
@Deprecated
public String encodeRedirectUrl(String s) { public String encodeRedirectUrl(String s) {
return null; return null;
} }
@ -116,6 +118,7 @@ public class HttpServletResponseImpl implements HttpServletResponse {
} }
@Override @Override
@Deprecated
public void setStatus(int i, String s) { public void setStatus(int i, String s) {
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2020 Ziver Koc * Copyright (c) 2020-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -63,6 +63,7 @@ public class HttpSessionImpl implements HttpSession {
} }
@Override @Override
@Deprecated
public HttpSessionContext getSessionContext() { public HttpSessionContext getSessionContext() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -73,6 +74,7 @@ public class HttpSessionImpl implements HttpSession {
} }
@Override @Override
@Deprecated
public Object getValue(String name) { public Object getValue(String name) {
return null; return null;
} }
@ -83,6 +85,7 @@ public class HttpSessionImpl implements HttpSession {
} }
@Override @Override
@Deprecated
public String[] getValueNames() { public String[] getValueNames() {
return new String[0]; return new String[0];
} }
@ -93,6 +96,7 @@ public class HttpSessionImpl implements HttpSession {
} }
@Override @Override
@Deprecated
public void putValue(String name, Object value) { public void putValue(String name, Object value) {
} }
@ -103,6 +107,7 @@ public class HttpSessionImpl implements HttpSession {
} }
@Override @Override
@Deprecated
public void removeValue(String name) { public void removeValue(String name) {
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2020 Ziver Koc * Copyright (c) 2020-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -24,6 +24,7 @@
package zutil.net.ws; package zutil.net.ws;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Collection; import java.util.Collection;
@ -132,7 +133,7 @@ public class WebServiceDef {
return path; return path;
} }
public WSInterface newInstance() throws InstantiationException, IllegalAccessException { public WSInterface newInstance() throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
return intf.newInstance(); return intf.getDeclaredConstructor().newInstance();
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2021 Ziver Koc * Copyright (c) 2021-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -24,12 +24,15 @@
package zutil.osal.app.ffmpeg; package zutil.osal.app.ffmpeg;
import zutil.log.LogUtil;
import zutil.osal.app.ffmpeg.FFmpegConstants.*; import zutil.osal.app.ffmpeg.FFmpegConstants.*;
import zutil.osal.app.ffmpeg.FFmpegProgressManager.FFmpegProgressListener; import zutil.osal.app.ffmpeg.FFmpegProgressManager.FFmpegProgressListener;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger;
/** /**
* Class for building a ffmpeg commandline for execution * Class for building a ffmpeg commandline for execution
@ -37,6 +40,8 @@ import java.util.List;
* @see <a href="https://ffmpeg.org/ffmpeg.html">FFmpeg Commandline Documentation</a> * @see <a href="https://ffmpeg.org/ffmpeg.html">FFmpeg Commandline Documentation</a>
*/ */
public class FFmpeg { public class FFmpeg {
private Logger logger = LogUtil.getLogger();
private FFmpegLogLevel logLevel; private FFmpegLogLevel logLevel;
private boolean overwriteOutput = false; private boolean overwriteOutput = false;
private List<FFmpegInput> inputs = new ArrayList<>(); private List<FFmpegInput> inputs = new ArrayList<>();
@ -81,22 +86,28 @@ public class FFmpeg {
} }
public String buildCommand() { /**
StringBuilder command = new StringBuilder(); * Will generate a parameter list that will be supplied to ffmpeg binary based on the Object configuration.
command.append("ffmpeg"); *
* @return a list of parameter that should be supplied to FFmpeg
*/
public List<String> buildCommand() {
List<String> command = new ArrayList<>();
// General inputs // General inputs
if (logLevel != null) { if (logLevel != null) {
command.append(" -loglevel ").append(logLevel.toString().toLowerCase()); command.add("-loglevel");
command.add(logLevel.toString().toLowerCase());
} }
if (progressManager != null) { if (progressManager != null) {
command.append(" -progress ").append(progressManager.getAddress()); command.add("-progress");
command.add(progressManager.getAddress());
} }
if (overwriteOutput) { if (overwriteOutput) {
command.append(" -y"); command.add("-y");
} }
// TODO: -stdin Enable interaction on standard input // TODO: -stdin Enable interaction on standard input
@ -104,15 +115,35 @@ public class FFmpeg {
// Inputs // Inputs
for (FFmpegInput input : inputs) { for (FFmpegInput input : inputs) {
command.append(" ").append(input.buildCommand()); command.addAll(input.buildCommand());
} }
// Outputs // Outputs
for (FFmpegOutput output : outputs) { for (FFmpegOutput output : outputs) {
command.append(" ").append(output.buildCommand()); command.addAll(output.buildCommand());
} }
return command.toString(); return command;
}
/**
* Will execute the ffmpeg binary with the configured parameters.
* Recommended to use {@see OSALBinaryManager} to select correct FFmpeg binary depending on OS.
*
* @param ffmpegPath The path to the FFmpeg binary. (OS dependent)
* @return a Process object containing the execution of FFmpeg.
*/
public Process execute(File ffmpegPath) throws IOException {
List<String> cmd = new ArrayList<>();
cmd.add(ffmpegPath.getAbsolutePath());
cmd.addAll(buildCommand());
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
logger.finest("Executing FFmpeg: " + String.join(" ", cmd));
return pb.start();
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2021 Ziver Koc * Copyright (c) 2021-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -24,8 +24,6 @@
package zutil.osal.app.ffmpeg; package zutil.osal.app.ffmpeg;
import zutil.StringUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -88,6 +86,7 @@ public class FFmpegInput {
/** /**
* Add additional args that may not be supported by the API, these values will be inserted to the command line as is. * Add additional args that may not be supported by the API, these values will be inserted to the command line as is.
* Each argument must be a separate String in the list.
* *
* @param args a list of additional commands * @param args a list of additional commands
*/ */
@ -102,7 +101,7 @@ public class FFmpegInput {
/** /**
* Enable or Blocks audio from input file. (enabled by default) * Enable or Blocks audio from input file. (enabled by default)
* *
* @param enabled Set to false to disable audio * @param enabled Set too false to disable audio
*/ */
public void setAudioEnabled(boolean enabled) { public void setAudioEnabled(boolean enabled) {
this.audioEnabled = enabled; this.audioEnabled = enabled;
@ -115,7 +114,7 @@ public class FFmpegInput {
/** /**
* Enable or Blocks subtitles from input file. (enabled by default) * Enable or Blocks subtitles from input file. (enabled by default)
* *
* @param enabled Set to false to disable subtitles * @param enabled Set too false to disable subtitles
*/ */
public void setSubtitleEnabled(boolean enabled) { public void setSubtitleEnabled(boolean enabled) {
this.subtitleEnabled = enabled; this.subtitleEnabled = enabled;
@ -125,36 +124,46 @@ public class FFmpegInput {
// Command Generation // Command Generation
// ---------------------------------------------------- // ----------------------------------------------------
protected String buildCommand() { protected List<String> buildCommand() {
StringBuilder command = new StringBuilder(); List<String> command = new ArrayList<>();
// ---------------------------------------------------- // ----------------------------------------------------
// General Options // General Options
// ---------------------------------------------------- // ----------------------------------------------------
if (positionStart != null) if (positionStart != null) {
command.append(" -ss ").append(positionStart); command.add("-ss");
if (positionEnd != null) command.add(String.valueOf(positionStart));
command.append(" -to ").append(positionEnd); }
if (duration != null) if (positionEnd != null) {
command.append(" -t ").append(duration); command.add("-to");
command.add(String.valueOf(positionEnd));
}
if (duration != null) {
command.add("-t");
command.add(String.valueOf(duration));
}
// ---------------------------------------------------- // ----------------------------------------------------
// Audio Options // Audio Options
// ---------------------------------------------------- // ----------------------------------------------------
if (!audioEnabled) if (!audioEnabled) {
command.append(" -an"); command.add("-an");
}
// ---------------------------------------------------- // ----------------------------------------------------
// Subtitle Options // Subtitle Options
// ---------------------------------------------------- // ----------------------------------------------------
if (!subtitleEnabled) if (!subtitleEnabled) {
command.append(" -sn"); command.add("-sn");
}
command.append(StringUtil.join(" ", additionalArgs)); command.addAll(additionalArgs);
command.append(" -i \"").append(input).append("\"");
return command.toString().trim(); command.add("-i");
command.add(input);
return command;
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2021 Ziver Koc * Copyright (c) 2021-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -24,7 +24,6 @@
package zutil.osal.app.ffmpeg; package zutil.osal.app.ffmpeg;
import zutil.StringUtil;
import zutil.osal.app.ffmpeg.FFmpegConstants.FFmpegAudioCodec; import zutil.osal.app.ffmpeg.FFmpegConstants.FFmpegAudioCodec;
import zutil.osal.app.ffmpeg.FFmpegConstants.FFmpegSubtitleCodec; import zutil.osal.app.ffmpeg.FFmpegConstants.FFmpegSubtitleCodec;
import zutil.osal.app.ffmpeg.FFmpegConstants.FFmpegVideoCodec; import zutil.osal.app.ffmpeg.FFmpegConstants.FFmpegVideoCodec;
@ -126,6 +125,7 @@ public class FFmpegOutput {
/** /**
* Add additional args that may not be supported by the API, these values will be inserted to the command line as is. * Add additional args that may not be supported by the API, these values will be inserted to the command line as is.
* Each argument must be a separate String in the list.
* *
* @param args a list of FFmpeg arguments * @param args a list of FFmpeg arguments
*/ */
@ -282,7 +282,7 @@ public class FFmpegOutput {
/** /**
* Enable or Disables subtitles in output file. (enabled by default) * Enable or Disables subtitles in output file. (enabled by default)
* *
* @param enabled Set to false to disable subtitles * @param enabled Set too false to disable subtitles
*/ */
public void setSubtitleEnabled(boolean enabled) { public void setSubtitleEnabled(boolean enabled) {
this.subtitleEnabled = enabled; this.subtitleEnabled = enabled;
@ -292,70 +292,104 @@ public class FFmpegOutput {
// Command Generation // Command Generation
// ---------------------------------------------------- // ----------------------------------------------------
protected String buildCommand() { protected List<String> buildCommand() {
StringBuilder command = new StringBuilder(); List<String> command = new ArrayList<>();
// ---------------------------------------------------- // ----------------------------------------------------
// General Options // General Options
// ---------------------------------------------------- // ----------------------------------------------------
if (positionStart != null) if (positionStart != null) {
command.append(" -ss ").append(positionStart); command.add("-ss");
if (positionEnd != null) command.add(String.valueOf(positionStart));
command.append(" -to ").append(positionEnd); }
if (duration != null) if (positionEnd != null) {
command.append(" -t ").append(duration); command.add("-to");
if (fileSize != null) command.add(String.valueOf(positionEnd));
command.append(" -fs ").append(fileSize); }
if (duration != null) {
command.add("-t");
command.add(String.valueOf(duration));
}
if (fileSize != null) {
command.add("-fs");
command.add(String.valueOf(fileSize));
}
if (encodingPass != null) if (encodingPass != null) {
command.append(" -pass ").append(encodingPass); command.add("-pass");
command.add(String.valueOf(encodingPass));
}
// ---------------------------------------------------- // ----------------------------------------------------
// Video Options // Video Options
// ---------------------------------------------------- // ----------------------------------------------------
if (videoCodec != null) if (videoCodec != null) {
command.append(" -codec:v ").append(videoCodec); command.add("-codec:v");
if (videoFrameRate != null) command.add(videoCodec);
command.append(" -frames ").append(videoFrameRate); }
if (videoWidth != null && videoHeight != null) if (videoFrameRate != null) {
command.append(" -filter:v scale=").append(videoWidth).append(':').append(videoHeight); command.add("-frames");
if (videoBitRate != null) command.add(String.valueOf(videoFrameRate));
command.append(" -b:v ").append(videoBitRate); }
if (videoQuality != null) if (videoWidth != null && videoHeight != null) {
command.append(" -qscale:v ").append(videoQuality); command.add("-filter:v");
command.add("scale=" + videoWidth + ":" + videoHeight);
}
if (videoBitRate != null) {
command.add("-b:v");
command.add(String.valueOf(videoBitRate));
}
if (videoQuality != null) {
command.add("-qscale:v");
command.add(String.valueOf(videoQuality));
}
// ---------------------------------------------------- // ----------------------------------------------------
// Audio Options // Audio Options
// ---------------------------------------------------- // ----------------------------------------------------
if (audioCodec != null) if (audioCodec != null) {
command.append(" -codec:a ").append(audioCodec); command.add("-codec:a");
if (audioSampleRate != null) command.add(audioCodec);
command.append(" -ar ").append(audioSampleRate); }
if (audioChannels != null) if (audioSampleRate != null) {
command.append(" -ac ").append(audioChannels); command.add("-ar");
if (audioBitRate != null) command.add(String.valueOf(audioSampleRate));
command.append(" -b:a ").append(audioBitRate); }
if (audioQuality != null) if (audioChannels != null) {
command.append(" -qscale:a ").append(audioQuality); command.add("-ac");
command.add(String.valueOf(audioChannels));
}
if (audioBitRate != null) {
command.add("-b:a");
command.add(String.valueOf(audioBitRate));
}
if (audioQuality != null) {
command.add("-qscale:a");
command.add(String.valueOf(audioQuality));
}
if (!audioEnabled) if (!audioEnabled) {
command.append(" -an"); command.add("-an");
}
// ---------------------------------------------------- // ----------------------------------------------------
// Subtitle Options // Subtitle Options
// ---------------------------------------------------- // ----------------------------------------------------
if (subtitleCodec != null) if (subtitleCodec != null) {
command.append(" -codec:s ").append(subtitleCodec); command.add("-codec:s");
command.add(subtitleCodec);
}
if (!subtitleEnabled) if (!subtitleEnabled) {
command.append(" -sn"); command.add("-sn");
}
command.append(StringUtil.join(" ", additionalArgs)); command.addAll(additionalArgs);
command.append(" \"").append(output).append("\""); command.add(output);
return command.toString().trim(); return command;
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2020 Ziver Koc * Copyright (c) 2020-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -152,7 +152,7 @@ public class PluginData {
private <T> T getObject(Class<T> objClass) { private <T> T getObject(Class<T> objClass) {
try { try {
if (!objectMap.containsKey(objClass)) if (!objectMap.containsKey(objClass))
objectMap.put(objClass, objClass.newInstance()); objectMap.put(objClass, objClass.getDeclaredConstructor().newInstance());
return (T) objectMap.get(objClass); return (T) objectMap.get(objClass);
} catch (Exception e) { } catch (Exception e) {
log.log(Level.WARNING, "Unable to instantiate plugin class: " + objClass, e); log.log(Level.WARNING, "Unable to instantiate plugin class: " + objClass, e);

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2021 Ziver Koc * Copyright (c) 2021-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -26,6 +26,8 @@ package zutil.osal.app.ffmpeg;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class FFmpegInputTest { public class FFmpegInputTest {
@ -34,7 +36,7 @@ public class FFmpegInputTest {
public void onlyInput() { public void onlyInput() {
FFmpegInput ffmpegInput = new FFmpegInput("iTest.mp4"); FFmpegInput ffmpegInput = new FFmpegInput("iTest.mp4");
assertEquals("-i \"iTest.mp4\"", ffmpegInput.buildCommand()); assertEquals(Arrays.asList("-i", "iTest.mp4"), ffmpegInput.buildCommand());
} }
@Test @Test
@ -48,9 +50,10 @@ public class FFmpegInputTest {
ffmpegInput.setSubtitleEnabled(false); ffmpegInput.setSubtitleEnabled(false);
assertEquals("-ss 9.1 -to 20.1 -t 10.1" + assertEquals(Arrays.asList("-ss", "9.1", "-to", "20.1", "-t", "10.1",
" -an" + "-an",
" -sn" + "-sn",
" -i \"iTest.mp4\"", ffmpegInput.buildCommand()); "-i", "iTest.mp4"),
ffmpegInput.buildCommand());
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2021 Ziver Koc * Copyright (c) 2021-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -26,6 +26,8 @@ package zutil.osal.app.ffmpeg;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class FFmpegOutputTest { public class FFmpegOutputTest {
@ -34,7 +36,7 @@ public class FFmpegOutputTest {
public void onlyOutput() { public void onlyOutput() {
FFmpegOutput ffmpegOutput = new FFmpegOutput("oTest.mp4"); FFmpegOutput ffmpegOutput = new FFmpegOutput("oTest.mp4");
assertEquals("\"oTest.mp4\"", ffmpegOutput.buildCommand()); assertEquals(Arrays.asList("oTest.mp4"), ffmpegOutput.buildCommand());
} }
@ -63,11 +65,11 @@ public class FFmpegOutputTest {
ffmpegOutput.setSubtitleCodec(FFmpegConstants.FFmpegSubtitleCodec.subrip); ffmpegOutput.setSubtitleCodec(FFmpegConstants.FFmpegSubtitleCodec.subrip);
ffmpegOutput.setSubtitleEnabled(false); ffmpegOutput.setSubtitleEnabled(false);
assertEquals("-ss 9.1 -to 20.1 -t 10.1 -fs 1000 -pass 2" + assertEquals(Arrays.asList("-ss", "9.1", "-to", "20.1", "-t", "10.1", "-fs", "1000", "-pass", "2",
" -codec:v libx264 -frames 29.8 -filter:v scale=320:240 -b:v 300000 -qscale:v 22" + "-codec:v", "libx264", "-frames", "29.8", "-filter:v", "scale=320:240", "-b:v", "300000", "-qscale:v", "22",
" -codec:a libmp3lame -ar 48000 -ac 6 -b:a 360000 -qscale:a 23 -an" + "-codec:a", "libmp3lame", "-ar", "48000", "-ac", "6", "-b:a", "360000", "-qscale:a", "23", "-an",
" -codec:s subrip -sn" + "-codec:s", "subrip", "-sn",
" \"oTest.mp4\"", "oTest.mp4"),
ffmpegOutput.buildCommand()); ffmpegOutput.buildCommand());
} }

View file

@ -1,7 +1,7 @@
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2021 Ziver Koc * Copyright (c) 2021-2025 Ziver Koc
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -27,6 +27,8 @@ package zutil.osal.app.ffmpeg;
import org.junit.Test; import org.junit.Test;
import zutil.osal.app.ffmpeg.FFmpegConstants.*; import zutil.osal.app.ffmpeg.FFmpegConstants.*;
import java.util.Arrays;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -38,7 +40,7 @@ public class FFmpegTest {
ffmpeg.addInput(new FFmpegInput("iTest.mp4")); ffmpeg.addInput(new FFmpegInput("iTest.mp4"));
ffmpeg.addOutput(new FFmpegOutput("oTest.mp4")); ffmpeg.addOutput(new FFmpegOutput("oTest.mp4"));
assertEquals("ffmpeg -i \"iTest.mp4\" \"oTest.mp4\"", ffmpeg.buildCommand()); assertEquals(Arrays.asList("-i", "iTest.mp4", "oTest.mp4"), ffmpeg.buildCommand());
} }
@Test @Test
@ -48,7 +50,7 @@ public class FFmpegTest {
ffmpeg.addInput(new FFmpegInput("iTest.mp4")); ffmpeg.addInput(new FFmpegInput("iTest.mp4"));
ffmpeg.addOutput(new FFmpegOutput("oTest.mp4")); ffmpeg.addOutput(new FFmpegOutput("oTest.mp4"));
assertEquals("ffmpeg -loglevel error -i \"iTest.mp4\" \"oTest.mp4\"", ffmpeg.buildCommand()); assertEquals(Arrays.asList("-loglevel", "error", "-i", "iTest.mp4", "oTest.mp4"), ffmpeg.buildCommand());
} }
@Test @Test
@ -58,6 +60,6 @@ public class FFmpegTest {
ffmpeg.addInput(new FFmpegInput("iTest.mp4")); ffmpeg.addInput(new FFmpegInput("iTest.mp4"));
ffmpeg.addOutput(new FFmpegOutput("oTest.mp4")); ffmpeg.addOutput(new FFmpegOutput("oTest.mp4"));
assertEquals("ffmpeg -y -i \"iTest.mp4\" \"oTest.mp4\"", ffmpeg.buildCommand()); assertEquals(Arrays.asList("-y", "-i", "iTest.mp4", "oTest.mp4"), ffmpeg.buildCommand());
} }
} }