use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.
the class FFHelper method videoToGraph.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void videoToGraph(File inAudio, File outImage) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
builder.hideBanner();
builder.getFFMPEGOperation().setAutoMap(AutoMaps.disable());
builder.addMediaInputFile(inAudio);
FilterComplex filter = FilterComplex.create(AudioToPictureShowWaves.build().size(Size.valueOf(1024, 200)));
builder.filter(filter);
builder.addMediaOutputFile(outImage).numberOfVideoFrameToRecord(1);
FFExecutor<Object> executor = builder.build();
System.out.println(executor.getCommandLine());
executor.execute();
}
use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.
the class FFHelper method concat.
/**
* @param inFiles
* @param outFile
* @throws IOException
*/
public static void concat(List<File> inFiles, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
Concat concat = Concat.create(builder, inFiles);
builder.filter(concat);
builder.mux(MP4Muxer.to(outFile).movflags(Movflags.FASTSTART)).qualityScale(0).codec(H264.findRecommanded().mostCompatible()).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder 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.ffmpeg.executor.FFMPEGExecutorBuilder 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.ffmpeg.executor.FFMPEGExecutorBuilder 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);
}
}
Aggregations