Write the output of FFmpeg to a log file in the segment directory
This commit is contained in:
parent
2da3d64ac8
commit
a3dee454a5
|
@ -37,6 +37,7 @@ public class FfmpegMuxer {
|
|||
LOG.debug("Deleting merged video and audio tracks");
|
||||
Files.delete(mp4VideoTrack.toPath());
|
||||
Files.delete(mp4AudioTrack.toPath());
|
||||
Files.deleteIfExists(new File(segmentDir, "merge.log").toPath());
|
||||
LOG.debug("Deleting segments");
|
||||
deleteFiles(segmentDir, videoSegments);
|
||||
deleteFiles(segmentDir, audioSegments);
|
||||
|
@ -74,7 +75,9 @@ public class FfmpegMuxer {
|
|||
}
|
||||
|
||||
private int mergeTracks(File mp4VideoTrack, File mp4AudioTrack, File output) throws IOException {
|
||||
try {
|
||||
File dir = mp4VideoTrack.getParentFile();
|
||||
File mergeLog = new File(dir, "merge.log");
|
||||
try (FileOutputStream muxLogStream = new FileOutputStream(mergeLog)) {
|
||||
LOG.debug("Merging:\n{}\n{}\n{}", mp4VideoTrack, mp4AudioTrack, output);
|
||||
// @formatter:off
|
||||
String[] cmdline = OS.getFFmpegCommand(
|
||||
|
@ -82,14 +85,15 @@ public class FfmpegMuxer {
|
|||
"-i", mp4AudioTrack.getCanonicalPath(),
|
||||
"-c:v", "copy",
|
||||
"-c:a", "copy",
|
||||
"-movflags", "faststart",
|
||||
"-movflags", "faststart", // for streaming
|
||||
"-y", // overwrite existing files
|
||||
output.getCanonicalPath()
|
||||
);
|
||||
// @formatter:on
|
||||
LOG.debug("Command line: {}", Arrays.toString(cmdline));
|
||||
Process ffmpeg = Runtime.getRuntime().exec(cmdline);
|
||||
new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), System.out)).start(); // NOSONAR
|
||||
new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), System.err)).start(); // NOSONAR
|
||||
new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), muxLogStream)).start();
|
||||
new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), muxLogStream)).start();
|
||||
return ffmpeg.waitFor();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
|
|
|
@ -74,6 +74,7 @@ public class MergedHlsDownload extends HlsDownload {
|
|||
}
|
||||
|
||||
private void postprocess(File playlist, File target) {
|
||||
File mergeLog = new File(playlist.getParentFile(), "merge.log");
|
||||
try {
|
||||
File dir = playlist.getParentFile();
|
||||
// @formatter:off
|
||||
|
@ -81,18 +82,24 @@ public class MergedHlsDownload extends HlsDownload {
|
|||
"-i", playlist.getAbsolutePath(),
|
||||
"-c:v", "copy",
|
||||
"-c:a", "copy",
|
||||
"-movflags", "faststart",
|
||||
"-movflags", "faststart", // for streaming
|
||||
"-y", // overwrite existing files
|
||||
"-f", "mp4",
|
||||
target.getAbsolutePath()
|
||||
);
|
||||
// @formatter:on
|
||||
LOG.debug("Command line: {}", Arrays.toString(cmdline));
|
||||
Process ffmpeg = Runtime.getRuntime().exec(cmdline, new String[0], playlist.getParentFile());
|
||||
new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), System.out)).start(); // NOSONAR
|
||||
new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), System.err)).start(); // NOSONAR
|
||||
int exitCode = ffmpeg.waitFor();
|
||||
int exitCode = 1;
|
||||
try (FileOutputStream mergeLogStream = new FileOutputStream(mergeLog)) {
|
||||
new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), mergeLogStream)).start();
|
||||
new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), mergeLogStream)).start();
|
||||
exitCode = ffmpeg.waitFor();
|
||||
mergeLogStream.flush();
|
||||
}
|
||||
if (exitCode == 0) {
|
||||
Files.delete(playlist.toPath());
|
||||
Files.deleteIfExists(mergeLog.toPath());
|
||||
File[] segments = dir.listFiles((directory, filename) -> filename.endsWith(".ts") || filename.endsWith(".corrupt"));
|
||||
for (File segment : segments) {
|
||||
Files.delete(segment.toPath());
|
||||
|
|
Loading…
Reference in New Issue