public static ExecResult getIdentifyResult(String inputFilePath) throws CommandNotAvailable { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("inputFilePath", inputFilePath); return cles.execCommand("identify", params); }
@Override public boolean isAvailable() { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CommandAvailability commandAvailability = cles.getCommandAvailability("identify"); return commandAvailability.isAvailable(); }
protected Map<String, Object> readMetadata(String command, Blob blob, List<String> metadata, boolean ignorePrefix) { CommandAvailability ca = commandLineService.getCommandAvailability(command); if (!ca.isAvailable()) { throw new BinaryMetadataException("Command '" + command + "' is not available."); } if (blob == null) { throw new BinaryMetadataException("The following command " + ca + " cannot be executed with a null blob"); } try { ExecResult er; try (CloseableFile source = getTemporaryFile(blob)) { CmdParameters params = commandLineService.getDefaultCmdParameters(); params.addNamedParameter("inFilePath", source.getFile()); if (metadata != null) { params.addNamedParameter("tagList", getCommandTags(metadata)); } er = commandLineService.execCommand(command, params); } return returnResultMap(er); } catch (CommandNotAvailable commandNotAvailable) { throw new RuntimeException("Command '" + command + "' is not available.", commandNotAvailable); } catch (IOException ioException) { throw new BinaryMetadataException(ioException); } }
/** * @deprecated Since 7.4. Useless. */ @Deprecated protected static ExecResult execCommand(String commandName, CmdParameters params) throws CommandNotAvailable { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); return cles.execCommand(commandName, params); }
CommandAvailability commandAvailability = cles.getCommandAvailability(THUMBNAIL_COMMAND); if (!commandAvailability.isAvailable()) { return null; targetBlob.setMimeType("image/png"); try (CloseableFile source = blob.getCloseableFile()) { CmdParameters params = cles.getDefaultCmdParameters(); String size = parameters == null ? THUMBNAIL_DEFAULT_SIZE : (String) parameters.getOrDefault(THUMBNAIL_SIZE_PARAMETER_NAME, THUMBNAIL_DEFAULT_SIZE); params.addNamedParameter("outputFilePath", targetBlob.getFile()); ExecResult res = cles.execCommand(THUMBNAIL_COMMAND, params); if (!res.isSuccessful()) { throw res.getError();
private static ExecResult execCommand(String commandName, CmdParameters params) throws CommandNotAvailable { CommandLineExecutorService cles = Framework.getLocalService(CommandLineExecutorService.class); return cles.execCommand(commandName, params); }
public static void convert(String inputFilePath, String outputFilePath) throws CommandNotAvailable, CommandException { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("inputFilePath", inputFilePath); params.addNamedParameter("outputFilePath", outputFilePath); ExecResult res = cles.execCommand("converter", params); if (!res.isSuccessful()) { throw res.getError(); } }
String command = ignorePrefix ? BinaryMetadataConstants.EXIFTOOL_WRITE_NOPREFIX : BinaryMetadataConstants.EXIFTOOL_WRITE; CommandAvailability ca = commandLineService.getCommandAvailability(command); if (!ca.isAvailable()) { throw new BinaryMetadataException("Command '" + command + "' is not available."); CmdParameters params = commandLineService.getDefaultCmdParameters(); params.addNamedParameter("inFilePath", newBlob.getFile()); params.addNamedParameter("tagList", getCommandTags(metadata)); ExecResult er = commandLineService.execCommand(command, params); boolean success = er.isSuccessful(); if (!success) {
ExecResult clResult = cles.execCommand(commandLineName, cmdParams); tool.cleanupInputs(params);
public boolean isToolAvailable(String toolName) { String commandLine; try { VideoTool tool = (VideoTool) videoTools.get(toolName).newInstance(); commandLine = tool.getCommandLineName(); } catch (InstantiationException e) { throw new NuxeoException("The video tool is not available.", e); } catch (IllegalAccessException e) { throw new NuxeoException("The video tool is not available.", e); } CommandAvailability ca = Framework.getService(CommandLineExecutorService.class) .getCommandAvailability(commandLine); return ca.isAvailable(); }
public static void rotate(String inputFile, String outputFile, int angle) throws CommandNotAvailable, CommandException { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("angle", String.valueOf(angle)); params.addNamedParameter("inputFilePath", inputFile); params.addNamedParameter("outputFilePath", outputFile); ExecResult result = cles.execCommand("rotate", params); if (!result.isSuccessful()) { throw result.getError(); } }
public Blob call(Blob blob, String targetExt, String commandName) { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CommandAvailability availability = cles.getCommandAvailability(commandName); if (!availability.isAvailable()) { return null; } try { makeFiles(blob, targetExt); callImageMagick(); Blob targetBlob = Blobs.createBlob(targetFile); targetBlob.setFilename(getFilename(blob, targetExt)); Framework.trackFile(targetFile, targetBlob); return targetBlob; } catch (CommandNotAvailable | CommandException | IOException e) { log.error("ImageMagick failed on command: " + commandName, e); return null; } finally { if (tmpFile != null) { try { Files.delete(tmpFile.toPath()); } catch (IOException e) { log.error("Unable to delete temporary file when calling ImageMagick command: " + commandName, e); } } } }
public static void crop(String inputFilePath, String outputFilePath, int tileWidth, int tileHeight, int offsetX, int offsetY) throws CommandNotAvailable, CommandException { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("tileWidth", String.valueOf(tileWidth)); params.addNamedParameter("tileHeight", String.valueOf(tileHeight)); params.addNamedParameter("offsetX", String.valueOf(offsetX)); params.addNamedParameter("offsetY", String.valueOf(offsetY)); params.addNamedParameter("inputFilePath", inputFilePath); params.addNamedParameter("outputFilePath", outputFilePath); ExecResult res = cles.execCommand("crop", params); if (!res.isSuccessful()) { throw res.getError(); } }
private Blob call(Blob blob, String finalFormat, final int width, final int height, final ImageInfoExtended info) { CommandAvailability availability = cles.getCommandAvailability("resizer"); if (!availability.isAvailable()) { return null;
protected TTCCmdReturn execOnBlobTTC(String commandName, Map<String, Blob> blobParameters, Map<String, String> parameters) throws ConversionException { final CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); final CmdParameters params = cles.getDefaultCmdParameters(); final List<String> filesToDelete = new ArrayList<>(); try { final ExecResult result = cles.execCommand(commandName, params); if (!result.isSuccessful()) { throw result.getError();
CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("targetWidth", String.valueOf(targetWidth)); params.addNamedParameter("targetHeight", String.valueOf(targetHeight)); ExecResult res = cles.execCommand(commandName, params); if (!res.isSuccessful()) { throw res.getError();
/** @since 5.9.5. */ public static void cropAndResize(String inputFilePath, String outputFilePath, int tileWidth, int tileHeight, int offsetX, int offsetY, int targetWidth, int targetHeight, String mapComponents) throws CommandNotAvailable, CommandException { if (mapComponents == null) { mapComponents = DEFAULT_MAP_COMPONENTS; } CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("tileWidth", String.valueOf(tileWidth)); params.addNamedParameter("tileHeight", String.valueOf(tileHeight)); params.addNamedParameter("offsetX", String.valueOf(offsetX)); params.addNamedParameter("offsetY", String.valueOf(offsetY)); params.addNamedParameter("targetWidth", String.valueOf(targetWidth)); params.addNamedParameter("targetHeight", String.valueOf(targetHeight)); params.addNamedParameter("inputFilePath", inputFilePath); params.addNamedParameter("outputFilePath", outputFilePath); params.addNamedParameter("mapComponents", mapComponents); ExecResult res = cles.execCommand("cropAndResize", params); if (!res.isSuccessful()) { throw res.getError(); } }
public static VideoInfo getVideoInfo(Blob video) { if (video == null || video.getLength() == 0) { return null; } try { ExecResult result; try (CloseableFile cf = video.getCloseableFile("." + FilenameUtils.getExtension(video.getFilename()))) { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("inFilePath", cf.getFile().getAbsolutePath()); // read the duration with a first command to adjust the best rate: result = cles.execCommand(FFMPEG_INFO_COMMAND_LINE, params); } if (!result.isSuccessful()) { throw result.getError(); } return VideoInfo.fromFFmpegOutput(result.getOutput()); } catch (CommandNotAvailable | CommandException | IOException e) { throw new NuxeoException(e); } }