forked from j62/ctbrec
Determine the movie's length from the MP4 file
Use the time spent recording the stream as a fallback
This commit is contained in:
parent
da4c1bda2c
commit
e8fccb327a
|
@ -26,6 +26,8 @@ import javax.xml.bind.JAXBElement;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
|
||||||
|
import org.jcodec.containers.mp4.MP4Util;
|
||||||
|
import org.jcodec.containers.mp4.boxes.MovieBox;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -63,6 +65,7 @@ public class DashDownload extends AbstractDownload {
|
||||||
private ZonedDateTime splitRecStartTime;
|
private ZonedDateTime splitRecStartTime;
|
||||||
|
|
||||||
private File targetFile;
|
private File targetFile;
|
||||||
|
private File finalFile;
|
||||||
|
|
||||||
public DashDownload(HttpClient httpClient, String manifestUrl) {
|
public DashDownload(HttpClient httpClient, String manifestUrl) {
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
|
@ -225,7 +228,7 @@ public class DashDownload extends AbstractDownload {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
File finalFile = Config.getInstance().getFileForRecording(model, "mp4", startTime);
|
finalFile = Config.getInstance().getFileForRecording(model, "mp4", startTime);
|
||||||
targetFile = new File(finalFile.getParentFile(), finalFile.getName() + ".part");
|
targetFile = new File(finalFile.getParentFile(), finalFile.getName() + ".part");
|
||||||
downloadDir = targetFile.toPath();
|
downloadDir = targetFile.toPath();
|
||||||
}
|
}
|
||||||
|
@ -363,8 +366,15 @@ public class DashDownload extends AbstractDownload {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Duration getLength() {
|
public Duration getLength() {
|
||||||
|
try {
|
||||||
|
MovieBox movieBox = MP4Util.parseMovie(finalFile);
|
||||||
|
double lengthInSeconds = (double) movieBox.getDuration() / movieBox.getTimescale();
|
||||||
|
return Duration.ofSeconds((long) Math.ceil(lengthInSeconds));
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.error("Couldn't determine length of MP4 file {}", getTarget(), e);
|
||||||
return Duration.between(startTime, Optional.ofNullable(endTime).orElse(Instant.now()));
|
return Duration.between(startTime, Optional.ofNullable(endTime).orElse(Instant.now()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess(Recording recording) {
|
public void postprocess(Recording recording) {
|
||||||
|
|
Loading…
Reference in New Issue