Search in sources :

Example 11 with TrackImpl

use of org.opencastproject.mediapackage.track.TrackImpl in project opencast by opencast.

the class NormalizeAudioWorkflowOperationHandlerTest method testAudioVideo.

@Test
public void testAudioVideo() throws Exception {
    operationInstance.setConfiguration("source-tags", "");
    operationInstance.setConfiguration("source-flavor", "*/video-audio");
    operationInstance.setConfiguration("source-flavors", "");
    operationInstance.setConfiguration("target-flavor", "*/normalized");
    operationInstance.setConfiguration("target-tags", "norm");
    operationInstance.setConfiguration("force-transcode", "false");
    operationInstance.setConfiguration("target-decibel", "-30");
    WorkflowOperationResult result = operationHandler.start(instance, null);
    Assert.assertEquals(Action.CONTINUE, result.getAction());
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 4, result.getMediaPackage().getElements().length);
    Track[] tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "normalized"));
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
    Assert.assertTrue(tracks[0].containsTag("norm"));
    TrackImpl audioVideo = (TrackImpl) tracks[0];
    Assert.assertEquals(-30f, audioVideo.getAudio().get(0).getRmsLevDb().floatValue(), 0.001d);
    tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "video-audio"));
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
    audioVideo = (TrackImpl) tracks[0];
    Assert.assertNull(audioVideo.getAudio().get(0).getRmsLevDb());
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 12 with TrackImpl

use of org.opencastproject.mediapackage.track.TrackImpl in project opencast by opencast.

the class NormalizeAudioWorkflowOperationHandlerTest method testAudio.

@Test
public void testAudio() throws Exception {
    operationInstance.setConfiguration("source-tags", "");
    operationInstance.setConfiguration("source-flavor", "*/audio");
    operationInstance.setConfiguration("source-flavors", "");
    operationInstance.setConfiguration("target-flavor", "*/normalized");
    operationInstance.setConfiguration("target-tags", "norm");
    operationInstance.setConfiguration("force-transcode", "true");
    operationInstance.setConfiguration("target-decibel", "-30");
    WorkflowOperationResult result = operationHandler.start(instance, null);
    Assert.assertEquals(Action.CONTINUE, result.getAction());
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 4, result.getMediaPackage().getElements().length);
    Track[] tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "normalized"));
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
    Assert.assertTrue(tracks[0].containsTag("norm"));
    TrackImpl audioVideo = (TrackImpl) tracks[0];
    Assert.assertEquals(-30f, audioVideo.getAudio().get(0).getRmsLevDb().floatValue(), 0.001d);
    tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "audio"));
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
    audioVideo = (TrackImpl) tracks[0];
    Assert.assertNull(audioVideo.getAudio().get(0).getRmsLevDb());
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 13 with TrackImpl

use of org.opencastproject.mediapackage.track.TrackImpl in project opencast by opencast.

the class NormalizeAudioWorkflowOperationHandlerTest method testAudioContainer.

@Test
public void testAudioContainer() throws Exception {
    operationInstance.setConfiguration("source-tags", "");
    operationInstance.setConfiguration("source-flavor", "*/container-audio");
    operationInstance.setConfiguration("source-flavors", "");
    operationInstance.setConfiguration("target-flavor", "*/normalized");
    operationInstance.setConfiguration("target-tags", "norm");
    operationInstance.setConfiguration("force-transcode", "true");
    operationInstance.setConfiguration("target-decibel", "-30");
    WorkflowOperationResult result = operationHandler.start(instance, null);
    Assert.assertEquals(Action.CONTINUE, result.getAction());
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 4, result.getMediaPackage().getElements().length);
    Track[] tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "normalized"));
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
    Assert.assertTrue(tracks[0].containsTag("norm"));
    TrackImpl audioVideo = (TrackImpl) tracks[0];
    Assert.assertEquals(-30f, audioVideo.getAudio().get(0).getRmsLevDb().floatValue(), 0.001d);
    tracks = result.getMediaPackage().getTracks(new MediaPackageElementFlavor("presentation", "container-audio"));
    Assert.assertEquals("Resulting mediapackage has the wrong number of tracks", 1, tracks.length);
    audioVideo = (TrackImpl) tracks[0];
    Assert.assertNull(audioVideo.getAudio().get(0).getRmsLevDb());
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 14 with TrackImpl

use of org.opencastproject.mediapackage.track.TrackImpl in project opencast by opencast.

the class SmilServiceImplTest method testAddClip.

/**
 * Test of addClip(s) methods, of class SmilServiceImpl.
 */
@Test
public void testAddClip() throws Exception {
    TrackImpl videoTrack = new TrackImpl();
    videoTrack.setIdentifier("track-1");
    videoTrack.setFlavor(new MediaPackageElementFlavor("source", "presentation"));
    videoTrack.setURI(new URI("http://hostname/video.mp4"));
    videoTrack.addStream(new VideoStreamImpl());
    videoTrack.setDuration(1000000000000L);
    SmilResponse smilResponse = smilService.createNewSmil();
    smilResponse = smilService.addParallel(smilResponse.getSmil());
    SmilMediaContainer par = (SmilMediaContainer) smilResponse.getEntity();
    // add video track into parallel element
    smilResponse = smilService.addClip(smilResponse.getSmil(), par.getId(), videoTrack, 1000L, 1000000L);
    // logger.info(smilResponse.getSmil().toXML());
    SmilMediaObject media = null;
    for (SmilObject entity : smilResponse.getEntities()) {
        if (entity instanceof SmilMediaObject) {
            media = (SmilMediaObject) entity;
            break;
        }
    }
    assertNotNull(media);
    assertEquals(media.getId(), ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0)).getElements().get(0).getId());
    assertTrue(media instanceof SmilMediaVideoImpl);
    assertSame(((SmilMediaElement) media).getMediaType(), SmilMediaElement.MediaType.VIDEO);
    // 1000 milliseconds = 1 second
    assertEquals(1000L, ((SmilMediaElement) media).getClipBeginMS());
    // duration is 1000000 milliseconds = 1000 soconds
    // start + duration = 1s + 1000s = 1001s
    assertEquals(1001000L, ((SmilMediaElement) media).getClipEndMS());
    TrackImpl audioTrack = new TrackImpl();
    audioTrack.setIdentifier("track-2");
    audioTrack.setFlavor(new MediaPackageElementFlavor("source", "presenter"));
    audioTrack.setURI(new URI("http://hostname/audio.mp3"));
    audioTrack.addStream(new AudioStreamImpl());
    audioTrack.setDuration(1000000000000L);
    // add audio track into parallel element
    smilResponse = smilService.addClip(smilResponse.getSmil(), par.getId(), audioTrack, 1000L, 1000000L);
    // logger.info(smilResponse.getSmil().toXML());
    media = null;
    for (SmilObject entity : smilResponse.getEntities()) {
        if (entity instanceof SmilMediaObject) {
            media = (SmilMediaObject) entity;
            break;
        }
    }
    assertNotNull(media);
    assertEquals(media.getId(), ((SmilMediaContainer) smilResponse.getSmil().getBody().getMediaElements().get(0)).getElements().get(1).getId());
    assertTrue(media instanceof SmilMediaAudioImpl);
    assertSame(((SmilMediaElement) media).getMediaType(), SmilMediaElement.MediaType.AUDIO);
    // 1000 milliseconds = 1 second
    assertEquals(1000L, ((SmilMediaElement) media).getClipBeginMS());
    // duration is 1000000 milliseconds = 1000 soconds
    // start + duration = 1s + 1000s = 1001s
    assertEquals(1001000L, ((SmilMediaElement) media).getClipEndMS());
    // add new par
    smilResponse = smilService.addParallel(smilResponse.getSmil());
    par = (SmilMediaContainer) smilResponse.getEntity();
    // add tracks (as array) to par
    smilResponse = smilService.addClips(smilResponse.getSmil(), par.getId(), new Track[] { audioTrack, videoTrack }, 15000L, 1000L);
    // logger.info(smilResponse.getSmil().toXML());
    assertSame(2, smilResponse.getEntitiesCount());
    assertTrue(smilResponse.getEntities()[0] instanceof SmilMediaElement);
    // get audio element
    SmilMediaElement mediaElement = (SmilMediaElement) smilResponse.getEntities()[0];
    assertTrue(mediaElement.getMediaType() == SmilMediaElement.MediaType.AUDIO);
    // 15000ms = 15s
    assertEquals(15000L, mediaElement.getClipBeginMS());
    // start + duration = 15s + 1s = 16s
    assertEquals(16000L, mediaElement.getClipEndMS());
    // get video element
    mediaElement = (SmilMediaElement) smilResponse.getEntities()[1];
    assertTrue(mediaElement.getMediaType() == SmilMediaElement.MediaType.VIDEO);
    // 15000ms = 15s
    assertEquals(15000L, mediaElement.getClipBeginMS());
    // start + duration = 15s + 1s = 16s
    assertEquals(16000L, mediaElement.getClipEndMS());
}
Also used : SmilMediaVideoImpl(org.opencastproject.smil.entity.media.element.SmilMediaVideoImpl) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) SmilObject(org.opencastproject.smil.entity.api.SmilObject) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilMediaAudioImpl(org.opencastproject.smil.entity.media.element.SmilMediaAudioImpl) SmilMediaObject(org.opencastproject.smil.entity.media.api.SmilMediaObject) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) Track(org.opencastproject.mediapackage.Track) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer) Test(org.junit.Test)

Example 15 with TrackImpl

use of org.opencastproject.mediapackage.track.TrackImpl in project opencast by opencast.

the class SoxServiceImpl method process.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
 */
@Override
protected String process(Job job) throws Exception {
    Operation op = null;
    String operation = job.getOperation();
    List<String> arguments = job.getArguments();
    try {
        op = Operation.valueOf(operation);
        TrackImpl audioTrack = null;
        final String serialized;
        switch(op) {
            case Analyze:
                audioTrack = (TrackImpl) MediaPackageElementParser.getFromXml(arguments.get(0));
                serialized = analyze(job, audioTrack).map(MediaPackageElementParser.<Track>getAsXml()).getOrElse("");
                break;
            case Normalize:
                audioTrack = (TrackImpl) MediaPackageElementParser.getFromXml(arguments.get(0));
                Float targetRmsLevDb = new Float(arguments.get(1));
                serialized = normalize(job, audioTrack, targetRmsLevDb).map(MediaPackageElementParser.<Track>getAsXml()).getOrElse("");
                break;
            default:
                throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
        }
        return serialized;
    } catch (IllegalArgumentException e) {
        throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
    } catch (Exception e) {
        throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
    }
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) SoxException(org.opencastproject.sox.api.SoxException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException)

Aggregations

TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)42 Test (org.junit.Test)21 Track (org.opencastproject.mediapackage.Track)20 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)17 URI (java.net.URI)14 MediaPackage (org.opencastproject.mediapackage.MediaPackage)13 VideoStreamImpl (org.opencastproject.mediapackage.track.VideoStreamImpl)12 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)11 Job (org.opencastproject.job.api.Job)9 ArrayList (java.util.ArrayList)7 AudioStream (org.opencastproject.mediapackage.AudioStream)7 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)7 File (java.io.File)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 VideoStream (org.opencastproject.mediapackage.VideoStream)6 InputStream (java.io.InputStream)5 SmilResponse (org.opencastproject.smil.api.SmilResponse)5 NotFoundException (org.opencastproject.util.NotFoundException)5 FileInputStream (java.io.FileInputStream)4