forked from j62/ctbrec
Change FFmpeg termination handling again
FFmpeg was killed to early, so that the file encoding was not finished properly. For example the moov atom was not written for MP4 files. We now wait at most 5 minutes for FFmpeg to finish and only kill it then with force.
This commit is contained in:
parent
f285d2ba53
commit
df50646627
|
@ -47,7 +47,6 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
private static final boolean IGNORE_CACHE = true;
|
||||
private ZonedDateTime splitRecStartTime;
|
||||
private File targetFile;
|
||||
private boolean downloadFinished = false;
|
||||
private transient Config config;
|
||||
private transient Process ffmpeg;
|
||||
private transient OutputStream ffmpegStdIn;
|
||||
|
@ -106,7 +105,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
downloadFinished = true;
|
||||
running = false;
|
||||
LOG.debug("Download for {} terminated", model);
|
||||
}
|
||||
}
|
||||
|
@ -343,21 +342,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
@Override
|
||||
public void stop() {
|
||||
if (running) {
|
||||
try {
|
||||
internalStop();
|
||||
int count = 0;
|
||||
while (!downloadFinished && count++ < 60) {
|
||||
LOG.debug("Waiting for download to finish {}", model);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
if (!downloadFinished) {
|
||||
LOG.warn("Download didn't finishe properly for model {}", model);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
LOG.error("Couldn't wait for download to finish", e);
|
||||
}
|
||||
LOG.debug("Download stopped");
|
||||
internalStop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -372,9 +357,17 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
LOG.error("Couldn't terminate FFmpeg by closing stdin", e);
|
||||
}
|
||||
}
|
||||
if (ffmpeg != null && ffmpeg.isAlive()) {
|
||||
ffmpeg.destroyForcibly();
|
||||
ffmpeg = null;
|
||||
|
||||
try {
|
||||
boolean waitFor = ffmpeg.waitFor(5, TimeUnit.MINUTES);
|
||||
if (!waitFor && ffmpeg.isAlive()) {
|
||||
LOG.info("FFmpeg didn't terminate. Destroying the process with force!");
|
||||
ffmpeg.destroyForcibly();
|
||||
ffmpeg = null;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error("Interrupted while waiting for FFmpeg to terminate");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue