Search in sources :

Example 41 with TrackImpl

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

the class AnalyzeTracksWorkflowOperationHandler method start.

@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    logger.info("Running analyze-tracks workflow operation on workflow {}", workflowInstance.getId());
    final MediaPackage mediaPackage = workflowInstance.getMediaPackage();
    final String sourceFlavor = getConfig(workflowInstance, OPT_SOURCE_FLAVOR);
    Map<String, String> properties = new HashMap<>();
    final MediaPackageElementFlavor flavor = MediaPackageElementFlavor.parseFlavor(sourceFlavor);
    final Track[] tracks = mediaPackage.getTracks(flavor);
    if (tracks.length <= 0) {
        if (BooleanUtils.toBoolean(getConfig(workflowInstance, OPT_FAIL_NO_TRACK, "false"))) {
            throw new WorkflowOperationException("No matching tracks for flavor " + sourceFlavor);
        }
        logger.info("No tracks with specified flavors ({}) to analyse.", sourceFlavor);
        return createResult(mediaPackage, properties, Action.CONTINUE, 0);
    }
    List<Fraction> aspectRatios = getAspectRatio(getConfig(workflowInstance, OPT_VIDEO_ASPECT, ""));
    for (Track track : tracks) {
        final String varName = toVariableName(track.getFlavor());
        properties.put(varName + "_media", "true");
        properties.put(varName + "_video", Boolean.toString(track.hasVideo()));
        properties.put(varName + "_audio", Boolean.toString(track.hasAudio()));
        // Check resolution
        if (track.hasVideo()) {
            for (VideoStream video : ((TrackImpl) track).getVideo()) {
                // Set resolution variables
                properties.put(varName + "_resolution_x", video.getFrameWidth().toString());
                properties.put(varName + "_resolution_y", video.getFrameHeight().toString());
                Fraction trackAspect = Fraction.getReducedFraction(video.getFrameWidth(), video.getFrameHeight());
                properties.put(varName + "_aspect", trackAspect.toString());
                properties.put(varName + "_framerate", video.getFrameRate().toString());
                // Check if we should fall back to nearest defined aspect ratio
                if (!aspectRatios.isEmpty()) {
                    trackAspect = getNearestAspectRatio(trackAspect, aspectRatios);
                    properties.put(varName + "_aspect_snap", trackAspect.toString());
                }
            }
        }
    }
    logger.info("Finished analyze-tracks workflow operation adding the properties: {}", properties);
    return createResult(mediaPackage, properties, Action.CONTINUE, 0);
}
Also used : HashMap(java.util.HashMap) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) VideoStream(org.opencastproject.mediapackage.VideoStream) Fraction(org.apache.commons.lang3.math.Fraction) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Track(org.opencastproject.mediapackage.Track)

Example 42 with TrackImpl

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

the class ProbeResolutionWorkflowOperationHandlerTest method testStart.

@Test
public void testStart() throws MediaPackageException, WorkflowOperationException {
    MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    VideoStreamImpl videoStream = new VideoStreamImpl("234");
    videoStream.setFrameWidth(1280);
    videoStream.setFrameHeight(720);
    TrackImpl track = new TrackImpl();
    track.setFlavor(MediaPackageElementFlavor.parseFlavor("presenter/source"));
    track.addStream(videoStream);
    JobContext jobContext = EasyMock.createMock(JobContext.class);
    EasyMock.replay(jobContext);
    WorkflowOperationInstance operationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
    String[][] config = { { ProbeResolutionWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source" }, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "aspect", "1280x720,1280x700" }, { ProbeResolutionWorkflowOperationHandler.OPT_VAL_PREFIX + "aspect", "16/9" }, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "is_720", "1280x720,1280x700" }, { ProbeResolutionWorkflowOperationHandler.OPT_VAR_PREFIX + "is_1080", "1920x1080" } };
    Set<String> keys = new HashSet<>();
    for (String[] cfg : config) {
        keys.add(cfg[0]);
        EasyMock.expect(operationInstance.getConfiguration(cfg[0])).andReturn(cfg[1]).anyTimes();
    }
    EasyMock.expect(operationInstance.getConfigurationKeys()).andReturn(keys).anyTimes();
    EasyMock.replay(operationInstance);
    WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
    EasyMock.replay(workflowInstance);
    // With no matching track
    assertEquals(null, operationHandler.start(workflowInstance, jobContext).getProperties());
    // With matching track
    mediaPackage.add(track);
    WorkflowOperationResult workflowOperationResult = operationHandler.start(workflowInstance, jobContext);
    Map<String, String> properties = workflowOperationResult.getProperties();
    String[][] props = { { "presenter_source_aspect", "16/9" }, { "presenter_source_is_720", "true" }, { "presenter_source_is_1080", null } };
    for (String[] prop : props) {
        assertEquals(prop[1], properties.get(prop[0]));
    }
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JobContext(org.opencastproject.job.api.JobContext) HashSet(java.util.HashSet) Test(org.junit.Test)

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