forked from j62/ctbrec
Implement getLength in MergedHlsDownload with jcodec
This commit is contained in:
parent
7aa07e1c5f
commit
da28d02da8
|
@ -8,8 +8,11 @@ import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -151,4 +154,16 @@ public class MergedHlsDownload extends HlsDownload {
|
||||||
response.close();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue