Search in sources :

Example 1 with FrameRate

use of org.fagu.fmv.ffmpeg.utils.FrameRate in project fmv by f-agu.

the class Bootstrap method newProject.

/**
 * @param printStream
 * @return
 */
private static Project newProject(PrintStream printStream) {
    try (Scanner scanner = new Scanner(new UnclosedInputStream(System.in))) {
        // name
        printStream.print("Name: ");
        String name = scanner.nextLine();
        // save file
        final File defaultSaveFile = new File(name);
        printStream.print("SaveFolder: [" + defaultSaveFile.getAbsolutePath() + "] ");
        File saveFile = null;
        String ssavefile = scanner.nextLine();
        if (StringUtils.isBlank(ssavefile)) {
            saveFile = defaultSaveFile;
        } else {
            saveFile = new File(ssavefile);
        }
        saveFile = new File(saveFile, name + ".fmv");
        saveFile.getParentFile().mkdirs();
        // format
        final String defaultFormat = "mp4";
        printStream.print("Format: [" + defaultFormat + "] ");
        String format = scanner.nextLine();
        if (StringUtils.isBlank(format)) {
            format = defaultFormat;
        }
        // size
        final Size defaultSize = Size.HD720;
        printStream.print("Size: [" + defaultSize + "] ");
        Size size = null;
        while (size == null) {
            String ssize = scanner.nextLine();
            if (StringUtils.isBlank(ssize)) {
                size = defaultSize;
            } else {
                try {
                    size = Size.parse(ssize);
                } catch (IllegalArgumentException e) {
                    printStream.println("Don't understand: " + ssize);
                }
            }
        }
        // rate
        final FrameRate defaultRate = FrameRate.valueOf(30, 1);
        printStream.print("Rate: [" + defaultRate + "] ");
        FrameRate frameRate = null;
        while (frameRate == null) {
            String srate = scanner.nextLine();
            if (StringUtils.isBlank(srate)) {
                frameRate = defaultRate;
            } else {
                try {
                    frameRate = FrameRate.parse(srate);
                } catch (IllegalArgumentException e) {
                    printStream.println("Don't understand: " + srate);
                }
            }
        }
        OutputInfos outputInfos = new OutputInfos();
        outputInfos.setSize(size);
        outputInfos.setFrameRate(frameRate);
        // TODO
        outputInfos.setAudioSampling(44100);
        outputInfos.setFormat(format);
        Project project = new Project(saveFile, outputInfos);
        project.setName(name);
        try {
            project.save();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return project;
    }
}
Also used : Scanner(java.util.Scanner) Project(org.fagu.fmv.core.project.Project) FrameRate(org.fagu.fmv.ffmpeg.utils.FrameRate) UnclosedInputStream(org.fagu.fmv.utils.io.UnclosedInputStream) Size(org.fagu.fmv.utils.media.Size) OutputInfos(org.fagu.fmv.core.project.OutputInfos) IOException(java.io.IOException) File(java.io.File)

Example 2 with FrameRate

use of org.fagu.fmv.ffmpeg.utils.FrameRate 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)

Example 3 with FrameRate

use of org.fagu.fmv.ffmpeg.utils.FrameRate in project fmv by f-agu.

the class FFReducer method isVideo.

/**
 * @param metadatas
 * @param logger
 * @return
 */
private boolean isVideo(MovieMetadatas metadatas, Logger logger) {
    if (!metadatas.contains(Type.VIDEO)) {
        logger.log("Is audio: not contains video stream");
        return false;
    }
    VideoStream videoStream = metadatas.getVideoStream();
    OptionalInt numberOfFrames = videoStream.numberOfFrames();
    if (numberOfFrames.isPresent() && numberOfFrames.getAsInt() == 1) {
        logger.log("Is audio: number of frames unavailable: " + numberOfFrames);
        return false;
    }
    if (Decoders.MJPEG.getName().equals(videoStream.codecName().get())) {
        FrameRate frameRate = videoStream.frameRate().orElse(null);
        if (frameRate != null && frameRate.floatValue() < 100) {
            return true;
        }
        logger.log("Is audio: frameRate is null or too high: " + frameRate);
        return false;
    }
    return true;
}
Also used : FrameRate(org.fagu.fmv.ffmpeg.utils.FrameRate) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) OptionalInt(java.util.OptionalInt)

Aggregations

FrameRate (org.fagu.fmv.ffmpeg.utils.FrameRate)3 OptionalInt (java.util.OptionalInt)2 File (java.io.File)1 IOException (java.io.IOException)1 Scanner (java.util.Scanner)1 JSONObject (net.sf.json.JSONObject)1 OutputInfos (org.fagu.fmv.core.project.OutputInfos)1 Project (org.fagu.fmv.core.project.Project)1 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)1 Fraction (org.fagu.fmv.ffmpeg.utils.Fraction)1 UnclosedInputStream (org.fagu.fmv.utils.io.UnclosedInputStream)1 Size (org.fagu.fmv.utils.media.Size)1 Duration (org.fagu.fmv.utils.time.Duration)1