use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.
the class ComposerServiceImpl method getProfile.
private EncodingProfile getProfile(Job job, String profileId) throws EncoderException {
final EncodingProfile profile = profileScanner.getProfile(profileId);
if (profile == null) {
final String msg = String.format("Profile %s is unknown", profileId);
logger.error(msg);
incident().recordFailure(job, PROFILE_NOT_FOUND, Collections.map(tuple("profile", profileId)));
throw new EncoderException(msg);
}
return profile;
}
use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.
the class ComposerServiceImpl method imageToVideo.
private Option<Track> imageToVideo(Job job, Attachment sourceImage, String profileId, Double time) throws EncoderException, MediaPackageException {
// Get the encoding profile
final EncodingProfile profile = getProfile(job, profileId);
final String targetTrackId = idBuilder.createNew().toString();
// Get the attachment and make sure it exist
File imageFile;
try {
imageFile = workspace.get(sourceImage.getURI());
} catch (NotFoundException e) {
incident().recordFailure(job, WORKSPACE_GET_NOT_FOUND, e, getWorkspaceMediapackageParams("source image", sourceImage), NO_DETAILS);
throw new EncoderException("Requested source image " + sourceImage + " is not found");
} catch (IOException e) {
incident().recordFailure(job, WORKSPACE_GET_IO_EXCEPTION, e, getWorkspaceMediapackageParams("source image", sourceImage), NO_DETAILS);
throw new EncoderException("Unable to access source image " + sourceImage);
}
// Create the engine
final EncoderEngine encoderEngine = getEncoderEngine();
logger.info("Converting image attachment {} into video {}", sourceImage.getIdentifier(), targetTrackId);
Map<String, String> properties = new HashMap<>();
if (time == -1)
time = 0D;
DecimalFormatSymbols ffmpegFormat = new DecimalFormatSymbols();
ffmpegFormat.setDecimalSeparator('.');
DecimalFormat df = new DecimalFormat("0.000", ffmpegFormat);
properties.put("time", df.format(time));
File output;
try {
output = encoderEngine.encode(imageFile, profile, properties);
} catch (EncoderException e) {
Map<String, String> params = new HashMap<>();
params.put("image", sourceImage.getURI().toString());
params.put("profile", profile.getIdentifier());
params.put("properties", properties.toString());
incident().recordFailure(job, IMAGE_TO_VIDEO_FAILED, e, params, detailsFor(e, encoderEngine));
throw e;
} finally {
activeEncoder.remove(encoderEngine);
}
// encoding did not return a file
if (!output.exists() || output.length() == 0)
return none();
// Put the file in the workspace
URI workspaceURI = putToCollection(job, output, "converted image file");
// Have the compound track inspected and return the result
Job inspectionJob = inspect(job, workspaceURI);
Track inspectedTrack = (Track) MediaPackageElementParser.getFromXml(inspectionJob.getPayload());
inspectedTrack.setIdentifier(targetTrackId);
if (profile.getMimeType() != null)
inspectedTrack.setMimeType(MimeTypes.parseMimeType(profile.getMimeType()));
return some(inspectedTrack);
}
use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.
the class ComposerServiceImpl method image.
/**
* {@inheritDoc}
*
* @see org.opencastproject.composer.api.ComposerService#image(Track, String, double...)
*/
@Override
public Job image(Track sourceTrack, String profileId, double... times) throws EncoderException, MediaPackageException {
if (sourceTrack == null)
throw new IllegalArgumentException("SourceTrack cannot be null");
if (times.length == 0)
throw new IllegalArgumentException("At least one time argument has to be specified");
List<String> parameters = new ArrayList<>();
parameters.add(profileId);
parameters.add(MediaPackageElementParser.getAsXml(sourceTrack));
parameters.add(Boolean.TRUE.toString());
for (double time : times) {
parameters.add(Double.toString(time));
}
try {
final EncodingProfile profile = profileScanner.getProfile(profileId);
return serviceRegistry.createJob(JOB_TYPE, Operation.Image.toString(), parameters, profile.getJobLoad());
} catch (ServiceRegistryException e) {
throw new EncoderException("Unable to create a job", e);
}
}
use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.
the class EncodingProfileScanner method uninstall.
/**
* {@inheritDoc}
*
* @see org.apache.felix.fileinstall.ArtifactInstaller#uninstall(java.io.File)
*/
@Override
public void uninstall(File artifact) throws Exception {
for (Iterator<EncodingProfile> iter = profiles.values().iterator(); iter.hasNext(); ) {
EncodingProfile profile = iter.next();
if (artifact.equals(profile.getSource())) {
logger.info("Uninstalling profile {}", profile.getIdentifier());
iter.remove();
}
}
}
use of org.opencastproject.composer.api.EncodingProfile in project opencast by opencast.
the class EncodingProfileScanner method loadFromProperties.
/**
* Reads the profiles from the given set of properties.
*
* @param artifact
* the properties file
* @return the profiles found in the properties
*/
Map<String, EncodingProfile> loadFromProperties(File artifact) throws IOException {
// Format name
FileInputStream in = null;
Properties properties = new Properties();
try {
in = new FileInputStream(artifact);
properties.load(in);
} finally {
IOUtils.closeQuietly(in);
}
// Find list of formats in properties
List<String> profileNames = new ArrayList<>();
for (Object fullKey : properties.keySet()) {
String key = fullKey.toString();
if (key.startsWith(PROP_PREFIX) && key.endsWith(PROP_NAME)) {
int separatorLocation = fullKey.toString().lastIndexOf('.');
key = key.substring(PROP_PREFIX.length(), separatorLocation);
if (!profileNames.contains(key)) {
profileNames.add(key);
} else {
throw new ConfigurationException("Found duplicate definition for encoding profile '" + key + "'");
}
}
}
// Load the formats
Map<String, EncodingProfile> profiles = new HashMap<String, EncodingProfile>();
for (String profileId : profileNames) {
logger.debug("Enabling media format " + profileId);
EncodingProfile profile = loadProfile(profileId, properties, artifact);
profiles.put(profileId, profile);
}
return profiles;
}
Aggregations