Skip to content

Commit 9d82ff2

Browse files
committed
chore: Deprecate setStartOffset and move readAtNativeFrameRate
1 parent 6b82e50 commit 9d82ff2

File tree

5 files changed

+175
-3
lines changed

5 files changed

+175
-3
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
public abstract class AbstractFFmpegInputBuilder<T extends AbstractFFmpegInputBuilder<T>> extends AbstractFFmpegStreamBuilder<T> {
1111
private final FFmpegProbeResult probeResult;
1212

13+
private boolean readAtNativeFrameRate;
14+
1315
public AbstractFFmpegInputBuilder() {
1416
this(null, null);
1517
}
@@ -25,6 +27,11 @@ public AbstractFFmpegInputBuilder(FFmpegBuilder parent, FFmpegProbeResult probeR
2527
this.probeResult = probeResult;
2628
}
2729

30+
public T readAtNativeFrameRate() {
31+
this.readAtNativeFrameRate = true;
32+
return getThis();
33+
}
34+
2835
public FFmpegProbeResult getProbeResult() {
2936
return probeResult;
3037
}
@@ -54,5 +61,14 @@ protected List<String> build(FFmpegBuilder parent, int pass) {
5461
return args.build();
5562
}
5663

64+
@Override
65+
protected void addGlobalFlags(FFmpegBuilder parent, ImmutableList.Builder<String> args) {
66+
if (this.readAtNativeFrameRate) {
67+
args.add("-re");
68+
}
69+
70+
super.addGlobalFlags(parent, args);
71+
}
72+
5773
protected abstract List<String> buildInputString();
5874
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ public FFmpegBuilder setUserAgent(String userAgent) {
125125
return this;
126126
}
127127

128+
/**
129+
* Makes ffmpeg read the first input at the native frame read
130+
* @return this
131+
* @deprecated Use {@link AbstractFFmpegInputBuilder#readAtNativeFrameRate()} instead
132+
*/
133+
@Deprecated
128134
public FFmpegBuilder readAtNativeFrameRate() {
129135
this.read_at_native_frame_rate = true;
130136
return this;
@@ -184,12 +190,26 @@ public FFmpegBuilder setThreads(int threads) {
184190
return this;
185191
}
186192

193+
/**
194+
* Sets the format for the first input stream
195+
* @param format
196+
* @return this
197+
* @deprecated Specify this option on an input stream using {@link AbstractFFmpegStreamBuilder#setFormat(String)}
198+
*/
187199
@Deprecated
188200
public FFmpegBuilder setFormat(String format) {
189201
this.format = checkNotNull(format);
190202
return this;
191203
}
192204

205+
/**
206+
* Sets the start offset for the first input stream
207+
* @param duration
208+
* @param units
209+
* @return this
210+
* @deprecated Specify this option on an input or output stream using {@link AbstractFFmpegStreamBuilder#setStartOffset(long, TimeUnit)}
211+
*/
212+
@Deprecated
193213
public FFmpegBuilder setStartOffset(long duration, TimeUnit units) {
194214
checkNotNull(units);
195215

@@ -208,6 +228,7 @@ public FFmpegBuilder addProgress(URI uri) {
208228
*
209229
* @param filter the complex filter string
210230
* @return this
231+
* @deprecated Use {@link AbstractFFmpegOutputBuilder#setComplexFilter(String)} instead
211232
*/
212233
@Deprecated
213234
public FFmpegBuilder setComplexFilter(String filter) {
@@ -353,6 +374,7 @@ public List<String> build() {
353374
}
354375

355376
if (startOffset != null) {
377+
log.warn("Using FFmpegBuilder#setStartOffset is deprecated. Specify it on the inputStream or outputStream instead");
356378
args.add("-ss", FFmpegUtils.toTimecode(startOffset, TimeUnit.MILLISECONDS));
357379
}
358380

@@ -366,6 +388,7 @@ public List<String> build() {
366388
}
367389

368390
if (read_at_native_frame_rate) {
391+
log.warn("Using FFmpegBuilder#readAtNativeFrameRate is deprecated. Specify it on the inputStream instead");
369392
args.add("-re");
370393
}
371394

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public void testExample1() throws IOException {
4545
new FFmpegBuilder()
4646
.addExtraArgs("-rtbufsize", "1500M")
4747
.addExtraArgs("-re")
48-
.setFormat("dshow")
4948
.setInput(
5049
"video=\"Microsoft Camera Rear\":audio=\"Microphone Array (Realtek High Definition Audio(SST))\"")
50+
.setFormat("dshow")
5151
.done()
5252
.addOutput("rtmp://a.rtmp.youtube.com/live2/1234-5678")
5353
.setFormat("flv")
@@ -69,7 +69,7 @@ public void testExample1() throws IOException {
6969

7070
String expected =
7171
"ffmpeg\\win64\\bin\\ffmpeg.exe -y -v error"
72-
+ " -f dshow -rtbufsize 1500M -re"
72+
+ " -rtbufsize 1500M -re -f dshow"
7373
+ " -i video=\"Microsoft Camera Rear\":audio=\"Microphone Array (Realtek High Definition Audio(SST))\""
7474
+ " -f flv"
7575
+ " -vcodec libx264 -pix_fmt yuv420p -s 426x240 -r 30/1 -b:v 2000000"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ public void testProgress() throws InterruptedException, ExecutionException, IOEx
220220

221221
FFmpegBuilder builder =
222222
new FFmpegBuilder()
223-
.readAtNativeFrameRate() // Slows the test down
224223
.setInput(in)
224+
.readAtNativeFrameRate() // Slows the test down
225225
.done()
226226
.overrideOutputFiles(true)
227227
.addOutput(Samples.output_mp4)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package net.bramp.ffmpeg;
2+
3+
import com.google.common.collect.ImmutableList;
4+
import net.bramp.ffmpeg.builder.FFmpegBuilder;
5+
import net.bramp.ffmpeg.lang.NewProcessAnswer;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
import org.mockito.Mock;
10+
import org.mockito.junit.MockitoJUnitRunner;
11+
12+
import java.io.IOException;
13+
import java.util.List;
14+
import java.util.concurrent.TimeUnit;
15+
16+
import static net.bramp.ffmpeg.FFmpegTest.argThatHasItem;
17+
import static org.hamcrest.MatcherAssert.assertThat;
18+
import static org.hamcrest.core.Is.is;
19+
import static org.mockito.Mockito.when;
20+
21+
@RunWith(MockitoJUnitRunner.class)
22+
public class InputOutputTest {
23+
@Mock
24+
ProcessFunction runFunc;
25+
26+
FFmpeg ffmpeg;
27+
28+
@Before
29+
public void before() throws IOException {
30+
when(runFunc.run(argThatHasItem("-version")))
31+
.thenAnswer(new NewProcessAnswer("avconv-version"));
32+
33+
ffmpeg = new FFmpeg(runFunc);
34+
}
35+
36+
@Test
37+
public void setInputFormat() {
38+
List<String> command = new FFmpegBuilder()
39+
.addInput("input.mp4")
40+
.setFormat("mp4")
41+
.done()
42+
.addOutput("output.mp4")
43+
.done()
44+
.build();
45+
46+
assertThat(command, is(ImmutableList.of("-y", "-v", "error", "-f", "mp4", "-i", "input.mp4", "output.mp4")));
47+
}
48+
49+
@Test
50+
public void setInputFormatMultiple() {
51+
List<String> command = new FFmpegBuilder()
52+
.addInput("input.mp4")
53+
.setFormat("mp4")
54+
.done()
55+
.addInput("input.mkv")
56+
.setFormat("matroschka")
57+
.done()
58+
.addOutput("output.mp4")
59+
.done()
60+
.build();
61+
62+
assertThat(command, is(ImmutableList.of("-y", "-v", "error", "-f", "mp4", "-i", "input.mp4", "-f", "matroschka", "-i", "input.mkv", "output.mp4")));
63+
}
64+
65+
@Test
66+
public void setStartOffsetOnInput() {
67+
List<String> command = new FFmpegBuilder()
68+
.addInput("input.mp4")
69+
.setStartOffset(10, TimeUnit.SECONDS)
70+
.done()
71+
.addOutput("output.mp4")
72+
.done()
73+
.build();
74+
75+
assertThat(command, is(ImmutableList.of("-y", "-v", "error", "-ss", "00:00:10", "-i", "input.mp4", "output.mp4")));
76+
}
77+
78+
@Test
79+
public void setStartOffsetOnOutput() {
80+
List<String> command = new FFmpegBuilder()
81+
.addInput("input.mp4")
82+
.done()
83+
.addOutput("output.mp4")
84+
.setStartOffset(10, TimeUnit.SECONDS)
85+
.done()
86+
.build();
87+
88+
assertThat(command, is(ImmutableList.of("-y", "-v", "error", "-i", "input.mp4", "-ss", "00:00:10", "output.mp4")));
89+
}
90+
91+
@Test
92+
public void setStartOffsetOnInputAndOutput() {
93+
List<String> command = new FFmpegBuilder()
94+
.addInput("input.mp4")
95+
.setStartOffset(1, TimeUnit.SECONDS)
96+
.done()
97+
.addOutput("output.mp4")
98+
.setStartOffset(10, TimeUnit.SECONDS)
99+
.done()
100+
.build();
101+
102+
assertThat(command, is(ImmutableList.of("-y", "-v", "error", "-ss", "00:00:01", "-i", "input.mp4", "-ss", "00:00:10", "output.mp4")));
103+
}
104+
105+
@Test
106+
public void readAtNativeFrameRate() {
107+
List<String> command = new FFmpegBuilder()
108+
.addInput("input.mp4")
109+
.readAtNativeFrameRate()
110+
.done()
111+
.addOutput("output.mp4")
112+
.done()
113+
.build();
114+
115+
assertThat(command, is(ImmutableList.of("-y", "-v", "error", "-re", "-i", "input.mp4", "output.mp4")));
116+
}
117+
118+
@Test
119+
public void readAtNativeFrameRateMultiple() {
120+
List<String> command = new FFmpegBuilder()
121+
.addInput("input.mp4")
122+
.readAtNativeFrameRate()
123+
.done()
124+
.addInput("input.mkv")
125+
.readAtNativeFrameRate()
126+
.done()
127+
.addOutput("output.mp4")
128+
.done()
129+
.build();
130+
131+
assertThat(command, is(ImmutableList.of("-y", "-v", "error", "-re", "-i", "input.mp4", "-re", "-i", "input.mkv", "output.mp4")));
132+
}
133+
}

0 commit comments

Comments
 (0)