Search in sources :

Example 21 with EncoderException

use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.

the class ComposerServiceImpl method composite.

/**
 * {@inheritDoc}
 */
@Override
public Job composite(Dimension compositeTrackSize, Option<LaidOutElement<Track>> upperTrack, LaidOutElement<Track> lowerTrack, Option<LaidOutElement<Attachment>> watermark, String profileId, String background) throws EncoderException, MediaPackageException {
    List<String> arguments = new ArrayList<>(9);
    arguments.add(PROFILE_ID_INDEX, profileId);
    arguments.add(LOWER_TRACK_INDEX, MediaPackageElementParser.getAsXml(lowerTrack.getElement()));
    arguments.add(LOWER_TRACK_LAYOUT_INDEX, Serializer.json(lowerTrack.getLayout()).toJson());
    if (upperTrack.isNone()) {
        arguments.add(UPPER_TRACK_INDEX, NOT_AVAILABLE);
        arguments.add(UPPER_TRACK_LAYOUT_INDEX, NOT_AVAILABLE);
    } else {
        arguments.add(UPPER_TRACK_INDEX, MediaPackageElementParser.getAsXml(upperTrack.get().getElement()));
        arguments.add(UPPER_TRACK_LAYOUT_INDEX, Serializer.json(upperTrack.get().getLayout()).toJson());
    }
    arguments.add(COMPOSITE_TRACK_SIZE_INDEX, Serializer.json(compositeTrackSize).toJson());
    arguments.add(BACKGROUND_COLOR_INDEX, background);
    if (watermark.isSome()) {
        LaidOutElement<Attachment> watermarkLaidOutElement = watermark.get();
        arguments.add(WATERMARK_INDEX, MediaPackageElementParser.getAsXml(watermarkLaidOutElement.getElement()));
        arguments.add(WATERMARK_LAYOUT_INDEX, Serializer.json(watermarkLaidOutElement.getLayout()).toJson());
    }
    try {
        final EncodingProfile profile = profileScanner.getProfile(profileId);
        return serviceRegistry.createJob(JOB_TYPE, Operation.Composite.toString(), arguments, profile.getJobLoad());
    } catch (ServiceRegistryException e) {
        throw new EncoderException("Unable to create composite job", e);
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) ArrayList(java.util.ArrayList) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) Attachment(org.opencastproject.mediapackage.Attachment) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 22 with EncoderException

use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.

the class ComposerServiceImpl method image.

@Override
public Job image(Track sourceTrack, String profileId, Map<String, String> properties) throws EncoderException, MediaPackageException {
    if (sourceTrack == null)
        throw new IllegalArgumentException("SourceTrack cannot be null");
    List<String> arguments = new ArrayList<String>();
    arguments.add(profileId);
    arguments.add(MediaPackageElementParser.getAsXml(sourceTrack));
    arguments.add(Boolean.FALSE.toString());
    arguments.add(getPropertiesAsString(properties));
    try {
        final EncodingProfile profile = profileScanner.getProfile(profileId);
        return serviceRegistry.createJob(JOB_TYPE, Operation.Image.toString(), arguments, 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 23 with EncoderException

use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.

the class ComposerServiceImpl method inspect.

protected Job inspect(Job job, URI workspaceURI) throws EncoderException {
    Job inspectionJob;
    try {
        inspectionJob = inspectionService.inspect(workspaceURI);
    } catch (MediaInspectionException e) {
        incident().recordJobCreationIncident(job, e);
        throw new EncoderException("Media inspection of " + workspaceURI + " failed", e);
    }
    JobBarrier barrier = new JobBarrier(job, serviceRegistry, inspectionJob);
    if (!barrier.waitForJobs().isSuccess()) {
        throw new EncoderException("Media inspection of " + workspaceURI + " failed");
    }
    return inspectionJob;
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier)

Example 24 with EncoderException

use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.

the class ComposerServiceImpl method convertImage.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.composer.api.ComposerService#convertImage(org.opencastproject.mediapackage.Attachment,
 *      java.lang.String)
 */
@Override
public Job convertImage(Attachment image, String profileId) throws EncoderException, MediaPackageException {
    if (image == null)
        throw new IllegalArgumentException("Source image cannot be null");
    String[] parameters = new String[2];
    parameters[0] = profileId;
    parameters[1] = MediaPackageElementParser.getAsXml(image);
    try {
        final EncodingProfile profile = profileScanner.getProfile(profileId);
        return serviceRegistry.createJob(JOB_TYPE, Operation.ImageConversion.toString(), Arrays.asList(parameters), profile.getJobLoad());
    } catch (ServiceRegistryException e) {
        throw new EncoderException("Unable to create a job", e);
    }
}
Also used : EncoderException(org.opencastproject.composer.api.EncoderException) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 25 with EncoderException

use of org.opencastproject.composer.api.EncoderException in project opencast by opencast.

the class ComposerServiceImpl method composite.

private Option<Track> composite(Job job, Dimension compositeTrackSize, LaidOutElement<Track> lowerLaidOutElement, Option<LaidOutElement<Track>> upperLaidOutElement, Option<LaidOutElement<Attachment>> watermarkOption, String profileId, String backgroundColor) throws EncoderException, MediaPackageException {
    // Get the encoding profile
    final EncodingProfile profile = getProfile(job, profileId);
    // Create the engine
    final EncoderEngine encoderEngine = getEncoderEngine();
    final String targetTrackId = idBuilder.createNew().toString();
    Option<File> upperVideoFile = Option.none();
    try {
        // Get the tracks and make sure they exist
        final File lowerVideoFile = loadTrackIntoWorkspace(job, "lower video", lowerLaidOutElement.getElement());
        if (upperLaidOutElement.isSome()) {
            upperVideoFile = Option.option(loadTrackIntoWorkspace(job, "upper video", upperLaidOutElement.get().getElement()));
        }
        File watermarkFile = null;
        if (watermarkOption.isSome()) {
            try {
                watermarkFile = workspace.get(watermarkOption.get().getElement().getURI());
            } catch (NotFoundException e) {
                incident().recordFailure(job, WORKSPACE_GET_NOT_FOUND, e, getWorkspaceMediapackageParams("watermark image", watermarkOption.get().getElement()), NO_DETAILS);
                throw new EncoderException("Requested watermark image " + watermarkOption.get().getElement() + " is not found");
            } catch (IOException e) {
                incident().recordFailure(job, WORKSPACE_GET_IO_EXCEPTION, e, getWorkspaceMediapackageParams("watermark image", watermarkOption.get().getElement()), NO_DETAILS);
                throw new EncoderException("Unable to access right watermark image " + watermarkOption.get().getElement());
            }
            if (upperLaidOutElement.isSome()) {
                logger.info("Composing lower video track {} {} and upper video track {} {} including watermark {} {} into {}", lowerLaidOutElement.getElement().getIdentifier(), lowerLaidOutElement.getElement().getURI(), upperLaidOutElement.get().getElement().getIdentifier(), upperLaidOutElement.get().getElement().getURI(), watermarkOption.get().getElement().getIdentifier(), watermarkOption.get().getElement().getURI(), targetTrackId);
            } else {
                logger.info("Composing video track {} {} including watermark {} {} into {}", lowerLaidOutElement.getElement().getIdentifier(), lowerLaidOutElement.getElement().getURI(), watermarkOption.get().getElement().getIdentifier(), watermarkOption.get().getElement().getURI(), targetTrackId);
            }
        } else {
            if (upperLaidOutElement.isSome()) {
                logger.info("Composing lower video track {} {} and upper video track {} {} into {}", lowerLaidOutElement.getElement().getIdentifier(), lowerLaidOutElement.getElement().getURI(), upperLaidOutElement.get().getElement().getIdentifier(), upperLaidOutElement.get().getElement().getURI(), targetTrackId);
            } else {
                logger.info("Composing video track {} {} into {}", lowerLaidOutElement.getElement().getIdentifier(), lowerLaidOutElement.getElement().getURI(), targetTrackId);
            }
        }
        // Creating video filter command
        final String compositeCommand = buildCompositeCommand(compositeTrackSize, lowerLaidOutElement, upperLaidOutElement, upperVideoFile, watermarkOption, watermarkFile, backgroundColor);
        Map<String, String> properties = new HashMap<>();
        properties.put(EncoderEngine.CMD_SUFFIX + ".compositeCommand", compositeCommand);
        List<File> output;
        try {
            Map<String, File> source = new HashMap<>();
            if (upperVideoFile.isSome()) {
                source.put("audio", upperVideoFile.get());
            }
            source.put("video", lowerVideoFile);
            output = encoderEngine.process(source, profile, properties);
        } catch (EncoderException e) {
            Map<String, String> params = new HashMap<>();
            if (upperLaidOutElement.isSome()) {
                params.put("upper", upperLaidOutElement.get().getElement().getURI().toString());
            }
            params.put("lower", lowerLaidOutElement.getElement().getURI().toString());
            if (watermarkFile != null)
                params.put("watermark", watermarkOption.get().getElement().getURI().toString());
            params.put("profile", profile.getIdentifier());
            params.put("properties", properties.toString());
            incident().recordFailure(job, COMPOSITE_FAILED, e, params, detailsFor(e, encoderEngine));
            throw e;
        } finally {
            activeEncoder.remove(encoderEngine);
        }
        // We expect one file as output
        if (output.size() != 1) {
            // Ensure we do not leave behind old files in the workspace
            for (File file : output) {
                FileUtils.deleteQuietly(file);
            }
            throw new EncoderException("Composite does not support multiple files as output");
        }
        // Put the file in the workspace
        URI workspaceURI = putToCollection(job, output.get(0), "compound 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);
    } catch (Exception e) {
        if (upperLaidOutElement.isSome()) {
            logger.warn("Error composing {}  and {}: {}", lowerLaidOutElement.getElement(), upperLaidOutElement.get().getElement(), getStackTrace(e));
        } else {
            logger.warn("Error composing {}: {}", lowerLaidOutElement.getElement(), getStackTrace(e));
        }
        if (e instanceof EncoderException) {
            throw (EncoderException) e;
        } else {
            throw new EncoderException(e);
        }
    }
}
Also used : HashMap(java.util.HashMap) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) EncoderException(org.opencastproject.composer.api.EncoderException) 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)

Aggregations

EncoderException (org.opencastproject.composer.api.EncoderException)41 Job (org.opencastproject.job.api.Job)26 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)19 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)19 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)16 URI (java.net.URI)12 HashMap (java.util.HashMap)12 Track (org.opencastproject.mediapackage.Track)12 File (java.io.File)11 NotFoundException (org.opencastproject.util.NotFoundException)11 HttpResponse (org.apache.http.HttpResponse)10 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)10 HttpPost (org.apache.http.client.methods.HttpPost)10 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)10 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)10 Map (java.util.Map)9 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)7 LinkedList (java.util.LinkedList)6 POST (javax.ws.rs.POST)6