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 com.squareup.moshi.JsonWriter;
|
||||||
|
|
||||||
import ctbrec.recorder.download.Download;
|
import ctbrec.recorder.download.Download;
|
||||||
import ctbrec.recorder.download.hls.FFmpegDownload;
|
|
||||||
import ctbrec.recorder.download.hls.HlsDownload;
|
import ctbrec.recorder.download.hls.HlsDownload;
|
||||||
|
import ctbrec.recorder.download.hls.MergedFfmpegHlsDownload;
|
||||||
import ctbrec.sites.Site;
|
import ctbrec.sites.Site;
|
||||||
|
|
||||||
public abstract class AbstractModel implements Model {
|
public abstract class AbstractModel implements Model {
|
||||||
|
@ -233,7 +233,7 @@ public abstract class AbstractModel implements Model {
|
||||||
if (Config.isServerMode()) {
|
if (Config.isServerMode()) {
|
||||||
return new HlsDownload(getSite().getHttpClient());
|
return new HlsDownload(getSite().getHttpClient());
|
||||||
} else {
|
} 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");
|
LOG.trace("Stream redirect thread ended");
|
||||||
} catch(Exception e) {
|
} 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;
|
super.startTime = startTime;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
targetFile = Config.getInstance().getFileForRecording(model, "mp4", startTime);
|
String fileSuffix = config.getSettings().ffmpegFileSuffix;
|
||||||
|
targetFile = config.getFileForRecording(model, fileSuffix, startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -114,11 +115,15 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
||||||
private void startFfmpegProcess(File target) {
|
private void startFfmpegProcess(File target) {
|
||||||
ffmpegThread = new Thread(() -> {
|
ffmpegThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
String[] args = Config.getInstance().getSettings().ffmpegMergedDownloadArgs.split(" ");
|
String[] args = config.getSettings().ffmpegMergedDownloadArgs.split(" ");
|
||||||
String[] argsPlusFile = new String[args.length + 1];
|
String[] argsPlusFile = new String[args.length + 3];
|
||||||
System.arraycopy(args, 0, argsPlusFile, 0, args.length);
|
int i = 0;
|
||||||
argsPlusFile[argsPlusFile.length-1] = target.getAbsolutePath();
|
argsPlusFile[i++] = "-i";
|
||||||
|
argsPlusFile[i++] = "-";
|
||||||
|
System.arraycopy(args, 0, argsPlusFile, i, args.length);
|
||||||
|
argsPlusFile[argsPlusFile.length - 1] = targetFile.getAbsolutePath();
|
||||||
String[] cmdline = OS.getFFmpegCommand(argsPlusFile);
|
String[] cmdline = OS.getFFmpegCommand(argsPlusFile);
|
||||||
|
|
||||||
LOG.debug("Command line: {}", Arrays.toString(cmdline));
|
LOG.debug("Command line: {}", Arrays.toString(cmdline));
|
||||||
ffmpeg = Runtime.getRuntime().exec(cmdline, new String[0], target.getParentFile());
|
ffmpeg = Runtime.getRuntime().exec(cmdline, new String[0], target.getParentFile());
|
||||||
ffmpegStdIn = ffmpeg.getOutputStream();
|
ffmpegStdIn = ffmpeg.getOutputStream();
|
||||||
|
@ -134,7 +139,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
||||||
stderr.join();
|
stderr.join();
|
||||||
mergeLogStream.flush();
|
mergeLogStream.flush();
|
||||||
}
|
}
|
||||||
if (exitCode == 0) {
|
if (exitCode != 1) {
|
||||||
if (ffmpegLog.exists()) {
|
if (ffmpegLog.exists()) {
|
||||||
Files.delete(ffmpegLog.toPath());
|
Files.delete(ffmpegLog.toPath());
|
||||||
}
|
}
|
||||||
|
@ -284,7 +289,9 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeSegment(byte[] segmentData) throws IOException {
|
private void writeSegment(byte[] segmentData) throws IOException {
|
||||||
ffmpegStdIn.write(segmentData);
|
if (running) {
|
||||||
|
ffmpegStdIn.write(segmentData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean splitRecording() {
|
private boolean splitRecording() {
|
||||||
|
@ -336,7 +343,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
||||||
LOG.debug("Waiting for download to finish {}", model);
|
LOG.debug("Waiting for download to finish {}", model);
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
if(!downloadFinished) {
|
if (!downloadFinished) {
|
||||||
LOG.warn("Download didn't finishe properly for model {}", model);
|
LOG.warn("Download didn't finishe properly for model {}", model);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -352,10 +359,12 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
||||||
running = false;
|
running = false;
|
||||||
if (ffmpegStdIn != null) {
|
if (ffmpegStdIn != null) {
|
||||||
try {
|
try {
|
||||||
|
downloadQueue.clear();
|
||||||
ffmpegStdIn.close();
|
ffmpegStdIn.close();
|
||||||
ffmpegStdIn = null;
|
|
||||||
} catch (IOException e) {
|
} 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