Search in sources :

Example 11 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class ImageWorkflowOperationHandler method configure.

/**
 * Get and parse the configuration options.
 */
private Cfg configure(MediaPackage mp, WorkflowOperationInstance woi) throws WorkflowOperationException {
    final List<EncodingProfile> profiles = getOptConfig(woi, OPT_PROFILES).toStream().bind(asList.toFn()).map(fetchProfile(composerService)).toList();
    final List<String> targetImageTags = getOptConfig(woi, OPT_TARGET_TAGS).toStream().bind(asList.toFn()).toList();
    final Opt<MediaPackageElementFlavor> targetImageFlavor = getOptConfig(woi, OPT_TARGET_FLAVOR).map(MediaPackageElementFlavor.parseFlavor.toFn());
    final List<Track> sourceTracks;
    {
        // get the source flavors
        final Stream<MediaPackageElementFlavor> sourceFlavors = getOptConfig(woi, OPT_SOURCE_FLAVORS).toStream().bind(Strings.splitCsv).append(getOptConfig(woi, OPT_SOURCE_FLAVOR)).map(MediaPackageElementFlavor.parseFlavor.toFn());
        // get the source tags
        final Stream<String> sourceTags = getOptConfig(woi, OPT_SOURCE_TAGS).toStream().bind(Strings.splitCsv);
        // fold both into a selector
        final TrackSelector trackSelector = sourceTags.apply(tagFold(sourceFlavors.apply(flavorFold(new TrackSelector()))));
        // select the tracks based on source flavors and tags and skip those that don't have video
        sourceTracks = $(trackSelector.select(mp, true)).filter(Filters.hasVideo.toFn()).each(new Fx<Track>() {

            @Override
            public void apply(Track track) {
                if (track.getDuration() == null) {
                    chuck(new WorkflowOperationException(format("Track %s cannot tell its duration", track)));
                }
            }
        }).toList();
    }
    final List<MediaPosition> positions = parsePositions(getConfig(woi, OPT_POSITIONS));
    final long endMargin = getOptConfig(woi, OPT_END_MARGIN).bind(Strings.toLong).getOr(END_MARGIN_DEFAULT);
    // 
    return new Cfg(sourceTracks, positions, profiles, targetImageFlavor, targetImageTags, getTargetBaseNameFormat(woi, OPT_TARGET_BASE_NAME_FORMAT_SECOND), getTargetBaseNameFormat(woi, OPT_TARGET_BASE_NAME_FORMAT_PERCENT), endMargin);
}
Also used : TrackSelector(org.opencastproject.mediapackage.selector.TrackSelector) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Fx(com.entwinemedia.fn.Fx) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Stream(com.entwinemedia.fn.Stream) Track(org.opencastproject.mediapackage.Track)

Example 12 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method createVideoFromImage.

private Track createVideoFromImage(Attachment image, double time, List<MediaPackageElement> elementsToClean) throws EncoderException, MediaPackageException, WorkflowOperationException, NotFoundException {
    Job imageToVideoJob = composerService.imageToVideo(image, IMAGE_MOVIE_PROFILE, time);
    if (!waitForStatus(imageToVideoJob).isSuccess())
        throw new WorkflowOperationException("Image to video job did not complete successfully");
    // Get the latest copy
    try {
        imageToVideoJob = serviceRegistry.getJob(imageToVideoJob.getId());
    } catch (ServiceRegistryException e) {
        throw new WorkflowOperationException(e);
    }
    Track imageVideo = (Track) MediaPackageElementParser.getFromXml(imageToVideoJob.getPayload());
    elementsToClean.add(imageVideo);
    return imageVideo;
}
Also used : WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Job(org.opencastproject.job.api.Job) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Track(org.opencastproject.mediapackage.Track)

Example 13 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method mkTrackSelector.

private TrackSelector mkTrackSelector(Opt<String> flavor) throws WorkflowOperationException {
    final TrackSelector s = new TrackSelector();
    for (String fs : flavor) {
        try {
            final MediaPackageElementFlavor f = MediaPackageElementFlavor.parseFlavor(fs);
            s.addFlavor(f);
            s.addFlavor(deriveAudioFlavor(f));
        } catch (IllegalArgumentException e) {
            throw new WorkflowOperationException("Flavor '" + fs + "' is malformed");
        }
    }
    return s;
}
Also used : TrackSelector(org.opencastproject.mediapackage.selector.TrackSelector) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Example 14 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method mux.

/**
 * Mux a video and an audio track. Add the result to media package <code>mediaPackage</code> with the same flavor as
 * the <code>video</code>.
 *
 * @return the mux job's queue time
 */
protected long mux(MediaPackage mediaPackage, Track video, Track audio, List<MediaPackageElement> elementsToClean) throws EncoderException, MediaPackageException, WorkflowOperationException, NotFoundException, ServiceRegistryException, IOException {
    logger.debug("Muxing video {} and audio {}", video.getURI(), audio.getURI());
    Job muxJob = composerService.mux(video, audio, PrepareAVWorkflowOperationHandler.MUX_AV_PROFILE);
    if (!waitForStatus(muxJob).isSuccess()) {
        throw new WorkflowOperationException("Muxing of audio " + audio + " and video " + video + " failed");
    }
    muxJob = serviceRegistry.getJob(muxJob.getId());
    final Track muxed = (Track) MediaPackageElementParser.getFromXml(muxJob.getPayload());
    if (muxed == null) {
        throw new WorkflowOperationException("Muxed job " + muxJob + " returned no payload!");
    }
    muxed.setFlavor(video.getFlavor());
    muxed.setURI(workspace.moveTo(muxed.getURI(), mediaPackage.getIdentifier().toString(), muxed.getIdentifier(), FilenameUtils.getName(video.getURI().toString())));
    elementsToClean.add(audio);
    mediaPackage.remove(audio);
    elementsToClean.add(video);
    mediaPackage.remove(video);
    mediaPackage.add(muxed);
    return muxJob.getQueueTime();
}
Also used : WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Job(org.opencastproject.job.api.Job) Track(org.opencastproject.mediapackage.Track)

Example 15 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method start.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
 *      JobContext)
 */
@Override
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    logger.debug("Running partial import workflow operation on workflow {}", workflowInstance.getId());
    List<MediaPackageElement> elementsToClean = new ArrayList<MediaPackageElement>();
    try {
        return concat(workflowInstance.getMediaPackage(), workflowInstance.getCurrentOperation(), elementsToClean);
    } catch (Exception e) {
        throw new WorkflowOperationException(e);
    } finally {
        for (MediaPackageElement elem : elementsToClean) {
            try {
                workspace.delete(elem.getURI());
            } catch (Exception e) {
                logger.warn("Unable to delete element {}: {}", elem, e);
            }
        }
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) EncoderException(org.opencastproject.composer.api.EncoderException)

Aggregations

WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)103 MediaPackage (org.opencastproject.mediapackage.MediaPackage)57 Job (org.opencastproject.job.api.Job)47 Track (org.opencastproject.mediapackage.Track)34 IOException (java.io.IOException)31 URI (java.net.URI)28 ArrayList (java.util.ArrayList)28 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)28 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)28 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)27 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)27 NotFoundException (org.opencastproject.util.NotFoundException)27 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)18 HashMap (java.util.HashMap)17 File (java.io.File)16 InputStream (java.io.InputStream)15 Attachment (org.opencastproject.mediapackage.Attachment)15 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)15 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)13 HashSet (java.util.HashSet)12