use of org.fagu.fmv.ffmpeg.utils.Fraction in project fmv by f-agu.
the class Stream method countEstimateFrames.
/**
* @return
*/
public OptionalInt countEstimateFrames() {
OptionalInt count = numberOfFrames();
if (count.isPresent()) {
return count;
}
FrameRate frameRate = frameRate().orElse(null);
if (frameRate == null) {
frameRate = averageFrameRate().orElse(null);
}
if (frameRate == null) {
return OptionalInt.empty();
}
Duration duration = duration().orElse(null);
if (duration == null) {
Optional<Object> totDurObj = movieMetadatas.getFormat().tag("totalduration");
if (totDurObj.isPresent()) {
int totDur = NumberUtils.toInt(String.valueOf(totDurObj.get()));
if (totDur > 0) {
duration = Duration.valueOf(totDur);
}
}
}
if (duration == null) {
duration = movieMetadatas.getFormat().duration().orElse(null);
}
if (duration == null) {
OptionalInt dts = durationTimeBase();
if (!dts.isPresent()) {
return OptionalInt.empty();
}
Fraction timeBase = timeBase().orElse(null);
if (timeBase == null) {
return OptionalInt.empty();
}
duration = Duration.valueOf(dts.getAsInt() * timeBase.doubleValue());
}
return OptionalInt.of((int) (frameRate.doubleValue() * duration.toSeconds()));
}
Aggregations