Skip to content

Feature/345 add strict option on builder #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public abstract class AbstractFFmpegStreamBuilder<T extends AbstractFFmpegStream
public String presetFilename;
public final List<String> extra_args = new ArrayList<>();

public FFmpegBuilder.Strict strict = FFmpegBuilder.Strict.NORMAL;
public Strict strict = Strict.NORMAL;

public long targetSize = 0; // in bytes
public long pass_padding_bitrate = 1024; // in bits per second
Expand Down Expand Up @@ -455,7 +455,7 @@ public T setDuration(long duration, TimeUnit units) {
return getThis();
}

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

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

Expand Down
26 changes: 11 additions & 15 deletions src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ public class FFmpegBuilder {

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

public enum Strict {
VERY, // strictly conform to an older more strict version of the specifications or reference
// software
STRICT, // strictly conform to all the things in the specificiations no matter what consequences
NORMAL, // normal
UNOFFICIAL, // allow unofficial extensions
EXPERIMENTAL;

@Override
public String toString() {
// ffmpeg command line requires these options in lower case
return Ascii.toLowerCase(name());
}
}

/** Log level options: <a href="https://ffmpeg.org/ffmpeg.html#Generic-options">ffmpeg documentation</a> */
public enum Verbosity {
QUIET,
Expand Down Expand Up @@ -85,11 +70,18 @@ public String toString() {
// Output
final List<AbstractFFmpegOutputBuilder<?>> outputs = new ArrayList<>();

protected Strict strict = Strict.NORMAL;

// Filters
String audioFilter;
String videoFilter;
String complexFilter;

public FFmpegBuilder setStrict(Strict strict) {
this.strict = checkNotNull(strict);
return this;
}

public FFmpegBuilder overrideOutputFiles(boolean override) {
this.override = override;
return this;
Expand Down Expand Up @@ -366,6 +358,10 @@ public List<String> build() {
Preconditions.checkArgument(!inputs.isEmpty(), "At least one input must be specified");
Preconditions.checkArgument(!outputs.isEmpty(), "At least one output must be specified");

if (strict != Strict.NORMAL) {
args.add("-strict", strict.toString());
}

args.add(override ? "-y" : "-n");
args.add("-v", this.verbosity.toString());

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/bramp/ffmpeg/builder/Strict.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.bramp.ffmpeg.builder;

import com.google.common.base.Ascii;

public enum Strict {
VERY, // strictly conform to an older more strict version of the specifications or reference
// software
STRICT, // strictly conform to all the things in the specificiations no matter what consequences
NORMAL, // normal
UNOFFICIAL, // allow unofficial extensions
EXPERIMENTAL;

@Override
public String toString() {
// ffmpeg command line requires these options in lower case
return Ascii.toLowerCase(name());
}
}
5 changes: 3 additions & 2 deletions src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import net.bramp.ffmpeg.builder.FFmpegBuilder;
import net.bramp.ffmpeg.builder.Strict;
import net.bramp.ffmpeg.fixtures.Samples;
import net.bramp.ffmpeg.job.FFmpegJob;
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void testNormal() throws InterruptedException, ExecutionException, IOExce
// .setVideoPixelFormat("yuv420p")
// .setVideoBitStreamFilter("noise")
.setVideoQuality(2)
.setStrict(FFmpegBuilder.Strict.EXPERIMENTAL)
.setStrict(Strict.EXPERIMENTAL)
.done();

FFmpegJob job = ffExecutor.createJob(builder);
Expand Down Expand Up @@ -262,7 +263,7 @@ public void testIssue112() {
.setVideoCodec("libx264")
.setVideoFrameRate(24, 1)
.setVideoResolution(640, 480)
.setStrict(FFmpegBuilder.Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
.setStrict(Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
.done();

// Run a one-pass encode
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/net/bramp/ffmpeg/ReadmeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import net.bramp.ffmpeg.builder.FFmpegBuilder;
import net.bramp.ffmpeg.builder.Strict;
import net.bramp.ffmpeg.fixtures.Samples;
import net.bramp.ffmpeg.job.FFmpegJob;
import net.bramp.ffmpeg.probe.FFmpegFormat;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void testVideoEncoding() throws IOException {
.setVideoCodec("libx264") // Video using x264
.setVideoFrameRate(24, 1) // at 24 frames per second
.setVideoResolution(640, 480) // at 640x480 resolution
.setStrict(FFmpegBuilder.Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
.setStrict(Strict.EXPERIMENTAL) // Allow FFmpeg to use experimental specs
.done();

FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void testSetPresetFilename() {

@Test
public void testSetStrict() {
List<String> command = getBuilder().setStrict(FFmpegBuilder.Strict.STRICT).build(0);
List<String> command = getBuilder().setStrict(Strict.STRICT).build(0);

assertEquals("strict", command.get(command.indexOf("-strict") + 1));
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/net/bramp/ffmpeg/builder/FFmpegBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,17 @@ public void testQuestion156(){
args
);
}

@Test
public void testSetStrict() {
List<String> args = new FFmpegBuilder()
.addInput("input.mp4")
.done()
.addOutput("output.mp4")
.done()
.setStrict(Strict.EXPERIMENTAL)
.build();

assertEquals(ImmutableList.of("-strict", "experimental", "-y", "-v", "error", "-i", "input.mp4", "output.mp4"), args);
}
}
Loading