Wait for stdout and stderr log threads to finish

This commit is contained in:
0xboobface 2019-12-29 22:04:50 +01:00
parent b37178170b
commit 5ecad75b0d
3 changed files with 15 additions and 6 deletions

View File

@ -1,7 +1,7 @@
3.0.3 3.0.3
======================== ========================
* Fix: Recordings didn't start for some MFC models * Fix: Recordings didn't start for some MFC models
* Fix: In some cases a lot of recordings have been created, because a recording * Fix: In some cases a lot of recordings have been created, because they
failed immediately after start failed immediately after start
* Fix: Recorded models now don't switch their positions in the thumb overview * Fix: Recorded models now don't switch their positions in the thumb overview
* HLS downloads now try to update the segment playlist URL, if the playlist cannot * HLS downloads now try to update the segment playlist URL, if the playlist cannot

View File

@ -91,9 +91,14 @@ public class FfmpegMuxer {
// @formatter:on // @formatter:on
LOG.debug("Command line: {}", Arrays.toString(cmdline)); LOG.debug("Command line: {}", Arrays.toString(cmdline));
Process ffmpeg = Runtime.getRuntime().exec(cmdline); Process ffmpeg = Runtime.getRuntime().exec(cmdline);
new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), muxLogStream)).start(); Thread stdout = new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), muxLogStream));
new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), muxLogStream)).start(); Thread stderr = new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), muxLogStream));
return ffmpeg.waitFor(); stdout.start();
stderr.start();
int exitCode = ffmpeg.waitFor();
stdout.join();
stderr.join();
return exitCode;
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
LOG.error("Interrupted while waiting for FFMPEG", e); LOG.error("Interrupted while waiting for FFMPEG", e);

View File

@ -93,9 +93,13 @@ public class MergedHlsDownload extends HlsDownload {
Process ffmpeg = Runtime.getRuntime().exec(cmdline, new String[0], playlist.getParentFile()); Process ffmpeg = Runtime.getRuntime().exec(cmdline, new String[0], playlist.getParentFile());
int exitCode = 1; int exitCode = 1;
try (FileOutputStream mergeLogStream = new FileOutputStream(mergeLog)) { try (FileOutputStream mergeLogStream = new FileOutputStream(mergeLog)) {
new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), mergeLogStream)).start(); Thread stdout = new Thread(new StreamRedirectThread(ffmpeg.getInputStream(), mergeLogStream));
new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), mergeLogStream)).start(); Thread stderr = new Thread(new StreamRedirectThread(ffmpeg.getErrorStream(), mergeLogStream));
stdout.start();
stderr.start();
exitCode = ffmpeg.waitFor(); exitCode = ffmpeg.waitFor();
stdout.join();
stderr.join();
mergeLogStream.flush(); mergeLogStream.flush();
} }
if (exitCode == 0) { if (exitCode == 0) {