Search in sources :

Example 1 with MediaSegments

use of org.opencastproject.silencedetection.api.MediaSegments in project opencast by opencast.

the class SilenceDetectionServiceImpl method process.

@Override
protected String process(Job job) throws SilenceDetectionFailedException, SmilException, MediaPackageException {
    if (Operation.SILENCE_DETECTION.toString().equals(job.getOperation())) {
        // get source track
        String sourceTrackXml = StringUtils.trimToNull(job.getArguments().get(0));
        if (sourceTrackXml == null) {
            throw new SilenceDetectionFailedException("Track not set!");
        }
        Track sourceTrack = (Track) MediaPackageElementParser.getFromXml(sourceTrackXml);
        // run detection on source track
        MediaSegments segments = runDetection(sourceTrack);
        // get reference tracks if any
        List<Track> referenceTracks = null;
        if (job.getArguments().size() > 1) {
            String referenceTracksXml = StringUtils.trimToNull(job.getArguments().get(1));
            if (referenceTracksXml != null) {
                referenceTracks = (List<Track>) MediaPackageElementParser.getArrayFromXml(referenceTracksXml);
            }
        }
        if (referenceTracks == null) {
            referenceTracks = Arrays.asList(sourceTrack);
        }
        // create smil XML as result
        try {
            return generateSmil(segments, referenceTracks).toXML();
        } catch (Exception ex) {
            throw new SmilException("Failed to create smil document.", ex);
        }
    }
    throw new SilenceDetectionFailedException("Can't handle this operation: " + job.getOperation());
}
Also used : SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) MediaSegments(org.opencastproject.silencedetection.api.MediaSegments) SmilException(org.opencastproject.smil.api.SmilException) Track(org.opencastproject.mediapackage.Track) SmilException(org.opencastproject.smil.api.SmilException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException)

Aggregations

MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 Track (org.opencastproject.mediapackage.Track)1 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)1 MediaSegments (org.opencastproject.silencedetection.api.MediaSegments)1 SilenceDetectionFailedException (org.opencastproject.silencedetection.api.SilenceDetectionFailedException)1 SmilException (org.opencastproject.smil.api.SmilException)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1