forked from j62/ctbrec
1
0
Fork 0

Fix possible NPE

This commit is contained in:
0xboobface 2020-01-03 21:53:37 +01:00
parent b2138ca99b
commit 5448763b9d
1 changed files with 10 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,9 +23,16 @@ public class FfmpegMuxer {
public FfmpegMuxer(File segmentDir, File targetFile) throws IOException {
this.segmentDir = segmentDir;
String[] videoSegments = segmentDir.list((dir, name) -> name.startsWith("video_"));
if (!segmentDir.exists()) {
throw new IOException("Directory does not exist " + segmentDir);
}
if (!segmentDir.isDirectory()) {
throw new IOException(segmentDir + " is not a directory");
}
String[] videoSegments = Optional.ofNullable(segmentDir.list((dir, name) -> name.startsWith("video_"))).orElse(new String[0]);
Arrays.sort(videoSegments);
String[] audioSegments = segmentDir.list((dir, name) -> name.startsWith("audio_"));
String[] audioSegments = Optional.ofNullable(segmentDir.list((dir, name) -> name.startsWith("audio_"))).orElse(new String[0]);
Arrays.sort(audioSegments);
File mp4VideoTrack = new File(segmentDir, "video.mp4");