Search in sources :

Example 1 with OutputInfos

use of org.fagu.fmv.core.project.OutputInfos 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 OutputInfos

use of org.fagu.fmv.core.project.OutputInfos in project fmv by f-agu.

the class FileCache method scaleForPreview.

/**
 * @param inFile
 * @param toFile
 * @param id
 * @throws IOException
 */
private void scaleForPreview(File inFile, File toFile, Identifiable identifiable) throws IOException {
    OutputInfos outputInfos = project.getOutputInfos();
    Size previewSize = outputInfos.getSize().fitAndKeepRatioTo(PREVIEW_SIZE);
    FFMPEGExecutorBuilder builder = FFUtils.builder(project);
    builder.addMediaInputFile(inFile);
    builder.filter(Scale.to(previewSize, ScaleMode.fitToBox()));
    Drawtext drawtext = Drawtext.build().x(0);
    drawtext.y(16 * identifiable.getDepth(i -> i instanceof Executable));
    drawtext.text(identifiable.getId() + " - %{pts} / %{n}").fontColor(Color.WHITE).fontSize(15);
    builder.filter(drawtext);
    builder.addMediaOutputFile(toFile).format(outputInfos.getFormat()).overwrite();
    FFExecutor<Object> build = builder.build();
    build.execute();
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Size(org.fagu.fmv.utils.media.Size) OutputInfos(org.fagu.fmv.core.project.OutputInfos) Drawtext(org.fagu.fmv.ffmpeg.filter.impl.Drawtext)

Example 3 with OutputInfos

use of org.fagu.fmv.core.project.OutputInfos in project fmv by f-agu.

the class FileCache method scaleForMake.

/**
 * @param inFile
 * @throws IOException
 */
private void scaleForMake(File inFile) throws IOException {
    OutputInfos outputInfos = project.getOutputInfos();
    Size makeSize = outputInfos.getSize();
    MovieMetadatas metadatas = MovieMetadatas.with(inFile).extract();
    VideoStream videoStream = metadatas.getVideoStream();
    if (videoStream == null) {
        return;
    }
    Size videoSize = videoStream.size();
    if (videoSize.equals(makeSize)) {
        return;
    }
    File makeTmpFile = File.createTempFile(inFile.getName() + "-", "." + FilenameUtils.getExtension(inFile.getName()), inFile.getParentFile());
    try {
        makeTmpFile.delete();
        if (!inFile.renameTo(makeTmpFile)) {
            throw new IOException("Unable to rename " + inFile + " to " + makeTmpFile);
        }
        File toFile = inFile;
        FFMPEGExecutorBuilder builder = FFUtils.builder(project);
        // input
        builder.addMediaInputFile(makeTmpFile);
        // filter
        builder.filter(Scale.to(makeSize, ScaleMode.fitToBox()));
        // output
        builder.addMediaOutputFile(toFile).format(outputInfos.getFormat()).overwrite();
        FFExecutor<Object> build = builder.build();
        build.execute();
    } finally {
        makeTmpFile.delete();
    }
}
Also used : FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) Size(org.fagu.fmv.utils.media.Size) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) OutputInfos(org.fagu.fmv.core.project.OutputInfos) IOException(java.io.IOException) File(java.io.File)

Example 4 with OutputInfos

use of org.fagu.fmv.core.project.OutputInfos in project fmv by f-agu.

the class CutExecutable method execute.

/**
 * @see org.fagu.fmv.core.exec.Executable#execute(java.io.File, Cache)
 */
@Override
public void execute(File toFile, Cache cache) throws IOException {
    Source source = getSource();
    Executable executable = getExecutable();
    if (executable == null && source == null) {
        return;
    }
    OutputInfos outputInfos = getProject().getOutputInfos();
    FFMPEGExecutorBuilder builder = FFUtils.builder(getProject());
    InputProcessor inputProcessor = null;
    if (executable != null) {
        File childExec = getProject().getFileCache().getFile(executable, cache);
        // executable.execute(childExec, cache);
        inputProcessor = builder.addMediaInputFile(childExec);
    } else if (source != null) {
        inputProcessor = (InputProcessor) source.createAndAdd(builder);
    } else {
        throw new IllegalArgumentException("Source or executable not defined !");
    }
    inputProcessor.timeSeek(startTime);
    // SetPTS videoSetPTS = new SetPTSVideo();
    // videoSetPTS.setStartAtFirstFrame();
    // FilterComplex videoSetPTSComplex = FilterComplex.createWith(videoSetPTS);
    // videoSetPTSComplex.addInput(inputProcessor, Type.VIDEO);
    // builder.add(videoSetPTSComplex);
    // 
    // SetPTS audioSetPTS = new SetPTSAudio();
    // audioSetPTS.setStartAtFirstFrame();
    // FilterComplex audioSetPTSComplex = FilterComplex.createWith(audioSetPTS);
    // audioSetPTSComplex.addInput(inputProcessor, Type.AUDIO);
    // builder.add(audioSetPTSComplex);
    BasicStreamMuxer muxer = BasicStreamMuxer.to(toFile, outputInfos.getFormat()).avoidNegativeTs(AvoidNegativeTs.MAKE_NON_NEGATIVE);
    OutputProcessor outputProcessor = builder.mux(muxer);
    outputProcessor.duration(duration);
    outputProcessor(outputProcessor, cache);
    FFExecutor<Object> executor = builder.build();
    executor.execute();
    if (cache == Cache.MAKE) {
        MovieMetadatas movieMetadatas = MovieMetadatas.with(toFile).extract();
        MovieMetadatasUtils.getDuration(movieMetadatas).ifPresent(this::setDuration);
    }
}
Also used : BasicStreamMuxer(org.fagu.fmv.ffmpeg.format.BasicStreamMuxer) FFMPEGExecutorBuilder(org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) OutputInfos(org.fagu.fmv.core.project.OutputInfos) OutputProcessor(org.fagu.fmv.ffmpeg.operation.OutputProcessor) InputProcessor(org.fagu.fmv.ffmpeg.operation.InputProcessor) Executable(org.fagu.fmv.core.exec.Executable) File(java.io.File) Source(org.fagu.fmv.core.exec.Source)

Example 5 with OutputInfos

use of org.fagu.fmv.core.project.OutputInfos in project fmv by f-agu.

the class GenericExecutable method fixOutput.

/**
 * @param outputProcessor
 */
protected void fixOutput(OutputProcessor outputProcessor) {
    if (executables.isEmpty() && getFilters().isEmpty() && !sources.isEmpty()) {
        OutputInfos outputInfos = getProject().getOutputInfos();
        outputProcessor.videoRate(outputInfos.getFrameRate().invert().intValue());
    }
}
Also used : OutputInfos(org.fagu.fmv.core.project.OutputInfos)

Aggregations

OutputInfos (org.fagu.fmv.core.project.OutputInfos)6 File (java.io.File)3 FFMPEGExecutorBuilder (org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder)3 Size (org.fagu.fmv.utils.media.Size)3 IOException (java.io.IOException)2 BasicStreamMuxer (org.fagu.fmv.ffmpeg.format.BasicStreamMuxer)2 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)2 Scanner (java.util.Scanner)1 Executable (org.fagu.fmv.core.exec.Executable)1 Source (org.fagu.fmv.core.exec.Source)1 Project (org.fagu.fmv.core.project.Project)1 Drawtext (org.fagu.fmv.ffmpeg.filter.impl.Drawtext)1 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)1 InputProcessor (org.fagu.fmv.ffmpeg.operation.InputProcessor)1 OutputProcessor (org.fagu.fmv.ffmpeg.operation.OutputProcessor)1 FrameRate (org.fagu.fmv.ffmpeg.utils.FrameRate)1 UnclosedInputStream (org.fagu.fmv.utils.io.UnclosedInputStream)1