forked from j62/ctbrec
Use MergedFfmpegHlsDownload for merged HLS downloads
This commit is contained in:
parent
1e95872cb7
commit
4ebc847720
|
@ -11,8 +11,8 @@ import com.squareup.moshi.JsonReader;
|
|||
import com.squareup.moshi.JsonWriter;
|
||||
|
||||
import ctbrec.recorder.download.Download;
|
||||
import ctbrec.recorder.download.hls.FFmpegDownload;
|
||||
import ctbrec.recorder.download.hls.HlsDownload;
|
||||
import ctbrec.recorder.download.hls.MergedFfmpegHlsDownload;
|
||||
import ctbrec.sites.Site;
|
||||
|
||||
public abstract class AbstractModel implements Model {
|
||||
|
@ -233,7 +233,7 @@ public abstract class AbstractModel implements Model {
|
|||
if (Config.isServerMode()) {
|
||||
return new HlsDownload(getSite().getHttpClient());
|
||||
} else {
|
||||
return new FFmpegDownload(getSite().getHttpClient());
|
||||
return new MergedFfmpegHlsDownload(getSite().getHttpClient());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class StreamRedirectThread implements Runnable {
|
|||
}
|
||||
LOG.trace("Stream redirect thread ended");
|
||||
} catch(Exception e) {
|
||||
LOG.error("Couldn't redirect stream: {}", e.getLocalizedMessage());
|
||||
LOG.warn("Couldn't redirect stream: {}", e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,8 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
super.startTime = startTime;
|
||||
this.config = config;
|
||||
this.model = model;
|
||||
targetFile = Config.getInstance().getFileForRecording(model, "mp4", startTime);
|
||||
String fileSuffix = config.getSettings().ffmpegFileSuffix;
|
||||
targetFile = config.getFileForRecording(model, fileSuffix, startTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,11 +115,15 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
private void startFfmpegProcess(File target) {
|
||||
ffmpegThread = new Thread(() -> {
|
||||
try {
|
||||
String[] args = Config.getInstance().getSettings().ffmpegMergedDownloadArgs.split(" ");
|
||||
String[] argsPlusFile = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, argsPlusFile, 0, args.length);
|
||||
argsPlusFile[argsPlusFile.length-1] = target.getAbsolutePath();
|
||||
String[] args = config.getSettings().ffmpegMergedDownloadArgs.split(" ");
|
||||
String[] argsPlusFile = new String[args.length + 3];
|
||||
int i = 0;
|
||||
argsPlusFile[i++] = "-i";
|
||||
argsPlusFile[i++] = "-";
|
||||
System.arraycopy(args, 0, argsPlusFile, i, args.length);
|
||||
argsPlusFile[argsPlusFile.length - 1] = targetFile.getAbsolutePath();
|
||||
String[] cmdline = OS.getFFmpegCommand(argsPlusFile);
|
||||
|
||||
LOG.debug("Command line: {}", Arrays.toString(cmdline));
|
||||
ffmpeg = Runtime.getRuntime().exec(cmdline, new String[0], target.getParentFile());
|
||||
ffmpegStdIn = ffmpeg.getOutputStream();
|
||||
|
@ -134,7 +139,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
stderr.join();
|
||||
mergeLogStream.flush();
|
||||
}
|
||||
if (exitCode == 0) {
|
||||
if (exitCode != 1) {
|
||||
if (ffmpegLog.exists()) {
|
||||
Files.delete(ffmpegLog.toPath());
|
||||
}
|
||||
|
@ -284,8 +289,10 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
}
|
||||
|
||||
private void writeSegment(byte[] segmentData) throws IOException {
|
||||
if (running) {
|
||||
ffmpegStdIn.write(segmentData);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean splitRecording() {
|
||||
if (config.getSettings().splitRecordings > 0) {
|
||||
|
@ -336,7 +343,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
LOG.debug("Waiting for download to finish {}", model);
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
if(!downloadFinished) {
|
||||
if (!downloadFinished) {
|
||||
LOG.warn("Download didn't finishe properly for model {}", model);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -352,10 +359,12 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
|||
running = false;
|
||||
if (ffmpegStdIn != null) {
|
||||
try {
|
||||
downloadQueue.clear();
|
||||
ffmpegStdIn.close();
|
||||
ffmpegStdIn = null;
|
||||
} catch (IOException e) {
|
||||
LOG.error("Couldn't close ffmpeg stream", e);
|
||||
LOG.error("Couldn't terminate FFmpeg by closing stdin", e);
|
||||
} finally {
|
||||
ffmpeg.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue