Skip to content

Commit

Permalink
Version 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
EoinKanro authored Apr 3, 2023
2 parents 23d6131 + 84c9687 commit 05e5cef
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 48 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ Requirements for start:
- FFmpeg

Start application:
- Download ffmpeg. For example from here: <a href="https://www.gyan.dev/ffmpeg/builds/ffmpeg-git-full.7z">FFmpeg</a>
- Put ffmpeg.exe into project-folder near the jar
- Install ffmpeg
- - Unix: for example:
```
brew install ffmpeg
```
- - Windows: download <a href="https://www.gyan.dev/ffmpeg/builds/ffmpeg-git-full.7z">FFmpeg</a>.
And put ffmpeg.exe into project-folder near the jar

```
cd <project-folder>
java -jar FilesToVideos.jar <arguments>
Expand All @@ -64,15 +70,13 @@ There are several custom arguments for command line, you can use -h to see them

**Example of converting files to videos:**
```
cd <project-folder>
java -jar -Xmx2048m -Xms2048m FilesToVideosConverter.jar -fti -itv -fp in -diip
```

It transforms files from project-folder/in to videos and delete temp images in process

**Example of converting videos to files:**
```
cd <project-folder>
java -jar -Xmx2048m -Xms2048m FilesToVideosConverter.jar -vti -itf -vp resultVideos202303222343 -diip
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>io.github.eoinkanro.files-to-videos-converter</groupId>
<artifactId>files-to-videos-converter</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>

<properties>
<java.version>17</java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,8 @@ public abstract class Transformer {
@Autowired
protected BytesUtils bytesUtils;
@Autowired
protected CommonUtils commonUtils;
@Autowired
protected TransformerTaskExecutor transformerTaskExecutor;

public final void transform() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
};
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class FileUtils {

@Autowired
private InputCLIArgumentsHolder inputCLIArgumentsHolder;
@Autowired
private CommonUtils commonUtils;


//--------------- Result files -------------------
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 05e5cef

Please sign in to comment.