use of org.fagu.fmv.ffmpeg.executor.FFExecListener in project fmv by f-agu.
the class FFReducer method createCropDetectFFExecListener.
/**
* @param logger
* @param cropDetect
* @param videoMetadatas
* @return
*/
private FFExecListener createCropDetectFFExecListener(Logger logger, CropDetect cropDetect, MovieMetadatas videoMetadatas) {
return new FFExecListener() {
/**
* @see org.fagu.fmv.soft.exec.FMVExecListener#eventPostExecute(org.fagu.fmv.soft.exec.FMVExecutor,
* org.apache.commons.exec.CommandLine, java.util.Map, org.apache.commons.exec.ExecuteResultHandler)
*/
@Override
public void eventPostExecute(FMVExecutor fmvExecutor, CommandLine command, Map environment, ExecuteResultHandler handler) {
CropDetection cropDetection = cropDetect.getCropSizeDetected();
SortedSet<CropSize> orderedCropSizes = cropDetection.getOrderedCropSizes();
if (!orderedCropSizes.isEmpty()) {
CropSize first = orderedCropSizes.first();
Size size = first.toSize();
if (!videoMetadatas.getVideoStreams().stream().anyMatch(s -> size.equals(s.size()))) {
logger.log("CropDetect: " + cropDetection.getTotalCount() + " lines parsed");
orderedCropSizes.stream().limit(10).forEach(cs -> logger.log("CropDetect: " + cs));
logger.log("CropDetect: Add crop filter: " + first.toCrop());
}
}
}
};
}
use of org.fagu.fmv.ffmpeg.executor.FFExecListener in project fmv by f-agu.
the class FFReducer method createVolumeDetectFFExecListener.
/**
* @param logger
* @param volumeDetect
* @return
*/
private FFExecListener createVolumeDetectFFExecListener(Logger logger, VolumeDetect volumeDetect) {
return new FFExecListener() {
/**
* @see org.fagu.fmv.soft.exec.FMVExecListener#eventPostExecute(org.fagu.fmv.soft.exec.FMVExecutor,
* org.apache.commons.exec.CommandLine, java.util.Map, org.apache.commons.exec.ExecuteResultHandler)
*/
@Override
public void eventPostExecute(FMVExecutor fmvExecutor, CommandLine command, Map environment, ExecuteResultHandler handler) {
if (volumeDetect.isDetected()) {
VolumeDetected detected = volumeDetect.getDetected();
logger.log("VolumeDetect: nb_sample= " + detected.countSample());
logger.log("VolumeDetect: max= " + detected.getMax());
logger.log("VolumeDetect: mean= " + detected.getMean());
logger.log("VolumeDetect: histogram= " + detected.getHistogram());
logger.log("VolumeDetect: Add volume filter: " + detected.toMaxVolume());
} else {
logger.log("volume not detected");
}
}
};
}
use of org.fagu.fmv.ffmpeg.executor.FFExecListener 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();
}
Aggregations