Skip to content

Commit bfb63a3

Browse files
authored
Feature/345 add strict option on builder (#352)
* feat(builder): Extract Strict enum into it's own class * feat: Add setStrict to FFmpegBuilder Fixes: #345
1 parent 4506377 commit bfb63a3

File tree

7 files changed

+51
-22
lines changed

7 files changed

+51
-22
lines changed

src/main/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public abstract class AbstractFFmpegStreamBuilder<T extends AbstractFFmpegStream
9696
public String presetFilename;
9797
public final List<String> extra_args = new ArrayList<>();
9898

99-
public FFmpegBuilder.Strict strict = FFmpegBuilder.Strict.NORMAL;
99+
public Strict strict = Strict.NORMAL;
100100

101101
public long targetSize = 0; // in bytes
102102
public long pass_padding_bitrate = 1024; // in bits per second
@@ -455,7 +455,7 @@ public T setDuration(long duration, TimeUnit units) {
455455
return getThis();
456456
}
457457

458-
public T setStrict(FFmpegBuilder.Strict strict) {
458+
public T setStrict(Strict strict) {
459459
this.strict = checkNotNull(strict);
460460
return getThis();
461461
}
@@ -592,7 +592,7 @@ protected List<String> build(FFmpegBuilder parent, int pass) {
592592
protected abstract void addSourceTarget(int pass, ImmutableList.Builder<String> args);
593593

594594
protected void addGlobalFlags(FFmpegBuilder parent, ImmutableList.Builder<String> args) {
595-
if (strict != FFmpegBuilder.Strict.NORMAL) {
595+
if (strict != Strict.NORMAL) {
596596
args.add("-strict", strict.toString());
597597
}
598598

src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ public class FFmpegBuilder {
2929

3030
private static final Logger log = LoggerFactory.getLogger(FFmpegBuilder.class);
3131

32-
public enum Strict {
33-
VERY, // strictly conform to an older more strict version of the specifications or reference
34-
// software
35-
STRICT, // strictly conform to all the things in the specificiations no matter what consequences
36-
NORMAL, // normal
37-
UNOFFICIAL, // allow unofficial extensions
38-
EXPERIMENTAL;
39-
40-
@Override
41-
public String toString() {
42-
// ffmpeg command line requires these options in lower case
43-
return Ascii.toLowerCase(name());
44-
}
45-
}
46-
4732
/** Log level options: <a href="https://ffmpeg.org/ffmpeg.html#Generic-options">ffmpeg documentation</a> */
4833
public enum Verbosity {
4934
QUIET,
@@ -85,11 +70,18 @@ public String toString() {
8570
// Output
8671
final List<AbstractFFmpegOutputBuilder<?>> outputs = new ArrayList<>();
8772

73+
protected Strict strict = Strict.NORMAL;
74+
8875
// Filters
8976
String audioFilter;
9077
String videoFilter;
9178
String complexFilter;
9279

80+
public FFmpegBuilder setStrict(Strict strict) {
81+
this.strict = checkNotNull(strict);
82+
return this;
83+
}
84+
9385
public FFmpegBuilder overrideOutputFiles(boolean override) {
9486
this.override = override;
9587
return this;
@@ -366,6 +358,10 @@ public List<String> build() {
366358
Preconditions.checkArgument(!inputs.isEmpty(), "At least one input must be specified");
367359
Preconditions.checkArgument(!outputs.isEmpty(), "At least one output must be specified");
368360

361+
if (strict != Strict.NORMAL) {
362+
args.add("-strict", strict.toString());
363+
}
364+
369365
args.add(override ? "-y" : "-n");
370366
args.add("-v", this.verbosity.toString());
371367

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.bramp.ffmpeg.builder;
2+
3+
import com.google.common.base.Ascii;
4+
5+
public enum Strict {
6+
VERY, // strictly conform to an older more strict version of the specifications or reference
7+
// software
8+
STRICT, // strictly conform to all the things in the specificiations no matter what consequences
9+
NORMAL, // normal
10+
UNOFFICIAL, // allow unofficial extensions
11+
EXPERIMENTAL;
12+
13+
@Override
14+
public String toString() {
15+
// ffmpeg command line requires these options in lower case
16+
return Ascii.toLowerCase(name());
17+
}
18+
}

src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.concurrent.Executors;
2020
import java.util.concurrent.TimeUnit;
2121
import net.bramp.ffmpeg.builder.FFmpegBuilder;
22+
import net.bramp.ffmpeg.builder.Strict;
2223
import net.bramp.ffmpeg.fixtures.Samples;
2324
import net.bramp.ffmpeg.job.FFmpegJob;
2425
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
@@ -105,7 +106,7 @@ public void testNormal() throws InterruptedException, ExecutionException, IOExce
105106
// .setVideoPixelFormat("yuv420p")
106107
// .setVideoBitStreamFilter("noise")
107108
.setVideoQuality(2)
108-
.setStrict(FFmpegBuilder.Strict.EXPERIMENTAL)
109+
.setStrict(Strict.EXPERIMENTAL)
109110
.done();
110111

111112
FFmpegJob job = ffExecutor.createJob(builder);
@@ -262,7 +263,7 @@ public void testIssue112() {
262263
.setVideoCodec("libx264")
263264
.setVideoFrameRate(24, 1)
264265
.setVideoResolution(640, 480)
265-
.setStrict(FFmpegBuilder.Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
266+
.setStrict(Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
266267
.done();
267268

268269
// Run a one-pass encode

src/test/java/net/bramp/ffmpeg/ReadmeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Locale;
99
import java.util.concurrent.TimeUnit;
1010
import net.bramp.ffmpeg.builder.FFmpegBuilder;
11+
import net.bramp.ffmpeg.builder.Strict;
1112
import net.bramp.ffmpeg.fixtures.Samples;
1213
import net.bramp.ffmpeg.job.FFmpegJob;
1314
import net.bramp.ffmpeg.probe.FFmpegFormat;
@@ -59,7 +60,7 @@ public void testVideoEncoding() throws IOException {
5960
.setVideoCodec("libx264") // Video using x264
6061
.setVideoFrameRate(24, 1) // at 24 frames per second
6162
.setVideoResolution(640, 480) // at 640x480 resolution
62-
.setStrict(FFmpegBuilder.Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
63+
.setStrict(Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
6364
.done();
6465

6566
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);

src/test/java/net/bramp/ffmpeg/builder/AbstractFFmpegStreamBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public void testSetPresetFilename() {
214214

215215
@Test
216216
public void testSetStrict() {
217-
List<String> command = getBuilder().setStrict(FFmpegBuilder.Strict.STRICT).build(0);
217+
List<String> command = getBuilder().setStrict(Strict.STRICT).build(0);
218218

219219
assertEquals("strict", command.get(command.indexOf("-strict") + 1));
220220
}

src/test/java/net/bramp/ffmpeg/builder/FFmpegBuilderTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,4 +585,17 @@ public void testQuestion156(){
585585
args
586586
);
587587
}
588+
589+
@Test
590+
public void testSetStrict() {
591+
List<String> args = new FFmpegBuilder()
592+
.addInput("input.mp4")
593+
.done()
594+
.addOutput("output.mp4")
595+
.done()
596+
.setStrict(Strict.EXPERIMENTAL)
597+
.build();
598+
599+
assertEquals(ImmutableList.of("-strict", "experimental", "-y", "-v", "error", "-i", "input.mp4", "output.mp4"), args);
600+
}
588601
}

0 commit comments

Comments
 (0)