diff --git a/README.md b/README.md index aeb55fb..b30243d 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,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 @@ -64,7 +70,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 ``` @@ -72,7 +77,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 ``` 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 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/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 3c04564..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 @@ -77,27 +77,8 @@ 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 +88,43 @@ private void processFile(File exampleImage) { } } + private String[] getFFmpegArgumentsBasedOnOS(String findPattern, String resultFilePath, int indexSize) { + String ffmpeg; + if (commonUtils.isWindows()) { + 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 + }; + } + } 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..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.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; - } - }