How to release resources
hnuuhc opened this issue · 1 comments
hnuuhc commented
Code:
public static boolean audioVideoMerge(@NotNull String audio, @NotNull String video, @NotNull String output) {
boolean success = false;
try (FileOutputStream fos = new FileOutputStream(output);
DataSource videoDataSource = new FileDataSourceImpl(video);
DataSource audioDataSource = new FileDataSourceImpl(audio)) {
Movie countVideo = MovieCreator.build(videoDataSource);
MovieCreator.build(audioDataSource).getTracks().forEach(countVideo::addTrack);
Container out = new FragmentedMp4Builder().build(countVideo);
out.writeContainer(fos.getChannel());
success = true;
} catch (Exception e) {
e.printStackTrace();
}
new File(audio).delete();
new File(video).delete();
return success;
}
Result:
audio file exists
video file exists
Is this a bug?
Must use System.gc() and wait time to delete.
tiro8183 commented
I had the same problem