Add real FFmpeg scheduler integration test
This commit is contained in:
parent
f96d0689e1
commit
90cadbe097
|
|
@ -29,7 +29,7 @@ Note: the local machine's filesystem root is read-only in this workspace, so abs
|
|||
9. [x] Add success handling that moves processed source files to processed storage.
|
||||
10. [x] Add failure handling for FFmpeg or filesystem errors.
|
||||
11. [x] Add unit tests for ordering, invalid-file handling, repeat prevention, and state transitions.
|
||||
12. [ ] Add optional FFmpeg integration test for a short fixture.
|
||||
12. [x] Add optional FFmpeg integration test for a short fixture.
|
||||
13. [ ] Add local profile or documented runtime config for enabling the scheduler.
|
||||
14. [ ] Run verification and mark feature complete.
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package org.example.videoclips.folder;
|
||||
|
||||
import org.example.videoclips.config.VideoClippingProperties;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@EnabledIf("toolsAvailable")
|
||||
class FolderFfmpegIntegrationTest {
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void createsThreeEightSecondMp4ClipsFromSeventeenSecondVideo() throws Exception {
|
||||
Path source = tempDir.resolve("sample.mp4");
|
||||
run(List.of(
|
||||
"ffmpeg", "-hide_banner", "-loglevel", "error", "-y",
|
||||
"-f", "lavfi", "-i", "testsrc2=size=320x240:rate=24",
|
||||
"-f", "lavfi", "-i", "sine=frequency=1000:sample_rate=48000",
|
||||
"-t", "17",
|
||||
"-c:v", "libx264", "-pix_fmt", "yuv420p",
|
||||
"-c:a", "aac", "-shortest",
|
||||
source.toString()
|
||||
));
|
||||
VideoClippingProperties properties = new VideoClippingProperties();
|
||||
Path outputRoot = Files.createDirectory(tempDir.resolve("output"));
|
||||
properties.getFolderScheduler().setOutputDirectory(outputRoot.toString());
|
||||
|
||||
assertTrue(new FolderVideoValidator(properties).validate(source).valid());
|
||||
FolderFfmpegClipper.ClipResult result = new FolderFfmpegClipper(properties).clip(source);
|
||||
|
||||
assertEquals(outputRoot.resolve("sample"), result.outputDirectory());
|
||||
assertEquals(3, result.clipCount());
|
||||
assertTrue(Files.isRegularFile(result.outputDirectory().resolve("clip_00000.mp4")));
|
||||
assertTrue(Files.isRegularFile(result.outputDirectory().resolve("clip_00001.mp4")));
|
||||
assertTrue(Files.isRegularFile(result.outputDirectory().resolve("clip_00002.mp4")));
|
||||
}
|
||||
|
||||
static boolean toolsAvailable() {
|
||||
return commandAvailable("ffmpeg") && commandAvailable("ffprobe");
|
||||
}
|
||||
|
||||
private static boolean commandAvailable(String command) {
|
||||
try {
|
||||
return new ProcessBuilder(command, "-version").start().waitFor() == 0;
|
||||
} catch (IOException ex) {
|
||||
return false;
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void run(List<String> command) throws Exception {
|
||||
Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
|
||||
String output = new String(process.getInputStream().readAllBytes());
|
||||
assertEquals(0, process.waitFor(), output);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue