forked from j62/ctbrec
1
0
Fork 0

Implement getLength in MergedHlsDownload with jcodec

This commit is contained in:
0xboobface 2019-12-23 13:36:54 +01:00
parent 7aa07e1c5f
commit da28d02da8
1 changed files with 15 additions and 0 deletions

View File

@ -8,8 +8,11 @@ import java.net.URL;
import java.nio.file.Files;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.Arrays;
import org.jcodec.containers.mp4.MP4Util;
import org.jcodec.containers.mp4.boxes.MovieBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -151,4 +154,16 @@ public class MergedHlsDownload extends HlsDownload {
response.close();
}
}
@Override
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.ofSeconds(0);
}
}
}