Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
fe29664a83 | |||
5e8da26257 | |||
763c27ca95 | |||
a8302c38e0 | |||
a977ff8cfe | |||
b049581632 | |||
5bde5bfee0 | |||
347211d566 | |||
204a5e15f1 | |||
26ec5d2782 | |||
21ea8b3caf | |||
12ab510224 | |||
f861445697 | |||
ffb7d2d9f1 | |||
3742c44c40 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
|||||||
.settings/
|
.settings/
|
||||||
target/
|
target/
|
||||||
.idea/
|
.idea/
|
||||||
|
logs/
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
pipeline:
|
pipeline:
|
||||||
|
test:
|
||||||
|
image: maven:3-jdk-11
|
||||||
|
commands:
|
||||||
|
- mvn test
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: maven:3-jdk-11
|
image: maven:3-jdk-11
|
||||||
commands:
|
commands:
|
||||||
- mvn clean package
|
- mvn clean compile assembly:single
|
||||||
|
|
||||||
gitea_release:
|
gitea_release:
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
|
43
README.md
43
README.md
@ -1,3 +1,42 @@
|
|||||||
# dragoon
|
# Dragoon
|
||||||
|
|
||||||
Bit Goblin video transcoder
|
The Bit Goblin video transcoder.
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
Currently this project is targeting Java 11 LTS and uses Maven to manage the software lifecycle. Thus, you must have a Java 11 JDK and Maven installed to build this project.
|
||||||
|
|
||||||
|
*NOTE:* The targeted Java version will likely change to 17 LTS soon.
|
||||||
|
|
||||||
|
### Ubuntu
|
||||||
|
|
||||||
|
`sudo apt install openjdk-11-jdk maven`
|
||||||
|
|
||||||
|
### Red Hat/Almalinux
|
||||||
|
|
||||||
|
`sudo dnf install java-11-openjdk-devel maven`
|
||||||
|
|
||||||
|
### Actually Building
|
||||||
|
|
||||||
|
Now that the needed tools are installed, you should be able to build this project. To build a JAR file with it's dependencies included:
|
||||||
|
|
||||||
|
`mvn clean compile assembly:single`
|
||||||
|
|
||||||
|
Then you can run the transcoder:
|
||||||
|
|
||||||
|
`java -jar target/Dragon-VERSION-jar-with-dependencies.jar`
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
If you were paying attention to Dragoon's output, you would have noticed that it failed with a complaint about not finding a configuration file. The location might move in the future or even be configurable, but for now you need to have a TOML file located at `~/.config/dragoon.toml` with at minimum the following contents:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
# This example transcodes footage to DNxHD 1080p60 for use in video editors like DaVinci Resolve.
|
||||||
|
[transcoder]
|
||||||
|
repo_path = '~/videos' # location of the videos to transcode
|
||||||
|
video_format = 'mov' # video container format
|
||||||
|
video_codec = 'dnxhd' # video codec to use
|
||||||
|
video_parameters = 'scale=1920x1080,fps=60,format=yuv422p' # video extra format parameters flag - this will be broken later into separate attributes
|
||||||
|
video_profile = 'dnxhr_hq' # DNxHD has multiple presets for various video qualities
|
||||||
|
audio_codec = 'pcm_s16le' # audio codec to use
|
||||||
|
```
|
||||||
|
190
pom.xml
190
pom.xml
@ -1,86 +1,122 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>tech.bitgoblin</groupId>
|
<groupId>tech.bitgoblin</groupId>
|
||||||
<artifactId>Dragoon</artifactId>
|
<artifactId>Dragoon</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.3.0</version>
|
||||||
|
|
||||||
<name>Dragoon</name>
|
<name>Dragoon</name>
|
||||||
<url>https://www.bitgoblin.tech</url>
|
<url>https://www.bitgoblin.tech</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.tomlj</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>tomlj</artifactId>
|
||||||
<version>4.11</version>
|
<version>1.0.0</version>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
</dependencies>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
<version>2.17.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.17.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-clean-plugin</artifactId>
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.0.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.22.1</version>
|
<version>2.22.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>3.0.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!-- DO NOT include log4j.properties file in your Jar -->
|
<!-- DO NOT include log4j.properties file in your Jar -->
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/log4j.properties</exclude>
|
<exclude>**/log4j.properties</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<!-- Jar file entry point -->
|
<!-- Jar file entry point -->
|
||||||
<mainClass>tech.bitgoblin.App</mainClass>
|
<mainClass>tech.bitgoblin.App</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>2.5.2</version>
|
<executions>
|
||||||
</plugin>
|
<execution>
|
||||||
<plugin>
|
<phase>package</phase>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<goals>
|
||||||
<version>2.8.2</version>
|
<goal>single</goal>
|
||||||
</plugin>
|
</goals>
|
||||||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
</execution>
|
||||||
<plugin>
|
</executions>
|
||||||
<artifactId>maven-site-plugin</artifactId>
|
<configuration>
|
||||||
<version>3.7.1</version>
|
<archive>
|
||||||
</plugin>
|
<manifest>
|
||||||
<plugin>
|
<mainClass>tech.bitgoblin.App</mainClass>
|
||||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
</manifest>
|
||||||
<version>3.0.0</version>
|
</archive>
|
||||||
</plugin>
|
<descriptorRefs>
|
||||||
</plugins>
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
</pluginManagement>
|
</descriptorRefs>
|
||||||
</build>
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package tech.bitgoblin;
|
package tech.bitgoblin;
|
||||||
|
|
||||||
import tech.bitgoblin.video.Transcoder;
|
import tech.bitgoblin.config.Config;
|
||||||
|
import tech.bitgoblin.transcoder.RunTranscoderTask;
|
||||||
|
import tech.bitgoblin.transcoder.Transcoder;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Bit Goblin video transcoder service.
|
* The Bit Goblin video transcoder service.
|
||||||
@ -8,10 +12,18 @@ import tech.bitgoblin.video.Transcoder;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
|
private static final String configFile = "~/.config/dragoon.toml";
|
||||||
|
|
||||||
|
private static final int msToMinutes = 60 * 1000;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
// read our config file
|
||||||
|
Config c = new Config(configFile);
|
||||||
// create new Transcoder object and start the service
|
// create new Transcoder object and start the service
|
||||||
Transcoder t = new Transcoder("~/dragoon");
|
Transcoder t = new Transcoder(c);
|
||||||
t.transcode();
|
Timer timer = new Timer();
|
||||||
|
timer.scheduleAtFixedRate(new RunTranscoderTask(t), 2500, ((long) c.getInt("transcoder.interval") * msToMinutes));
|
||||||
|
Logger.logger.info(String.format("Starting transcoder, running in %d minute intervals.", c.getInt("transcoder.interval")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
9
src/main/java/tech/bitgoblin/Logger.java
Normal file
9
src/main/java/tech/bitgoblin/Logger.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package tech.bitgoblin;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
|
||||||
|
public static org.apache.logging.log4j.Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
}
|
49
src/main/java/tech/bitgoblin/config/Config.java
Normal file
49
src/main/java/tech/bitgoblin/config/Config.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package tech.bitgoblin.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.tomlj.Toml;
|
||||||
|
import org.tomlj.TomlParseResult;
|
||||||
|
import tech.bitgoblin.Logger;
|
||||||
|
import tech.bitgoblin.io.IOUtils;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
private final String configPath;
|
||||||
|
private TomlParseResult result;
|
||||||
|
|
||||||
|
public Config(String path) {
|
||||||
|
this.configPath = IOUtils.resolveTilda(path);
|
||||||
|
// parse config file
|
||||||
|
try {
|
||||||
|
this.parseConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Logger.logger.info("Unable to read config file; please check that " + this.configPath + " is available.");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String key) {
|
||||||
|
return this.result.getString(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInt(String key) {
|
||||||
|
return Objects.requireNonNull(this.result.getLong(key)).intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(String key) {
|
||||||
|
return this.result.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseConfig() throws IOException {
|
||||||
|
// parse config file
|
||||||
|
Path source = Paths.get(this.configPath);
|
||||||
|
this.result = Toml.parse(source);
|
||||||
|
this.result.errors().forEach(error -> System.err.println(error.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,9 +14,9 @@ public class IOUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String resolveTilda(String path) {
|
public static String resolveTilda(String path) {
|
||||||
if (path.startsWith("~" + File.separator)) {
|
if (path.startsWith("~" + File.separator) || path.equals("~")) {
|
||||||
path = System.getProperty("user.home") + path.substring(1);
|
path = System.getProperty("user.home") + path.substring(1);
|
||||||
} else if (path.startsWith("~")) {
|
} else if ((!path.equals("~")) && path.startsWith("~")) {
|
||||||
// here you can implement reading homedir of other users if you care
|
// here you can implement reading homedir of other users if you care
|
||||||
throw new UnsupportedOperationException("Home dir expansion not implemented for explicit usernames");
|
throw new UnsupportedOperationException("Home dir expansion not implemented for explicit usernames");
|
||||||
}
|
}
|
||||||
|
74
src/main/java/tech/bitgoblin/transcoder/Repository.java
Normal file
74
src/main/java/tech/bitgoblin/transcoder/Repository.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package tech.bitgoblin.transcoder;
|
||||||
|
|
||||||
|
import tech.bitgoblin.Logger;
|
||||||
|
import tech.bitgoblin.io.IOUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
public class Repository {
|
||||||
|
|
||||||
|
private String repoPath;
|
||||||
|
private String ingestPath;
|
||||||
|
private String outputPath;
|
||||||
|
private String archivePath;
|
||||||
|
|
||||||
|
public Repository(String repoPath) {
|
||||||
|
this.repoPath = IOUtils.resolveTilda(repoPath);
|
||||||
|
this.ingestPath = Paths.get(this.repoPath, "ingest").toString();
|
||||||
|
this.outputPath = Paths.get(this.repoPath, "output").toString();
|
||||||
|
this.archivePath = Paths.get(this.repoPath, "archive").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// initializes the video repository
|
||||||
|
public void init() {
|
||||||
|
String[] dirs = {this.repoPath, this.ingestPath, this.outputPath, this.archivePath};
|
||||||
|
for (String p : dirs) {
|
||||||
|
IOUtils.createDirectory(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// searches this ingest directory for video files
|
||||||
|
public File[] searchIngest() {
|
||||||
|
Logger.logger.info("Searching for files to transcode in " + this.ingestPath);
|
||||||
|
File repo = new File(this.ingestPath);
|
||||||
|
return repo.listFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
// archives files in the ingest directory
|
||||||
|
public void archiveIngest(File[] sourceFiles) {
|
||||||
|
for (File f : sourceFiles) {
|
||||||
|
Path filePath = Path.of(f.toString());
|
||||||
|
String filename = filePath.getFileName().toString();
|
||||||
|
String archivePath = Paths.get(this.archivePath, filename).toString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.copy(filePath, Paths.get(archivePath), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean up the ingest directory once we're done
|
||||||
|
public void cleanupIngest(File[] sourceFiles) {
|
||||||
|
for (File f : sourceFiles) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the repository's path
|
||||||
|
public String getPath() {
|
||||||
|
return this.repoPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the repository's output path
|
||||||
|
public String getOutputPath() {
|
||||||
|
return this.outputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package tech.bitgoblin.transcoder;
|
||||||
|
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
public class RunTranscoderTask extends TimerTask {
|
||||||
|
|
||||||
|
private Transcoder transcoder;
|
||||||
|
|
||||||
|
public RunTranscoderTask(Transcoder t) {
|
||||||
|
this.transcoder = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// archive the files
|
||||||
|
transcoder.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
89
src/main/java/tech/bitgoblin/transcoder/Transcoder.java
Normal file
89
src/main/java/tech/bitgoblin/transcoder/Transcoder.java
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
package tech.bitgoblin.transcoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.InterruptedException;
|
||||||
|
import java.lang.Process;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
|
import tech.bitgoblin.Logger;
|
||||||
|
import tech.bitgoblin.config.Config;
|
||||||
|
import tech.bitgoblin.io.IOUtils;
|
||||||
|
|
||||||
|
public class Transcoder {
|
||||||
|
|
||||||
|
private Repository repo;
|
||||||
|
private Config config;
|
||||||
|
private String ffmpeg_path = "/usr/bin/ffmpeg";
|
||||||
|
|
||||||
|
// only define the working directory; use default FFMPEG path
|
||||||
|
public Transcoder(Config config) {
|
||||||
|
this.config = config;
|
||||||
|
this.repo = new Repository(this.config.getString("transcoder.repo_path"));
|
||||||
|
if (this.config.contains("transcoder.ffmpeg_path")) {
|
||||||
|
this.ffmpeg_path = this.config.getString("transcoder.ffmpeg_path");
|
||||||
|
}
|
||||||
|
this.repo.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a periodic timer task and start it
|
||||||
|
public void run() {
|
||||||
|
// pull list of files to transcode
|
||||||
|
File[] sourceFiles = this.repo.searchIngest();
|
||||||
|
|
||||||
|
// archive files
|
||||||
|
this.repo.archiveIngest(sourceFiles);
|
||||||
|
// transcode files
|
||||||
|
this.transcode(sourceFiles);
|
||||||
|
// cleanup old files
|
||||||
|
this.repo.cleanupIngest(sourceFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
// transcode files in the working directory
|
||||||
|
public void transcode(File[] sourceFiles) {
|
||||||
|
// check if the ingest directory is empty
|
||||||
|
if (sourceFiles.length == 0) {
|
||||||
|
Logger.logger.info("There is nothing to transcode in ingest.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// transcode
|
||||||
|
Logger.logger.info("Transcoding video files ingest...");
|
||||||
|
for (File f : sourceFiles) {
|
||||||
|
String filePath = f.toString().substring(0, f.toString().lastIndexOf("."));
|
||||||
|
String filename = Paths.get(filePath).getFileName().toString();
|
||||||
|
String outputPath = Paths.get(this.repo.getOutputPath(), String.format("%s.mov", filename)).toString();
|
||||||
|
|
||||||
|
String cmd = String.format("%s -i %s -y -f %s -c:v %s -vf %s -profile:v %s -c:a %s %s",
|
||||||
|
this.ffmpeg_path, // FFMPEG binary path
|
||||||
|
f.toString(), // input file
|
||||||
|
this.config.getString("transcoder.video_format"), // video container format
|
||||||
|
this.config.getString("transcoder.video_codec"), // video codec
|
||||||
|
this.config.getString("transcoder.video_parameters"), // video format
|
||||||
|
this.config.getString("transcoder.video_profile"), // video profile
|
||||||
|
this.config.getString("transcoder.audio_codec"), // audio codec
|
||||||
|
outputPath // output file path
|
||||||
|
);
|
||||||
|
|
||||||
|
ProcessBuilder pb = new ProcessBuilder(cmd.split("\\s+"));
|
||||||
|
pb.inheritIO(); // use the java processes' input and output streams
|
||||||
|
try {
|
||||||
|
Process process = pb.start();
|
||||||
|
int ret = process.waitFor();
|
||||||
|
Logger.logger.info("Program exited with code: %d", ret);
|
||||||
|
Logger.logger.info("");
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// end output
|
||||||
|
Logger.logger.info("------------ End of transcoding ------------");
|
||||||
|
Logger.logger.info("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,87 +0,0 @@
|
|||||||
package tech.bitgoblin.video;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.InterruptedException;
|
|
||||||
import java.lang.Process;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import tech.bitgoblin.io.IOUtils;
|
|
||||||
|
|
||||||
public class Transcoder {
|
|
||||||
|
|
||||||
private String repo_dir;
|
|
||||||
private String ffmpeg_path = "/usr/bin/ffmpeg";
|
|
||||||
|
|
||||||
// only define the working directory; use default FFMPEG path
|
|
||||||
public Transcoder(String repo_dir) {
|
|
||||||
this.repo_dir = IOUtils.resolveTilda(repo_dir);
|
|
||||||
this.initDirectory();
|
|
||||||
}
|
|
||||||
// define a custom FFMPEG binary path
|
|
||||||
public Transcoder(String repo_dir, String ffmpeg_path) {
|
|
||||||
this.repo_dir = IOUtils.resolveTilda(repo_dir);
|
|
||||||
this.ffmpeg_path = ffmpeg_path;
|
|
||||||
this.initDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
// transcode files in the working directory
|
|
||||||
public void transcode() {
|
|
||||||
// search for files
|
|
||||||
System.out.println("Searching for files to transcode in " + this.repo_dir);
|
|
||||||
File repo = new File(Paths.get(this.repo_dir, "ingest").toString());
|
|
||||||
File[] sourceFiles = repo.listFiles();
|
|
||||||
|
|
||||||
// transcode
|
|
||||||
System.out.println("Transcoding files in " + this.repo_dir + "/ingest...");
|
|
||||||
for (File f : sourceFiles) {
|
|
||||||
String filePath = f.toString().substring(0, f.toString().lastIndexOf("."));
|
|
||||||
String filename = Paths.get(filePath).getFileName().toString();
|
|
||||||
String outputPath = Paths.get(this.repo_dir, "output", String.format("%s.mov", filename)).toString();
|
|
||||||
|
|
||||||
String cmd = String.format("%s -i %s -y -f %s -c:v %s -vf %s -profile:v %s -c:a %s %s",
|
|
||||||
this.ffmpeg_path, // FFMPEG binary path
|
|
||||||
f.toString(), // input file
|
|
||||||
"mov",
|
|
||||||
"dnxhd", // video codec
|
|
||||||
"scale=1920x1080,fps=60,format=yuv422p", // video format
|
|
||||||
"dnxhr_hq", // video profile
|
|
||||||
"pcm_s16le", // audio codec
|
|
||||||
outputPath // output file path
|
|
||||||
);
|
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(cmd.split("\\s+"));
|
|
||||||
pb.inheritIO(); // use the java processes' input and output streams
|
|
||||||
try {
|
|
||||||
Process process = pb.start();
|
|
||||||
int ret = process.waitFor();
|
|
||||||
System.out.printf("Program exited with code: %d\n", ret);
|
|
||||||
System.out.println(String.join(" ", pb.command()));
|
|
||||||
System.out.println();
|
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// end output
|
|
||||||
System.out.println("------------ End of transcoding ------------");
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensures the transcoder's working directory is available
|
|
||||||
private void initDirectory() {
|
|
||||||
// create transcoder directory
|
|
||||||
IOUtils.createDirectory(this.repo_dir);
|
|
||||||
// create the sub-directories
|
|
||||||
IOUtils.createDirectory(Paths.get(this.repo_dir, "ingest").toString());
|
|
||||||
IOUtils.createDirectory(Paths.get(this.repo_dir, "archive").toString());
|
|
||||||
IOUtils.createDirectory(Paths.get(this.repo_dir, "output").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
20
src/main/resources/log4j2.xml
Normal file
20
src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="info" name="Dragoon" packages="">
|
||||||
|
<Appenders>
|
||||||
|
<File name="DragoonLog" fileName="logs/dragoon.log">
|
||||||
|
<PatternLayout>
|
||||||
|
<Pattern>%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Pattern>
|
||||||
|
</PatternLayout>
|
||||||
|
</File>
|
||||||
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
|
<PatternLayout
|
||||||
|
pattern="%highlight{%d [%t] %-5level: %msg%n%throwable}" />
|
||||||
|
</Console>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Root level="info">
|
||||||
|
<AppenderRef ref="DragoonLog"/>
|
||||||
|
<AppenderRef ref="Console"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
36
src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Normal file
36
src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package tech.bitgoblin.io;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class IOUtilsTest {
|
||||||
|
|
||||||
|
private static String testDir = "test-temp";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCreateDirectory() {
|
||||||
|
IOUtils.createDirectory(testDir);
|
||||||
|
assertTrue(new File(testDir).exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldExpandTilda() {
|
||||||
|
String homeExpanded = IOUtils.resolveTilda("~");
|
||||||
|
assertTrue(!homeExpanded.equals("~"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=UnsupportedOperationException.class)
|
||||||
|
public void shouldFailExpandExplicitTilda() {
|
||||||
|
IOUtils.resolveTilda("~test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanup() {
|
||||||
|
new File(testDir).delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user