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