forked from j62/ctbrec
1
0
Fork 0

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:
0xboobface 2020-05-02 12:45:15 +02:00
parent f285d2ba53
commit df50646627
1 changed files with 13 additions and 20 deletions

View File

@ -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();
}
}