Search in sources :

Example 26 with EncodingProfile

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;
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) EncodingProfile(org.opencastproject.composer.api.EncodingProfile)

Example 27 with EncodingProfile

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);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) URI(java.net.URI) EncoderException(org.opencastproject.composer.api.EncoderException) Job(org.opencastproject.job.api.Job) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) Track(org.opencastproject.mediapackage.Track)

Example 28 with EncodingProfile

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);
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) ArrayList(java.util.ArrayList) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 29 with EncodingProfile

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();
        }
    }
}
Also used : EncodingProfile(org.opencastproject.composer.api.EncodingProfile)

Example 30 with EncodingProfile

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;
}
Also used : ConfigurationException(org.opencastproject.util.ConfigurationException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

EncodingProfile (org.opencastproject.composer.api.EncodingProfile)38 EncoderException (org.opencastproject.composer.api.EncoderException)16 Track (org.opencastproject.mediapackage.Track)15 HashMap (java.util.HashMap)14 Job (org.opencastproject.job.api.Job)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 Map (java.util.Map)10 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)10 File (java.io.File)9 URI (java.net.URI)8 IOException (java.io.IOException)7 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)7 Attachment (org.opencastproject.mediapackage.Attachment)6 MediaPackage (org.opencastproject.mediapackage.MediaPackage)6 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)6 NotFoundException (org.opencastproject.util.NotFoundException)6 LinkedList (java.util.LinkedList)5 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)5