Skip to content

Commit c3de044

Browse files
gogoadlbramp
authored andcommitted
fix/passlog-files-not-deleted (#361)
* fix/passlog-files-not-deleted + add getter (passDirectory, passlogPrefix) + add test + add get pass directory when delete passlog * fix testCode
1 parent dec2f7f commit c3de044

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,19 @@ public FFmpegBuilder setPassDirectory(String directory) {
104104
return this;
105105
}
106106

107+
public String getPassDirectory() {
108+
return this.pass_directory;
109+
}
110+
107111
public FFmpegBuilder setPassPrefix(String prefix) {
108112
this.pass_prefix = checkNotNull(prefix);
109113
return this;
110114
}
111115

116+
public String getPassPrefix() {
117+
return this.pass_prefix;
118+
}
119+
112120
public FFmpegBuilder setVerbosity(Verbosity verbosity) {
113121
checkNotNull(verbosity);
114122
this.verbosity = verbosity;

src/main/java/net/bramp/ffmpeg/job/TwoPassFFmpegJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public TwoPassFFmpegJob(
4040
}
4141

4242
protected void deletePassLog() throws IOException {
43-
final Path cwd = Paths.get("");
43+
final Path cwd = Paths.get(builder.getPassDirectory());
4444
try (DirectoryStream<Path> stream = Files.newDirectoryStream(cwd, passlogPrefix + "*.log*")) {
4545
for (Path p : stream) {
4646
Files.deleteIfExists(p);

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.google.common.io.ByteStreams;
1313
import com.google.common.io.CountingOutputStream;
1414
import com.google.common.net.HostAndPort;
15+
16+
import java.io.File;
1517
import java.io.IOException;
1618
import java.util.List;
1719
import java.util.concurrent.ExecutionException;
@@ -268,6 +270,43 @@ public void testIssue112() {
268270
ffExecutor.createJob(builder).run();
269271
}
270272

273+
274+
@Test
275+
public void testIssue287() throws InterruptedException, ExecutionException, IOException {
276+
FFmpegProbeResult in = ffprobe.probe(Samples.big_buck_bunny_720p_1mb);
277+
assertFalse(in.hasError());
278+
279+
String tempDir = System.getProperty("java.io.tmpdir");
280+
281+
FFmpegBuilder builder =
282+
new FFmpegBuilder()
283+
.setInput(in)
284+
.done()
285+
.overrideOutputFiles(true)
286+
.addOutput(Samples.output_mp4)
287+
.setFormat("mp4")
288+
.disableAudio()
289+
.setVideoCodec("mpeg4")
290+
.setVideoFrameRate(FFmpeg.FPS_30)
291+
.setVideoResolution(320, 240)
292+
.setTargetSize(1024 * 1024)
293+
.done().setPassDirectory(tempDir);
294+
295+
FFmpegJob job = ffExecutor.createTwoPassJob(builder);
296+
runAndWait(job);
297+
298+
assertEquals(FFmpegJob.State.FINISHED, job.getState());
299+
300+
File passDir = new File(builder.getPassDirectory());
301+
String passPrefix = builder.getPassPrefix();
302+
303+
File[] remainingFiles = passDir.listFiles((dir, name) ->
304+
name.startsWith(passPrefix) && name.contains(".log")
305+
);
306+
307+
assertEquals(true, remainingFiles == null || remainingFiles.length == 0);
308+
}
309+
271310
protected void runAndWait(FFmpegJob job) throws ExecutionException, InterruptedException {
272311
executor.submit(job).get();
273312
}

0 commit comments

Comments
 (0)