From bf38572bec87cdbb91b883930a6f68d0fd77fc24 Mon Sep 17 00:00:00 2001 From: eoinkanro Date: Mon, 3 Apr 2023 21:43:31 +0400 Subject: [PATCH 1/4] Add Unix supporting --- .../conf/OutputCLIArguments.java | 3 +- .../impl/ImagesToVideosTransformer.java | 73 +++++++++++++------ .../impl/VideosToImagesTransformer.java | 2 +- 3 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/github/eoinkanro/filestovideosconverter/conf/OutputCLIArguments.java b/src/main/java/io/github/eoinkanro/filestovideosconverter/conf/OutputCLIArguments.java index d04fd1d..6d4e108 100644 --- a/src/main/java/io/github/eoinkanro/filestovideosconverter/conf/OutputCLIArguments.java +++ b/src/main/java/io/github/eoinkanro/filestovideosconverter/conf/OutputCLIArguments.java @@ -6,7 +6,8 @@ @Getter @AllArgsConstructor public enum OutputCLIArguments { - FFMPEG("ffmpeg.exe"), + FFMPEG("ffmpeg"), + FFMPEG_EXE("ffmpeg.exe"), DEFAULT_YES("-y"), FRAMERATE("-framerate"), PATTERN_TYPE("-pattern_type"), diff --git a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/ImagesToVideosTransformer.java b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/ImagesToVideosTransformer.java index 3c04564..8cc032e 100644 --- a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/ImagesToVideosTransformer.java +++ b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/ImagesToVideosTransformer.java @@ -6,6 +6,7 @@ import io.github.eoinkanro.filestovideosconverter.transformer.TransformException; import io.github.eoinkanro.filestovideosconverter.utils.CommandLineExecutor; import lombok.extern.log4j.Log4j2; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import java.io.File; @@ -19,6 +20,8 @@ public class ImagesToVideosTransformer extends ImagesTransformer { @Autowired private CommandLineExecutor commandLineExecutor; + private String os; + public ImagesToVideosTransformer(InputCLIArgument activeTransformerArgument, InputCLIArgument pathToFileArgument) { super(activeTransformerArgument, pathToFileArgument); } @@ -77,27 +80,7 @@ private void processFile(File exampleImage) { String findPattern = fileUtils.getFFmpegImagesToVideosPattern(exampleImage.getAbsolutePath()); boolean isWritten = commandLineExecutor.execute( - FFMPEG.getValue(), - DEFAULT_YES.getValue(), - FRAMERATE.getValue(), - inputCLIArgumentsHolder.getArgument(InputCLIArguments.FRAMERATE), - PATTERN_TYPE.getValue(), - SEQUENCE.getValue(), - START_NUMBER.getValue(), - "0".repeat(indexSize), - INPUT.getValue(), - BRACKETS_PATTERN.formatValue(findPattern), - CODEC_VIDEO.getValue(), - LIBX264.getValue(), - MOV_FLAGS.getValue(), - FAST_START.getValue(), - CRF.getValue(), - CRF_18.getValue(), - PIXEL_FORMAT.getValue(), - GRAY.getValue(), - PRESET.getValue(), - SLOW.getValue(), - BRACKETS_PATTERN.formatValue(resultFile.getAbsolutePath())); + getFFmpegArgumentsBasedOnOS(findPattern, resultFile.getAbsolutePath(), indexSize)); if (!isWritten) { throw new TransformException("Error while writing " + resultFile); @@ -107,4 +90,52 @@ private void processFile(File exampleImage) { } } + private String[] getFFmpegArgumentsBasedOnOS(String findPattern, String resultFilePath, int indexSize) { + String os = getOs(); + + String ffmpeg; + if (os.startsWith("windows")) { + ffmpeg = FFMPEG_EXE.getValue(); + findPattern = BRACKETS_PATTERN.formatValue(findPattern); + resultFilePath = BRACKETS_PATTERN.formatValue(resultFilePath); + } else { + ffmpeg = FFMPEG.getValue(); + } + + return getFFmpegArguments(ffmpeg, findPattern, resultFilePath, indexSize); + } + + private String[] getFFmpegArguments(String ffmpeg, String findPattern, String resultFilePath, int indexSize) { + return new String[] { + ffmpeg, + DEFAULT_YES.getValue(), + FRAMERATE.getValue(), + inputCLIArgumentsHolder.getArgument(InputCLIArguments.FRAMERATE), + PATTERN_TYPE.getValue(), + SEQUENCE.getValue(), + START_NUMBER.getValue(), + "0".repeat(indexSize), + INPUT.getValue(), + findPattern, + CODEC_VIDEO.getValue(), + LIBX264.getValue(), + MOV_FLAGS.getValue(), + FAST_START.getValue(), + CRF.getValue(), + CRF_18.getValue(), + PIXEL_FORMAT.getValue(), + GRAY.getValue(), + PRESET.getValue(), + SLOW.getValue(), + resultFilePath + }; + } + + private String getOs() { + if (StringUtils.isEmpty(os)) { + os = System.getProperty("os.name").toLowerCase(); + } + return os; + } + } diff --git a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/VideosToImagesTransformer.java b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/VideosToImagesTransformer.java index 6fa388d..9ef9bf2 100644 --- a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/VideosToImagesTransformer.java +++ b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/VideosToImagesTransformer.java @@ -55,7 +55,7 @@ private void processFile(File file) { log.info("Processing {}...", file); String imagesPattern = fileUtils.getFFmpegVideosToImagesPattern(file, fileUtils.getResultPathForVideos()); boolean isWritten = commandLineExecutor.execute( - FFMPEG.getValue(), + FFMPEG_EXE.getValue(), DEFAULT_YES.getValue(), INPUT.getValue(), BRACKETS_PATTERN.formatValue(file.getAbsolutePath()), From 82fb1c492cfc0e33415aaf89c7bae75c9350f3c4 Mon Sep 17 00:00:00 2001 From: eoinkanro Date: Mon, 3 Apr 2023 21:48:34 +0400 Subject: [PATCH 2/4] Update README --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9a8f0e1..ad1d668 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,14 @@ Requirements for start: - FFmpeg Start application: -- Download ffmpeg. For example from here: FFmpeg -- Put ffmpeg.exe into project-folder near the jar +- Install ffmpeg +- - Unix: for example: +``` + brew install ffmpeg +``` +- - Windows: download FFmpeg. +And put ffmpeg.exe into project-folder near the jar + ``` cd java -jar FilesToVideos.jar @@ -61,7 +67,6 @@ There are several custom arguments for command line, you can use -h to see them **Example of converting files to videos:** ``` -cd java -jar -Xmx2048m -Xms2048m FilesToVideosConverter.jar -fti -itv -fp in -diip ``` @@ -69,7 +74,6 @@ It transforms files from project-folder/in to videos and delete temp images in p **Example of converting videos to files:** ``` -cd java -jar -Xmx2048m -Xms2048m FilesToVideosConverter.jar -vti -itf -vp resultVideos202303222343 -diip ``` From 9bcde708809c82c53cd8c52c47a70b9da4748353 Mon Sep 17 00:00:00 2001 From: eoinkanro Date: Mon, 3 Apr 2023 22:12:02 +0400 Subject: [PATCH 3/4] Add Unix supporting --- .../transformer/Transformer.java | 3 ++ .../impl/ImagesToVideosTransformer.java | 17 ++------- .../impl/VideosToImagesTransformer.java | 37 ++++++++++++++----- .../utils/CommonUtils.java | 29 +++++++++++++++ .../utils/FileUtils.java | 17 +++------ 5 files changed, 68 insertions(+), 35 deletions(-) create mode 100644 src/main/java/io/github/eoinkanro/filestovideosconverter/utils/CommonUtils.java diff --git a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/Transformer.java b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/Transformer.java index 62e7f85..e7a58e5 100644 --- a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/Transformer.java +++ b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/Transformer.java @@ -4,6 +4,7 @@ import io.github.eoinkanro.filestovideosconverter.conf.InputCLIArgument; import io.github.eoinkanro.filestovideosconverter.conf.InputCLIArgumentsHolder; import io.github.eoinkanro.filestovideosconverter.utils.BytesUtils; +import io.github.eoinkanro.filestovideosconverter.utils.CommonUtils; import io.github.eoinkanro.filestovideosconverter.utils.FileUtils; import io.github.eoinkanro.filestovideosconverter.utils.concurrent.TransformerTaskExecutor; import lombok.RequiredArgsConstructor; @@ -29,6 +30,8 @@ public abstract class Transformer { @Autowired protected BytesUtils bytesUtils; @Autowired + protected CommonUtils commonUtils; + @Autowired protected TransformerTaskExecutor transformerTaskExecutor; public final void transform() { diff --git a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/ImagesToVideosTransformer.java b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/ImagesToVideosTransformer.java index 8cc032e..853cadb 100644 --- a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/ImagesToVideosTransformer.java +++ b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/ImagesToVideosTransformer.java @@ -6,7 +6,6 @@ import io.github.eoinkanro.filestovideosconverter.transformer.TransformException; import io.github.eoinkanro.filestovideosconverter.utils.CommandLineExecutor; import lombok.extern.log4j.Log4j2; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import java.io.File; @@ -20,8 +19,6 @@ public class ImagesToVideosTransformer extends ImagesTransformer { @Autowired private CommandLineExecutor commandLineExecutor; - private String os; - public ImagesToVideosTransformer(InputCLIArgument activeTransformerArgument, InputCLIArgument pathToFileArgument) { super(activeTransformerArgument, pathToFileArgument); } @@ -80,7 +77,8 @@ private void processFile(File exampleImage) { String findPattern = fileUtils.getFFmpegImagesToVideosPattern(exampleImage.getAbsolutePath()); boolean isWritten = commandLineExecutor.execute( - getFFmpegArgumentsBasedOnOS(findPattern, resultFile.getAbsolutePath(), indexSize)); + getFFmpegArgumentsBasedOnOS(findPattern, resultFile.getAbsolutePath(), indexSize) + ); if (!isWritten) { throw new TransformException("Error while writing " + resultFile); @@ -91,10 +89,8 @@ private void processFile(File exampleImage) { } private String[] getFFmpegArgumentsBasedOnOS(String findPattern, String resultFilePath, int indexSize) { - String os = getOs(); - String ffmpeg; - if (os.startsWith("windows")) { + if (commonUtils.isWindows()) { ffmpeg = FFMPEG_EXE.getValue(); findPattern = BRACKETS_PATTERN.formatValue(findPattern); resultFilePath = BRACKETS_PATTERN.formatValue(resultFilePath); @@ -131,11 +127,4 @@ private String[] getFFmpegArguments(String ffmpeg, String findPattern, String re }; } - private String getOs() { - if (StringUtils.isEmpty(os)) { - os = System.getProperty("os.name").toLowerCase(); - } - return os; - } - } diff --git a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/VideosToImagesTransformer.java b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/VideosToImagesTransformer.java index 9ef9bf2..47eca6d 100644 --- a/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/VideosToImagesTransformer.java +++ b/src/main/java/io/github/eoinkanro/filestovideosconverter/transformer/impl/VideosToImagesTransformer.java @@ -50,17 +50,12 @@ private void processFolder(File[] files) { } } - private void processFile(File file) { + private void processFile(File videoFile) { try { - log.info("Processing {}...", file); - String imagesPattern = fileUtils.getFFmpegVideosToImagesPattern(file, fileUtils.getResultPathForVideos()); + log.info("Processing {}...", videoFile); + String imagesPattern = fileUtils.getFFmpegVideosToImagesPattern(videoFile, fileUtils.getResultPathForVideos()); boolean isWritten = commandLineExecutor.execute( - FFMPEG_EXE.getValue(), - DEFAULT_YES.getValue(), - INPUT.getValue(), - BRACKETS_PATTERN.formatValue(file.getAbsolutePath()), - BRACKETS_PATTERN.formatValue(imagesPattern), - HIDE_BANNER.getValue() + getFFmpegArgumentsBasedOnOS(fileUtils.getAbsolutePath(videoFile.getAbsolutePath()), imagesPattern) ); if (!isWritten) { @@ -71,4 +66,28 @@ private void processFile(File file) { } } + private String[] getFFmpegArgumentsBasedOnOS(String videoFilePath, String imagesPattern) { + String ffmpeg; + if (commonUtils.isWindows()) { + ffmpeg = FFMPEG_EXE.getValue(); + videoFilePath = BRACKETS_PATTERN.formatValue(videoFilePath); + imagesPattern = BRACKETS_PATTERN.formatValue(imagesPattern); + } else { + ffmpeg = FFMPEG.getValue(); + } + + return getFFmpegArguments(ffmpeg, videoFilePath, imagesPattern); + } + + private String[] getFFmpegArguments(String ffmpeg, String videoFilePath, String imagesPattern) { + return new String[] { + ffmpeg, + DEFAULT_YES.getValue(), + INPUT.getValue(), + videoFilePath, + imagesPattern, + HIDE_BANNER.getValue() + }; + } + } diff --git a/src/main/java/io/github/eoinkanro/filestovideosconverter/utils/CommonUtils.java b/src/main/java/io/github/eoinkanro/filestovideosconverter/utils/CommonUtils.java new file mode 100644 index 0000000..129b122 --- /dev/null +++ b/src/main/java/io/github/eoinkanro/filestovideosconverter/utils/CommonUtils.java @@ -0,0 +1,29 @@ +package io.github.eoinkanro.filestovideosconverter.utils; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +@Component +public class CommonUtils { + + private String osName; + + public int parseInt(String anIntString) { + if (!StringUtils.isBlank(anIntString)) { + return Integer.parseInt(anIntString); + } + return 0; + } + + public boolean isWindows() { + return getOsName().startsWith("windows"); + } + + public String getOsName() { + if (StringUtils.isEmpty(osName)) { + osName = System.getProperty("os.name").toLowerCase(); + } + return osName; + } + +} diff --git a/src/main/java/io/github/eoinkanro/filestovideosconverter/utils/FileUtils.java b/src/main/java/io/github/eoinkanro/filestovideosconverter/utils/FileUtils.java index aa57e6f..a49b2b9 100644 --- a/src/main/java/io/github/eoinkanro/filestovideosconverter/utils/FileUtils.java +++ b/src/main/java/io/github/eoinkanro/filestovideosconverter/utils/FileUtils.java @@ -24,6 +24,8 @@ public class FileUtils { @Autowired private InputCLIArgumentsHolder inputCLIArgumentsHolder; + @Autowired + private CommonUtils commonUtils; //--------------- Result files ------------------- @@ -271,7 +273,7 @@ public int calculateLastZeroBytesAmount(File file) { * @return - index */ public int getImageIndex(String filePath) { - return parseInt(getImageIndexString(filePath)); + return commonUtils.parseInt(getImageIndexString(filePath)); } /** @@ -304,7 +306,7 @@ public int getImageIndexSize(String filePath) { * @return - duplicate factor */ public int getImageDuplicateFactor(String filePath) { - return parseInt(getImageDuplicateFactorString(filePath)); + return commonUtils.parseInt(getImageDuplicateFactorString(filePath)); } /** @@ -327,7 +329,7 @@ private String getImageDuplicateFactorString(String filePath) { * @return - count */ public int getImageLastZeroBytesCount(String filePath) { - return parseInt(getLastZeroBytesCountString(filePath)); + return commonUtils.parseInt(getLastZeroBytesCountString(filePath)); } /** @@ -455,13 +457,4 @@ private void deleteFolder(File[] files) throws IOException { } } - //------------------- Utils ----------------- - - private int parseInt(String anIntString) { - if (!StringUtils.isBlank(anIntString)) { - return Integer.parseInt(anIntString); - } - return 0; - } - } From 84c96873757c46c8abe67f4596f0a9f6e6f7777b Mon Sep 17 00:00:00 2001 From: eoinkanro Date: Mon, 3 Apr 2023 22:24:25 +0400 Subject: [PATCH 4/4] Version 1.0.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c9fdc38..fd52882 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ io.github.eoinkanro.files-to-videos-converter files-to-videos-converter - 1.0.5 + 1.0.6 17