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);
}
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;
}
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;
}
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();
}
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);
}
}
}
}
Aggregations