Skip to content

Commit 7338748

Browse files
Extract helper method
1 parent 34a197e commit 7338748

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ private static File convertWithFfmpeg(File file) throws MediaException {
412412
};
413413

414414
try {
415-
var command = Stream.concat(Arrays.stream(baseFfmpegCommand), Arrays.stream(pass1Options))
416-
.toArray(String[]::new);
417-
ProcessHelper.executeCommand(command);
415+
ProcessHelper.executeCommand(buildFfmpegCommand(baseFfmpegCommand, pass1Options));
418416
} catch (ProcessException e) {
419417
deleteFile(logFile);
420418
throw new MediaException(e.getMessage());
@@ -428,9 +426,7 @@ private static File convertWithFfmpeg(File file) throws MediaException {
428426
};
429427

430428
try {
431-
var command = Stream.concat(Arrays.stream(baseFfmpegCommand), Arrays.stream(pass2Options))
432-
.toArray(String[]::new);
433-
ProcessHelper.executeCommand(command);
429+
ProcessHelper.executeCommand(buildFfmpegCommand(baseFfmpegCommand, pass2Options));
434430
} catch (ProcessException e) {
435431
deleteFile(webmVideo);
436432
throw new MediaException(e.getMessage());
@@ -441,6 +437,17 @@ private static File convertWithFfmpeg(File file) throws MediaException {
441437
return webmVideo;
442438
}
443439

440+
/**
441+
* Builds the ffmpeg command combining a base part with a specific part (useful for 2 pass processing)
442+
*
443+
* @param baseCommand the common ffmpeg command
444+
* @param additionalOptions command specific options
445+
* @return the complete ffmpeg invocation command
446+
*/
447+
private static String[] buildFfmpegCommand(String[] baseCommand, String[] additionalOptions) {
448+
return Stream.concat(Arrays.stream(baseCommand), Arrays.stream(additionalOptions)).toArray(String[]::new);
449+
}
450+
444451
private MediaHelper() {
445452
throw new UnsupportedOperationException();
446453
}

0 commit comments

Comments
 (0)