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.Unmarshaller;
|
||||
|
||||
import org.jcodec.containers.mp4.MP4Util;
|
||||
import org.jcodec.containers.mp4.boxes.MovieBox;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -63,6 +65,7 @@ public class DashDownload extends AbstractDownload {
|
|||
private ZonedDateTime splitRecStartTime;
|
||||
|
||||
private File targetFile;
|
||||
private File finalFile;
|
||||
|
||||
public DashDownload(HttpClient httpClient, String manifestUrl) {
|
||||
this.httpClient = httpClient;
|
||||
|
@ -225,7 +228,7 @@ public class DashDownload extends AbstractDownload {
|
|||
this.config = config;
|
||||
this.model = model;
|
||||
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");
|
||||
downloadDir = targetFile.toPath();
|
||||
}
|
||||
|
@ -363,7 +366,14 @@ public class DashDownload extends AbstractDownload {
|
|||
|
||||
@Override
|
||||
public Duration getLength() {
|
||||
return Duration.between(startTime, Optional.ofNullable(endTime).orElse(Instant.now()));
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue