use of org.fagu.fmv.soft.exec.FMVExecutor 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.soft.exec.FMVExecutor 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.soft.exec.FMVExecutor in project fmv by f-agu.
the class ExecSoftFoundFactory method create.
/**
* @see org.fagu.fmv.soft.find.SoftFoundFactory#create(java.io.File, Locator, SoftPolicy)
*/
@Override
public final SoftFound create(File file, Locator locator, SoftPolicy softPolicy) throws IOException {
Parser parser = parserFactory.create(file, softPolicy);
CommandLine commandLine = FMVCommandLine.create(file, parameters);
String cmdLineStr = CommandLineUtils.toLine(commandLine);
List<String> readLineList = new ArrayList<>();
BufferedReadLine bufferedReadLine = new BufferedReadLine(readLineList);
FMVExecutor executor = executorFactory.create(file, parser, bufferedReadLine);
try {
int exitValue = executor.execute(commandLine);
SoftFound softFound = parser.closeAndParse(cmdLineStr, exitValue);
if (locator != null && softFound != null) {
softFound.setLocalizedBy(locator.toString());
}
return softFound;
} catch (IOException e) {
return parser.closeAndParse(e, cmdLineStr, readLineList);
}
}
use of org.fagu.fmv.soft.exec.FMVExecutor in project fmv by f-agu.
the class SoftExecutor method executeInBackground.
/**
* @param executorService
* @return
* @throws IOException
*/
public Future<SoftExecutor.Executed> executeInBackground(ExecutorService executorService) throws IOException {
return execute((fmvExecutor, commandLine, execListener, readLineList) -> {
final String cmdLineStr = CommandLineUtils.toLine(commandLine);
final AtomicLong startTime = new AtomicLong();
final AtomicLong time = new AtomicLong();
final PIDProcessOperator pidProcessOperator = new PIDProcessOperator();
fmvExecutor.addProcessOperator(pidProcessOperator);
return new WrapFuture<>(fmvExecutor.executeAsynchronous(geExecuteDelegate(), commandLine, executorService, // before
() -> {
startTime.set(System.currentTimeMillis());
execListener.eventExecuting(cmdLineStr);
}, // after
exitValue -> {
time.set(System.currentTimeMillis() - startTime.get());
execListener.eventExecuted(cmdLineStr, exitValue, time.get());
}, // exception
exception -> {
if (exception instanceof ExecuteException) {
ExecuteException e = (ExecuteException) exception;
FMVExecuteException fmvExecuteException = new FMVExecuteException(softProvider.getExceptionKnownAnalyzerClass(), e, cmdLineStr, readLineList);
execListener.eventException(fmvExecuteException);
ExceptionKnownAnalyzers.doOrThrows(softProvider.getExceptionKnownAnalyzerClass(), fmvExecuteException, exceptionKnowConsumer, exceptionConsumer);
}
}), exitValue -> new Executed(pidProcessOperator.getPID(), exitValue, time.get()));
});
}
use of org.fagu.fmv.soft.exec.FMVExecutor in project fmv by f-agu.
the class SoftExecutor method execute.
// -------------------------------------------------------------
/**
* @param executorService
* @return
* @throws IOException
*/
private <R> R execute(SoftExecutor.ForExec<R> forExec) throws IOException {
ExecListener execListener = new Proxifier<>(ExecListener.class).addAll(execListeners).proxify();
CommandLine commandLine = getCommandLine();
String cmdLineStr = CommandLineUtils.toLine(commandLine);
execListener.eventPrepare(cmdLineStr);
List<String> readLineList = new ArrayList<>();
ReadLine bufferedReadLine = new BufferedReadLine(readLineList);
FMVExecutor fmvExecutor = createFMVExecutor(execFile.getParentFile(), bufferedReadLine);
applyCustomizeExecutor(fmvExecutor);
return forExec.exec(fmvExecutor, commandLine, execListener, readLineList);
}
Aggregations