Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public String toString() {
URI progress;
String user_agent;

int threads;
// Input settings
String format;
Long startOffset; // in millis
Expand Down Expand Up @@ -150,7 +151,13 @@ public FFmpegBuilder setInput(String filename) {
return addInput(filename);
}

public FFmpegBuilder setFormat(String format) {
public FFmpegBuilder setThreads(int threads) {
checkArgument(threads != 0, "threads must be greater than zero");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check for >0

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Please make the change.

this.threads = threads;
return this;
}

public FFmpegBuilder setFormat(String format) {
this.format = checkNotNull(format);
return this;
}
Expand Down Expand Up @@ -289,6 +296,10 @@ public List<String> build() {
args.add("-ss", FFmpegUtils.toTimecode(startOffset, TimeUnit.MILLISECONDS));
}

if (threads > 0) {
args.add("-threads", String.valueOf(threads));
}

if (format != null) {
args.add("-f", format);
}
Expand Down
54 changes: 35 additions & 19 deletions src/test/java/net/bramp/ffmpeg/builder/FFmpegBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,39 @@ public void testAlternativeBuilderPattern() {
}

@Test
public void testPresets() {
List<String> args =
new FFmpegBuilder()
.addInput("input")
.addOutput("output")
.setPreset("a")
.setPresetFilename("b")
.setVideoPreset("c")
.setAudioPreset("d")
.setSubtitlePreset("e")
.done()
.build();

assertEquals(
args,
ImmutableList.of(
"-y", "-v", "error", "-i", "input", "-preset", "a", "-fpre", "b", "-vpre", "c", "-apre",
"d", "-spre", "e", "output"));
}
public void testPresets() {
List<String> args =
new FFmpegBuilder()
.addInput("input")
.addOutput("output")
.setPreset("a")
.setPresetFilename("b")
.setVideoPreset("c")
.setAudioPreset("d")
.setSubtitlePreset("e")
.done()
.build();

assertEquals(
args,
ImmutableList.of(
"-y", "-v", "error", "-i", "input", "-preset", "a", "-fpre", "b", "-vpre", "c", "-apre",
"d", "-spre", "e", "output"));
}

@Test
public void testThreads() {
List<String> args =
new FFmpegBuilder()
.setThreads(2)
.addInput("input")
.addOutput("output")
.done()
.build();

assertEquals(
args,
ImmutableList.of(
"-y", "-v", "error", "-threads", "2", "-i", "input", "output"));
}
}