Improves utility code
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
This commit is contained in:
@ -35,6 +35,79 @@ public final class FFMpegHelper {
|
||||
return parseStreams(ffprobePath, probeForStreams(ffprobePath, file), file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list containing all required arguments for converting a video to a web playable video
|
||||
*
|
||||
* @param executable <p>The executable to use (ffmpeg/ffprobe).</p>
|
||||
* @param fileName <p>The name of the file to execute on.</p>
|
||||
* @return <p>A base list of ffmpeg commands for converting a video for web</p>
|
||||
*/
|
||||
public static List<String> getFFMpegWebVideoCommand(String executable, String fileName) {
|
||||
List<String> command = getFFMpegGeneralFileCommand(executable, fileName);
|
||||
command.add("-vcodec");
|
||||
command.add("h264");
|
||||
command.add("-pix_fmt");
|
||||
command.add("yuv420p");
|
||||
command.add("-ar");
|
||||
command.add("48000");
|
||||
command.add("-movflags");
|
||||
command.add("+faststart");
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list containing command line arguments for a general file
|
||||
*
|
||||
* @param executable <p>The executable to use (ffmpeg/ffprobe).</p>
|
||||
* @param fileName <p>The name of the file to execute on.</p>
|
||||
* @return <p>A base list of ffmpeg commands for converting a file.</p>
|
||||
*/
|
||||
public static List<String> getFFMpegGeneralFileCommand(String executable, String fileName) {
|
||||
List<String> command = new ArrayList<>();
|
||||
command.add(executable);
|
||||
command.add("-nostdin");
|
||||
command.add("-i");
|
||||
command.add(fileName);
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds debugging parameters for only converting parts of a file
|
||||
*
|
||||
* @param command <p>The list containing the command to run.</p>
|
||||
* @param start <p>The offset before converting.</p>
|
||||
* @param length <p>The offset for stopping the conversion.</p>
|
||||
*/
|
||||
public static void addDebugArguments(List<String> command, int start, int length) {
|
||||
command.add("-ss");
|
||||
command.add("" + start);
|
||||
command.add("-t");
|
||||
command.add("" + length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts and prints output of a process
|
||||
*
|
||||
* @param process <p>The process to run.</p>
|
||||
* @param folder <p>The folder the process should run in.</p>
|
||||
* @throws IOException <p>If the process can't be readProcess.</p>
|
||||
*/
|
||||
public static void convertProcess(ProcessBuilder process, File folder) throws IOException {
|
||||
OutputUtil.print("Command to be run: ");
|
||||
OutputUtil.println(process.command().toString());
|
||||
process.directory(folder);
|
||||
process.redirectErrorStream(true);
|
||||
Process processConvert = process.start();
|
||||
BufferedReader readerConvert = new BufferedReader(new InputStreamReader(processConvert.getInputStream()));
|
||||
while (processConvert.isAlive()) {
|
||||
String read = readProcess(readerConvert, "\n");
|
||||
if (!read.equals("")) {
|
||||
OutputUtil.println(read);
|
||||
}
|
||||
}
|
||||
OutputUtil.println("Process finished.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all streams in a file
|
||||
*
|
||||
@ -129,29 +202,6 @@ public final class FFMpegHelper {
|
||||
return parsedStreams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts and prints output of a process
|
||||
*
|
||||
* @param process <p>The process to run.</p>
|
||||
* @param folder <p>The folder the process should run in.</p>
|
||||
* @throws IOException <p>If the process can't be readProcess.</p>
|
||||
*/
|
||||
public static void convertProcess(ProcessBuilder process, File folder) throws IOException {
|
||||
OutputUtil.print("Command to be run: ");
|
||||
OutputUtil.println(process.command().toString());
|
||||
process.directory(folder);
|
||||
process.redirectErrorStream(true);
|
||||
Process processConvert = process.start();
|
||||
BufferedReader readerConvert = new BufferedReader(new InputStreamReader(processConvert.getInputStream()));
|
||||
while (processConvert.isAlive()) {
|
||||
String read = readProcess(readerConvert, "\n");
|
||||
if (!read.equals("")) {
|
||||
OutputUtil.println(read);
|
||||
}
|
||||
}
|
||||
OutputUtil.println("Process is finished.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads from a process reader
|
||||
*
|
||||
@ -168,56 +218,6 @@ public final class FFMpegHelper {
|
||||
return text.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list containing all required arguments for converting a video to a web playable video
|
||||
*
|
||||
* @param executable <p>The executable to use (ffmpeg/ffprobe).</p>
|
||||
* @param fileName <p>The name of the file to execute on.</p>
|
||||
* @return <p>A base list of ffmpeg commands for converting a video for web</p>
|
||||
*/
|
||||
public static List<String> getFFMpegWebVideoCommand(String executable, String fileName) {
|
||||
List<String> command = getFFMpegGeneralFileCommand(executable, fileName);
|
||||
command.add("-vcodec");
|
||||
command.add("h264");
|
||||
command.add("-pix_fmt");
|
||||
command.add("yuv420p");
|
||||
command.add("-ar");
|
||||
command.add("48000");
|
||||
command.add("-movflags");
|
||||
command.add("+faststart");
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list containing command line arguments for a general file
|
||||
*
|
||||
* @param executable <p>The executable to use (ffmpeg/ffprobe).</p>
|
||||
* @param fileName <p>The name of the file to execute on.</p>
|
||||
* @return <p>A base list of ffmpeg commands for converting a file.</p>
|
||||
*/
|
||||
public static List<String> getFFMpegGeneralFileCommand(String executable, String fileName) {
|
||||
List<String> command = new ArrayList<>();
|
||||
command.add(executable);
|
||||
command.add("-nostdin");
|
||||
command.add("-i");
|
||||
command.add(fileName);
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds debugging parameters for only converting parts of a file
|
||||
*
|
||||
* @param command <p>The list containing the command to run.</p>
|
||||
* @param start <p>The offset before converting.</p>
|
||||
* @param length <p>The offset for stopping the conversion.</p>
|
||||
*/
|
||||
public static void addDebugArguments(List<String> command, int start, int length) {
|
||||
command.add("-ss");
|
||||
command.add("" + start);
|
||||
command.add("-t");
|
||||
command.add("" + length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a list of video stream parameters to a video stream object
|
||||
*
|
||||
|
Reference in New Issue
Block a user