Skip to content

Commit

Permalink
test: Add tests regarding duration strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Euklios committed Aug 11, 2024
1 parent 8f396ef commit cbbeeac
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/java/net/bramp/ffmpeg/FFmpegTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.google.common.collect.Lists;
import net.bramp.ffmpeg.builder.FFmpegBuilder;
import net.bramp.ffmpeg.fixtures.Codecs;
import net.bramp.ffmpeg.fixtures.Filters;
import net.bramp.ffmpeg.fixtures.Formats;
import net.bramp.ffmpeg.fixtures.ChannelLayouts;
import net.bramp.ffmpeg.fixtures.PixelFormats;
import net.bramp.ffmpeg.fixtures.Samples;
import net.bramp.ffmpeg.info.Filter;
import net.bramp.ffmpeg.lang.NewProcessAnswer;
import org.junit.Before;
Expand Down Expand Up @@ -61,6 +65,32 @@ public void testVersion() throws Exception {
verify(runFunc, times(1)).run(argThatHasItem("-version"));
}

@Test
public void testStartOffsetOption() throws Exception {
FFmpeg ffmpeg = new FFmpeg();

FFmpegBuilder builder = ffmpeg.builder().addInput(Samples.big_buck_bunny_720p_1mb).setStartOffset(1, TimeUnit.SECONDS).done().addOutput(Samples.output_mp4).done();

try {
ffmpeg.run(builder);
} catch (Throwable t) {
fail(t.getClass().getSimpleName() + " was thrown");
}
}

@Test
public void testDurationOption() throws Exception {
FFmpeg ffmpeg = new FFmpeg();

FFmpegBuilder builder = ffmpeg.builder().addInput(Samples.big_buck_bunny_720p_1mb).setDuration(1, TimeUnit.SECONDS).done().addOutput(Samples.output_mp4).done();

try {
ffmpeg.run(builder);
} catch (Throwable t) {
fail(t.getClass().getSimpleName() + " was thrown");
}
}

@Test
public void testCodecs() throws IOException {
// Run twice, the second should be cached
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,54 @@ public void testConvertVideoToHls() throws IOException {
assertTrue(Files.exists(segmentFilePath));
}

@Test
public void testConvertVideoToHlsSetHlsTime() throws IOException {
Path manifestFilePath = Paths.get("tmp/output.m3u8");
Path segmentFilePath = Paths.get("tmp/file000.ts");

Files.createDirectories(Paths.get("tmp/"));
Files.deleteIfExists(manifestFilePath);
Files.deleteIfExists(segmentFilePath);

List<String> command = new FFmpegBuilder()
.setInput(Samples.TEST_PREFIX + Samples.base_big_buck_bunny_720p_1mb)
.done()
.addHlsOutput("tmp/output.m3u8")
.setHlsTime(5, TimeUnit.SECONDS)
.setHlsSegmentFileName("tmp/file%03d.ts")
.done()
.build();

new FFmpeg().run(command);

assertTrue(Files.exists(manifestFilePath));
assertTrue(Files.exists(segmentFilePath));
}

@Test
public void testConvertVideoToHlsSetHlsInitTime() throws IOException {
Path manifestFilePath = Paths.get("tmp/output.m3u8");
Path segmentFilePath = Paths.get("tmp/file000.ts");

Files.createDirectories(Paths.get("tmp/"));
Files.deleteIfExists(manifestFilePath);
Files.deleteIfExists(segmentFilePath);

List<String> command = new FFmpegBuilder()
.setInput(Samples.TEST_PREFIX + Samples.base_big_buck_bunny_720p_1mb)
.done()
.addHlsOutput("tmp/output.m3u8")
.setHlsInitTime(5, TimeUnit.SECONDS)
.setHlsSegmentFileName("tmp/file%03d.ts")
.done()
.build();

new FFmpeg().run(command);

assertTrue(Files.exists(manifestFilePath));
assertTrue(Files.exists(segmentFilePath));
}

@Test
public void testHlsTime() {
List<String> command = new FFmpegHlsOutputBuilder(new FFmpegBuilder(), "output.m3u8")
Expand Down

0 comments on commit cbbeeac

Please sign in to comment.