Search in sources :

Example 1 with Fraction

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()));
}
Also used : FrameRate(org.fagu.fmv.ffmpeg.utils.FrameRate) Duration(org.fagu.fmv.utils.time.Duration) JSONObject(net.sf.json.JSONObject) Fraction(org.fagu.fmv.ffmpeg.utils.Fraction) OptionalInt(java.util.OptionalInt)

Aggregations

OptionalInt (java.util.OptionalInt)1 JSONObject (net.sf.json.JSONObject)1 Fraction (org.fagu.fmv.ffmpeg.utils.Fraction)1 FrameRate (org.fagu.fmv.ffmpeg.utils.FrameRate)1 Duration (org.fagu.fmv.utils.time.Duration)1