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;
}
}
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();
}
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();
}
}
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);
}
}
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());
}
}
Aggregations