Search in sources :

Example 1 with SilenceDetectionFailedException

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

the class SilenceDetectionServiceRemote method detect.

@Override
public Job detect(Track sourceTrack, Track[] referencedTracks) throws SilenceDetectionFailedException {
    HttpPost post = new HttpPost("/detect");
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    try {
        params.add(new BasicNameValuePair("track", MediaPackageElementParser.getAsXml(sourceTrack)));
        if (referencedTracks != null && referencedTracks.length > 0) {
            String referencedTracksXml = MediaPackageElementParser.getArrayAsXml(Arrays.asList(referencedTracks));
            params.add(new BasicNameValuePair("referenceTracks", referencedTracksXml));
        }
        post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
    } catch (Exception e) {
        throw new SilenceDetectionFailedException("Unable to assemble a remote silence detection request for track " + sourceTrack.getIdentifier());
    }
    HttpResponse response = null;
    try {
        response = getResponse(post);
        if (response != null) {
            String entity = EntityUtils.toString(response.getEntity());
            if (StringUtils.isNotEmpty(entity)) {
                Job resultJob = JobParser.parseJob(entity);
                logger.info("Start silence detection for track '{}' on remote silence detection service", sourceTrack.getIdentifier());
                return resultJob;
            }
        }
    } catch (Exception e) {
        throw new SilenceDetectionFailedException("Unable to run silence detection for track " + sourceTrack.getIdentifier() + " on remote silence detection service", e);
    } finally {
        closeConnection(response);
    }
    throw new SilenceDetectionFailedException("Unable to run silence detection for track " + sourceTrack.getIdentifier() + " on remote silence detection service");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Job(org.opencastproject.job.api.Job) SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException)

Example 2 with SilenceDetectionFailedException

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

the class SilenceDetectorTest method testMisconfiguration.

@Test
public void testMisconfiguration() throws Exception {
    if (this.skipTests)
        return;
    final URI trackUri = getResource("/nostreams.mp4");
    Properties props = new Properties();
    props.setProperty(SilenceDetectionProperties.SILENCE_PRE_LENGTH, "6000");
    props.setProperty(SilenceDetectionProperties.SILENCE_MIN_LENGTH, "4000");
    try {
        FFmpegSilenceDetector sd = init(trackUri, true, props);
        fail("Silence detection of media without audio should fail");
    } catch (SilenceDetectionFailedException e) {
    }
}
Also used : SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) Properties(java.util.Properties) SilenceDetectionProperties(org.opencastproject.silencedetection.impl.SilenceDetectionProperties) URI(java.net.URI) Test(org.junit.Test)

Example 3 with SilenceDetectionFailedException

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

the class SilenceDetectorTest method testNoAudio.

@Test
public void testNoAudio() throws Exception {
    if (this.skipTests)
        return;
    final URI trackUri = getResource("/nostreams.mp4");
    try {
        FFmpegSilenceDetector sd = init(trackUri, false);
        fail("Silence detection of media without audio should fail");
    } catch (SilenceDetectionFailedException e) {
    }
}
Also used : SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) URI(java.net.URI) Test(org.junit.Test)

Example 4 with SilenceDetectionFailedException

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

the class SilenceDetectionServiceImpl method detect.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.silencedetection.api.SilenceDetectionService#detect(
 * org.opencastproject.mediapackage.Track, org.opencastproject.mediapackage.Track[])
 */
@Override
public Job detect(Track sourceTrack, Track[] referenceTracks) throws SilenceDetectionFailedException {
    try {
        if (sourceTrack == null) {
            throw new SilenceDetectionFailedException("Source track is null!");
        }
        List<String> arguments = new LinkedList<String>();
        // put source track as job argument
        arguments.add(0, MediaPackageElementParser.getAsXml(sourceTrack));
        // put reference tracks as second argument
        if (referenceTracks != null) {
            arguments.add(1, MediaPackageElementParser.getArrayAsXml(Arrays.asList(referenceTracks)));
        }
        return serviceRegistry.createJob(getJobType(), Operation.SILENCE_DETECTION.toString(), arguments, jobload);
    } catch (ServiceRegistryException ex) {
        throw new SilenceDetectionFailedException("Unable to create job! " + ex.getMessage());
    } catch (MediaPackageException ex) {
        throw new SilenceDetectionFailedException("Unable to serialize track!");
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) LinkedList(java.util.LinkedList) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 5 with SilenceDetectionFailedException

use of org.opencastproject.silencedetection.api.SilenceDetectionFailedException 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

SilenceDetectionFailedException (org.opencastproject.silencedetection.api.SilenceDetectionFailedException)6 URI (java.net.URI)3 Test (org.junit.Test)2 Job (org.opencastproject.job.api.Job)2 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)2 Track (org.opencastproject.mediapackage.Track)2 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)2 SmilException (org.opencastproject.smil.api.SmilException)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 HttpResponse (org.apache.http.HttpResponse)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1 HttpPost (org.apache.http.client.methods.HttpPost)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 Catalog (org.opencastproject.mediapackage.Catalog)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageElementBuilder (org.opencastproject.mediapackage.MediaPackageElementBuilder)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1