Skip to content

Commit

Permalink
Added Tests for the Duration methods that weren't tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
Speiger committed Nov 5, 2024
1 parent b7dbdae commit 706d0c6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/test/java/com/github/kokorin/jaffree/ffmpeg/FFmpegTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,28 @@ public void testPosition() throws Exception {
assertEquals(inputDuration - 10, outputDuration, 0.5);
}

@Test
public void testDurationPositionNegative() throws Exception {
Path tempDir = Files.createTempDirectory("jaffree");
Path outputPath = tempDir.resolve(Artifacts.VIDEO_MP4.getFileName());

FFmpegResult result = FFmpeg.atPath(Config.FFMPEG_BIN)
.addInput(UrlInput
.fromPath(Artifacts.VIDEO_MP4)
.setPositionEof(Duration.ofSeconds(-7))
)
.addOutput(UrlOutput
.toPath(outputPath)
.copyAllCodecs())
.execute();

Assert.assertNotNull(result);

double outputDuration = getDuration(outputPath);

assertEquals(7.0, outputDuration, 0.5);
}

@Test
public void testPositionNegative() throws Exception {
Path tempDir = Files.createTempDirectory("jaffree");
Expand Down Expand Up @@ -797,6 +819,32 @@ public void testChannelInputPartialRead() throws IOException {
assertTrue(Files.exists(outputPath));
assertTrue(Files.size(outputPath) > 1000);
}

@Test
public void testChannelDurationInputSeek() throws IOException {
Path tempDir = Files.createTempDirectory("jaffree");
Path outputPath = tempDir.resolve("frame.jpg");

try (SeekableByteChannel channel = Files.newByteChannel(Artifacts.VIDEO_MP4, READ)) {
FFmpegResult result = FFmpeg.atPath(Config.FFMPEG_BIN)
.addInput(
new ChannelInput("testChannelInputSeek.mp4", channel)
.setPosition(Duration.ofMinutes(1L))
)
.addOutput(
UrlOutput.toPath(outputPath)
.setFrameCount(StreamType.VIDEO, 1L)
)
.setLogLevel(LogLevel.INFO)
.execute();

Assert.assertNotNull(result);
Assert.assertNotNull(result.getVideoSize());
}

assertTrue(Files.exists(outputPath));
assertTrue(Files.size(outputPath) > 1000);
}

@Test
public void testChannelInputSeek() throws IOException {
Expand Down

0 comments on commit 706d0c6

Please sign in to comment.