From 46523ab36a960990f4dbcf4f7e432e17f5e53b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=9A=B0?= Date: Sat, 3 May 2025 15:09:46 +0900 Subject: [PATCH 1/2] fix/passlog-files-not-deleted + add getter (passDirectory, passlogPrefix) + add test + add get pass directory when delete passlog --- .../bramp/ffmpeg/builder/FFmpegBuilder.java | 8 ++++ .../bramp/ffmpeg/job/TwoPassFFmpegJob.java | 2 +- .../net/bramp/ffmpeg/FFmpegExecutorTest.java | 41 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java b/src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java index e2ab9225..3c40f784 100644 --- a/src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java +++ b/src/main/java/net/bramp/ffmpeg/builder/FFmpegBuilder.java @@ -101,11 +101,19 @@ public FFmpegBuilder setPassDirectory(String directory) { return this; } + public String getPassDirectory() { + return this.pass_directory; + } + public FFmpegBuilder setPassPrefix(String prefix) { this.pass_prefix = checkNotNull(prefix); return this; } + public String getPassPrefix() { + return this.pass_prefix; + } + public FFmpegBuilder setVerbosity(Verbosity verbosity) { checkNotNull(verbosity); this.verbosity = verbosity; diff --git a/src/main/java/net/bramp/ffmpeg/job/TwoPassFFmpegJob.java b/src/main/java/net/bramp/ffmpeg/job/TwoPassFFmpegJob.java index 9b4c930e..200893d2 100644 --- a/src/main/java/net/bramp/ffmpeg/job/TwoPassFFmpegJob.java +++ b/src/main/java/net/bramp/ffmpeg/job/TwoPassFFmpegJob.java @@ -40,7 +40,7 @@ public TwoPassFFmpegJob( } protected void deletePassLog() throws IOException { - final Path cwd = Paths.get(""); + final Path cwd = Paths.get(builder.getPassDirectory()); try (DirectoryStream stream = Files.newDirectoryStream(cwd, passlogPrefix + "*.log*")) { for (Path p : stream) { Files.deleteIfExists(p); diff --git a/src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java b/src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java index fedd2501..5f625b61 100644 --- a/src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java +++ b/src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java @@ -12,6 +12,8 @@ import com.google.common.io.ByteStreams; import com.google.common.io.CountingOutputStream; import com.google.common.net.HostAndPort; + +import java.io.File; import java.io.IOException; import java.util.List; import java.util.concurrent.ExecutionException; @@ -270,6 +272,45 @@ public void testIssue112() { ffExecutor.createJob(builder).run(); } + + @Test + public void testIssue287() throws InterruptedException, ExecutionException, IOException { + FFmpegProbeResult in = ffprobe.probe(Samples.big_buck_bunny_720p_1mb); + assertFalse(in.hasError()); + + String tempDir = System.getProperty("java.io.tmpdir"); + + + FFmpegBuilder builder = + new FFmpegBuilder() + .setInput(in) + .done() + .overrideOutputFiles(true) + .addOutput(Samples.output_mp4) + .setFormat("mp4") + .disableAudio() + .setVideoCodec("mpeg4") + .setVideoFrameRate(FFmpeg.FPS_30) + .setVideoResolution(320, 240) + .setTargetSize(1024 * 1024) + .done().setPassDirectory(tempDir); + + FFmpegJob job = ffExecutor.createTwoPassJob(builder); + runAndWait(job); + + assertEquals(FFmpegJob.State.FINISHED, job.getState()); + + File passDir = new File(builder.getPassDirectory()); + String passPrefix = builder.getPassPrefix(); + + File[] remainingFiles = passDir.listFiles((dir, name) -> + name.startsWith(passPrefix) && name.contains(".log") + ); + + assertThat("Passlog files should be deleted", + remainingFiles == null || remainingFiles.length == 0, is(true)); + } + protected void runAndWait(FFmpegJob job) throws ExecutionException, InterruptedException { executor.submit(job).get(); } From 1584ca483d03716e32f9be1ee65e71a638ffe6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=9A=B0?= Date: Sat, 3 May 2025 16:15:02 +0900 Subject: [PATCH 2/2] fix testCode --- src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java b/src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java index 5f625b61..d97e850c 100644 --- a/src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java +++ b/src/test/java/net/bramp/ffmpeg/FFmpegExecutorTest.java @@ -280,7 +280,6 @@ public void testIssue287() throws InterruptedException, ExecutionException, IOEx String tempDir = System.getProperty("java.io.tmpdir"); - FFmpegBuilder builder = new FFmpegBuilder() .setInput(in) @@ -307,8 +306,7 @@ public void testIssue287() throws InterruptedException, ExecutionException, IOEx name.startsWith(passPrefix) && name.contains(".log") ); - assertThat("Passlog files should be deleted", - remainingFiles == null || remainingFiles.length == 0, is(true)); + assertEquals(true, remainingFiles == null || remainingFiles.length == 0); } protected void runAndWait(FFmpegJob job) throws ExecutionException, InterruptedException {