Skip to content

Commit 6b82e50

Browse files
committed
chore: Move setFormat and setComplexFilter to the corresponding stream builders
1 parent 3e43e13 commit 6b82e50

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public abstract class AbstractFFmpegOutputBuilder<T extends AbstractFFmpegOutput
6767
@Deprecated
6868
public String video_bit_stream_filter;
6969

70+
protected String complexFilter;
71+
7072
public AbstractFFmpegOutputBuilder() {
7173
super();
7274
}
@@ -194,6 +196,12 @@ public T setAudioBitStreamFilter(String filter) {
194196
return (T) this;
195197
}
196198

199+
public T setComplexFilter(String filter) {
200+
this.complexFilter = checkNotEmpty(filter, "filter must not be empty");
201+
202+
return (T) this;
203+
}
204+
197205
/**
198206
* Sets Audio Filter
199207
*
@@ -316,6 +324,10 @@ protected void addGlobalFlags(FFmpegBuilder parent, ImmutableList.Builder<String
316324
if (constantRateFactor != null) {
317325
args.add("-crf", formatDecimalInteger(constantRateFactor));
318326
}
327+
328+
if (complexFilter != null) {
329+
args.add("-filter_complex", complexFilter);
330+
}
319331
}
320332

321333
@Override
@@ -431,4 +443,8 @@ public String getVideoFilter() {
431443
public String getVideoBitStreamFilter() {
432444
return video_bit_stream_filter;
433445
}
446+
447+
public String getComplexFilter() {
448+
return complexFilter;
449+
}
434450
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import javax.annotation.CheckReturnValue;
1818
import net.bramp.ffmpeg.FFmpegUtils;
1919
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
2022

2123
/**
2224
* Builds a ffmpeg command line
@@ -25,6 +27,8 @@
2527
*/
2628
public class FFmpegBuilder {
2729

30+
private static final Logger log = LoggerFactory.getLogger(FFmpegBuilder.class);
31+
2832
public enum Strict {
2933
VERY, // strictly conform to an older more strict version of the specifications or reference
3034
// software
@@ -180,6 +184,7 @@ public FFmpegBuilder setThreads(int threads) {
180184
return this;
181185
}
182186

187+
@Deprecated
183188
public FFmpegBuilder setFormat(String format) {
184189
this.format = checkNotNull(format);
185190
return this;
@@ -204,6 +209,7 @@ public FFmpegBuilder addProgress(URI uri) {
204209
* @param filter the complex filter string
205210
* @return this
206211
*/
212+
@Deprecated
207213
public FFmpegBuilder setComplexFilter(String filter) {
208214
this.complexFilter = checkNotEmpty(filter, "filter must not be empty");
209215
return this;
@@ -355,6 +361,7 @@ public List<String> build() {
355361
}
356362

357363
if (format != null) {
364+
log.warn("Using FFmpegBuilder#setFormat is deprecated. Specify it on the inputStream or outputStream instead");
358365
args.add("-f", format);
359366
}
360367

@@ -389,6 +396,7 @@ public List<String> build() {
389396
}
390397

391398
if (!Strings.isNullOrEmpty(complexFilter)) {
399+
log.warn("Using FFmpegBuilder#setComplexFilter is deprecated. Specify it on the outputStream instead");
392400
args.add("-filter_complex", complexFilter);
393401
}
394402

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ public void testExample7() throws IOException {
189189
.done()
190190
.addInput("spot.mp4")
191191
.done()
192-
.setComplexFilter(
193-
"[1:v]scale=368:207,setpts=PTS-STARTPTS+5/TB [ov]; "
194-
+ "[0:v][ov] overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2:enable='between(t,5,15)' [v]")
195192
.addOutput("with-video.mp4")
193+
.setComplexFilter(
194+
"[1:v]scale=368:207,setpts=PTS-STARTPTS+5/TB [ov]; "
195+
+ "[0:v][ov] overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2:enable='between(t,5,15)' [v]")
196196
.addExtraArgs("-map", "[v]")
197197
.addExtraArgs("-map", "0:a")
198198
.setVideoCodec("libx264")
@@ -206,9 +206,9 @@ public void testExample7() throws IOException {
206206
"ffmpeg -y -v error"
207207
+ " -i original.mp4"
208208
+ " -i spot.mp4"
209-
+ " -filter_complex [1:v]scale=368:207,setpts=PTS-STARTPTS+5/TB [ov]; [0:v][ov] overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2:enable='between(t,5,15)' [v]"
210209
+ " -preset ultrafast"
211210
+ " -crf 20"
211+
+ " -filter_complex [1:v]scale=368:207,setpts=PTS-STARTPTS+5/TB [ov]; [0:v][ov] overlay=x=(main_w-overlay_w)/2:y=(main_h-overlay_h)/2:enable='between(t,5,15)' [v]"
212212
+ " -vcodec libx264"
213213
+ " -acodec copy"
214214
+ " -map [v]"

0 commit comments

Comments
 (0)