use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.
the class FFHelper method resize.
/**
* @param inFile
* @param size
* @param outFile
* @throws IOException
*/
public static void resize(File inFile, Size size, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
builder.filter(Scale.to(size, ScaleMode.fitToBoxKeepAspectRatio()));
builder.mux(MP4Muxer.to(outFile)).qualityScaleVideo(0).codecCopy(Type.AUDIO).codecCopy(Type.SUBTITLE).mapAllStreams(inputProcessor).overwrite();
FFExecutor<Object> executor = builder.build();
executor.addListener(new FFExecListener() {
@Override
public void eventExecFailed(IOException e, CommandLine command) {
System.out.println("FAILED: " + CommandLineUtils.toLine(command));
}
@Override
public void eventPreExecFallbacks(CommandLine command, Collection<FFExecFallback> fallbacks) {
System.out.println("With fallback: " + fallbacks);
System.out.println(" -->: " + CommandLineUtils.toLine(command));
}
});
executor.execute();
}
use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.
the class FFHelper method extractThumbnails2GIF.
/**
* similar extractThumbnails2JPEGS(..) without 'format("image2")'
*
* @param inFile
* @param outFolder
* @param countFrame
* @return
* @throws IOException
*/
public static void extractThumbnails2GIF(File inFile, File outFile, int countFrame) throws IOException {
if (!"gif".equalsIgnoreCase(FilenameUtils.getExtension(outFile.getName()))) {
throw new IllegalArgumentException("Not a gif: " + outFile.getPath());
}
// extract images
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
// global
builder.hideBanner();
builder.logLevel(LogLevel.INFO);
// input
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
// infos
MovieMetadatas movieMetadatas = inputProcessor.getMovieMetadatas();
VideoStream videoStream = movieMetadatas.getVideoStream();
// filter
SelectVideo selectVideo = SelectVideo.build().countFrame(videoStream, countFrame);
builder.filter(selectVideo);
// necessary ?
builder.filter(Format.with(PixelFormat.RGB8));
builder.filter(Format.with(PixelFormat.RGB24));
// output
builder.addMediaOutputFile(outFile).videoSync(VSync.PASSTHROUGH).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.
the class FFHelper method audioHalfVolume.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void audioHalfVolume(File inFile, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
AudioModifier audioModifier = AudioModifier.build().halfVolume().channelLayout(ChannelLayout.SAME);
FilterComplex filtercomplex = FilterComplex.create(audioModifier);
filtercomplex.addInput(inputProcessor);
builder.filter(filtercomplex);
builder.addMediaOutputFile(outFile).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.
the class FFHelper method cutConcat.
/**
* @param inFiles
* @param outFile
* @throws IOException
*/
public static void cutConcat(List<File> inFiles, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
Concat concat = Concat.create(builder, inFiles);
// for(File inFile : inFiles) {
// InputProcessor inputProcessor = builder.inputFile(inFile);
//
// // les 2 SetPTS permettent de commencer la video au debut car une video ne
// commence pas toujours a 0 !
//
// SetPTS setPTS = new SetPTSVideo();
// setPTS.setStartAtFirstFrame();
// FilterComplex setPTSComplex = FilterComplex.createWith(setPTS);
// setPTSComplex.addInput(inputProcessor, Type.VIDEO);
// builder.add(setPTSComplex);
// concat.addInput(setPTSComplex);
//
// setPTS = new SetPTSAudio();
// setPTS.setStartAtFirstFrame();
// setPTSComplex = FilterComplex.createWith(setPTS);
// setPTSComplex.addInput(inputProcessor, Type.AUDIO);
// builder.add(setPTSComplex);
// concat.addInput(setPTSComplex);
// }
builder.filter(concat);
builder.addMediaOutputFile(outFile).qualityScaleAudio(0).qualityScaleVideo(0).codec(H264.findRecommanded().mostCompatible()).format("mp4").overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
use of org.fagu.fmv.ffmpeg.executor.FFMPEGExecutorBuilder in project fmv by f-agu.
the class FFHelper method backgroundBlurOverlayScale.
/**
* @param inFile
* @param outFile
* @throws IOException
*/
public static void backgroundBlurOverlayScale(File inFile, File outFile) throws IOException {
FFMPEGExecutorBuilder builder = FFMPEGExecutorBuilder.create();
// inFile is in HD720
InputProcessor inputProcessor = builder.addMediaInputFile(inFile);
// builder.filter(FilterComplex.create(AudioGenerator.build().silence()));
Boxblur boxblur = Boxblur.build().lumaRadius("8").lumaPower(8);
Hue hue = Hue.build().blackAndWhite();
FilterComplex blurAndBW = FilterComplex.create(boxblur, hue).addInput(inputProcessor);
FilterComplex scale = FilterComplex.create(Scale.build().size(Size.HD480)).addInput(inputProcessor);
Overlay overlay = Overlay.with(blurAndBW, scale).shortest(true).positionMiddle();
FilterComplex scale2 = FilterComplex.create(Scale.build().size(Size.HD480)).addInput(overlay);
builder.filter(scale2);
builder.addMediaOutputFile(outFile).overwrite();
FFExecutor<Object> executor = builder.build();
executor.execute();
}
Aggregations