Search in sources :

Example 11 with Dimension

use of org.opencastproject.composer.layout.Dimension in project opencast by opencast.

the class ComposerServiceTest method testConcatWithFrameRate.

/**
 * Test method for {@link ComposerServiceImpl#concat(String, Dimension, float, Track...)}
 */
@Test
public void testConcatWithFrameRate() throws Exception {
    Dimension outputDimension = new Dimension(500, 500);
    Job concat = composerService.concat("concat.work", outputDimension, 20.0f, sourceVideoTrack, sourceVideoTrack);
    Track concatTrack = (Track) MediaPackageElementParser.getFromXml(concat.getPayload());
    Assert.assertNotNull(concatTrack);
    inspectedTrack.setIdentifier(concatTrack.getIdentifier());
    inspectedTrack.setMimeType(MimeType.mimeType("video", "mp4"));
    Assert.assertEquals(inspectedTrack, concatTrack);
}
Also used : Dimension(org.opencastproject.composer.layout.Dimension) Job(org.opencastproject.job.api.Job) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 12 with Dimension

use of org.opencastproject.composer.layout.Dimension in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method determineDimension.

/**
 * Determine the largest dimension of the given list of tracks
 *
 * @param tracks
 *          the list of tracks
 * @param forceDivisible
 *          Whether to enforce the track's dimension to be divisible by two
 * @return the largest dimension from the list of track
 */
private Dimension determineDimension(List<Track> tracks, boolean forceDivisible) {
    Tuple<Track, Dimension> trackDimension = getLargestTrack(tracks);
    if (trackDimension == null)
        return null;
    if (forceDivisible && (trackDimension.getB().getHeight() % 2 != 0 || trackDimension.getB().getWidth() % 2 != 0)) {
        Dimension scaledDimension = Dimension.dimension((trackDimension.getB().getWidth() / 2) * 2, (trackDimension.getB().getHeight() / 2) * 2);
        logger.info("Determined output dimension {} scaled down from {} for track {}", scaledDimension, trackDimension.getB(), trackDimension.getA());
        return scaledDimension;
    } else {
        logger.info("Determined output dimension {} for track {}", trackDimension.getB(), trackDimension.getA());
        return trackDimension.getB();
    }
}
Also used : Dimension(org.opencastproject.composer.layout.Dimension) Track(org.opencastproject.mediapackage.Track)

Example 13 with Dimension

use of org.opencastproject.composer.layout.Dimension in project opencast by opencast.

the class CompositeWorkflowOperationHandler method handleSingleTrack.

private WorkflowOperationResult handleSingleTrack(MediaPackage mediaPackage, WorkflowOperationInstance operation, CompositeSettings compositeSettings, Option<Attachment> watermarkAttachment) throws EncoderException, IOException, NotFoundException, MediaPackageException, WorkflowOperationException {
    if (compositeSettings.getSingleSourceLayout() == null) {
        throw new WorkflowOperationException("Single video layout must be set! Please verify that you have a " + LAYOUT_SINGLE + " property in your composite operation in your workflow definition.");
    }
    try {
        VideoStream[] videoStreams = TrackSupport.byType(compositeSettings.getSingleTrack().getStreams(), VideoStream.class);
        if (videoStreams.length == 0) {
            logger.warn("No video stream available to compose! {}", compositeSettings.getSingleTrack());
            return createResult(mediaPackage, Action.SKIP);
        }
        // Read the video dimensions from the mediapackage stream information
        Dimension videoDimension = Dimension.dimension(videoStreams[0].getFrameWidth(), videoStreams[0].getFrameHeight());
        // Create the video layout definitions
        List<Tuple<Dimension, HorizontalCoverageLayoutSpec>> shapes = new ArrayList<Tuple<Dimension, HorizontalCoverageLayoutSpec>>();
        shapes.add(0, Tuple.tuple(videoDimension, compositeSettings.getSingleSourceLayout()));
        // Determine dimension of output
        Dimension outputDimension = null;
        String outputResolutionSource = compositeSettings.getOutputResolutionSource();
        if (outputResolutionSource.equals(CompositeSettings.OUTPUT_RESOLUTION_FIXED)) {
            outputDimension = compositeSettings.getOutputDimension();
        } else if (outputResolutionSource.equals(CompositeSettings.OUTPUT_RESOLUTION_LOWER)) {
            outputDimension = videoDimension;
        } else if (outputResolutionSource.equals(CompositeSettings.OUTPUT_RESOLUTION_UPPER)) {
            outputDimension = videoDimension;
        }
        // Calculate the single layout
        MultiShapeLayout multiShapeLayout = LayoutManager.multiShapeLayout(outputDimension, shapes);
        // Create the laid out element for the videos
        LaidOutElement<Track> lowerLaidOutElement = new LaidOutElement<Track>(compositeSettings.getSingleTrack(), multiShapeLayout.getShapes().get(0));
        // Create the optionally laid out element for the watermark
        Option<LaidOutElement<Attachment>> watermarkOption = createWatermarkLaidOutElement(compositeSettings, outputDimension, watermarkAttachment);
        Job compositeJob = composerService.composite(outputDimension, Option.<LaidOutElement<Track>>none(), lowerLaidOutElement, watermarkOption, compositeSettings.getProfile().getIdentifier(), compositeSettings.getOutputBackground());
        // Wait for the jobs to return
        if (!waitForStatus(compositeJob).isSuccess())
            throw new WorkflowOperationException("The composite job did not complete successfully");
        if (compositeJob.getPayload().length() > 0) {
            Track compoundTrack = (Track) MediaPackageElementParser.getFromXml(compositeJob.getPayload());
            compoundTrack.setURI(workspace.moveTo(compoundTrack.getURI(), mediaPackage.getIdentifier().toString(), compoundTrack.getIdentifier(), "composite." + FilenameUtils.getExtension(compoundTrack.getURI().toString())));
            // Adjust the target tags
            for (String tag : compositeSettings.getTargetTags()) {
                logger.trace("Tagging compound track with '{}'", tag);
                compoundTrack.addTag(tag);
            }
            // Adjust the target flavor.
            compoundTrack.setFlavor(compositeSettings.getTargetFlavor());
            logger.debug("Compound track has flavor '{}'", compoundTrack.getFlavor());
            // store new tracks to mediaPackage
            mediaPackage.add(compoundTrack);
            WorkflowOperationResult result = createResult(mediaPackage, Action.CONTINUE, compositeJob.getQueueTime());
            logger.debug("Composite operation completed");
            return result;
        } else {
            logger.info("Composite operation unsuccessful, no payload returned: {}", compositeJob);
            return createResult(mediaPackage, Action.SKIP);
        }
    } finally {
        if (compositeSettings.getSourceUrlWatermark() != null)
            workspace.deleteFromCollection(COLLECTION, compositeSettings.getWatermarkIdentifier() + "." + FilenameUtils.getExtension(compositeSettings.getSourceUrlWatermark()));
    }
}
Also used : MultiShapeLayout(org.opencastproject.composer.layout.MultiShapeLayout) VideoStream(org.opencastproject.mediapackage.VideoStream) ArrayList(java.util.ArrayList) Dimension(org.opencastproject.composer.layout.Dimension) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) LaidOutElement(org.opencastproject.composer.api.LaidOutElement) HorizontalCoverageLayoutSpec(org.opencastproject.composer.layout.HorizontalCoverageLayoutSpec) Job(org.opencastproject.job.api.Job) Tuple(org.opencastproject.util.data.Tuple) Track(org.opencastproject.mediapackage.Track)

Example 14 with Dimension

use of org.opencastproject.composer.layout.Dimension in project opencast by opencast.

the class ComposerRestServiceTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageElementBuilder builder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
    // Set up our arguments and return values
    audioTrack = (Track) builder.newElement(Track.TYPE, MediaPackageElements.PRESENTATION_SOURCE);
    audioTrack.setIdentifier("audio1");
    videoTrack = (Track) builder.newElement(Track.TYPE, MediaPackageElements.PRESENTATION_SOURCE);
    videoTrack.setIdentifier("video1");
    profileId = "profile1";
    job = new JobImpl(1);
    job.setStatus(Job.Status.QUEUED);
    job.setJobType(ComposerService.JOB_TYPE);
    profile = new EncodingProfileImpl();
    profile.setIdentifier(profileId);
    List<EncodingProfileImpl> list = new ArrayList<EncodingProfileImpl>();
    list.add(profile);
    profileList = new EncodingProfileList(list);
    // Train a mock composer with some known behavior
    ComposerService composer = EasyMock.createNiceMock(ComposerService.class);
    EasyMock.expect(composer.encode(videoTrack, profileId)).andReturn(job).anyTimes();
    EasyMock.expect(composer.mux(videoTrack, audioTrack, profileId)).andReturn(job).anyTimes();
    EasyMock.expect(composer.listProfiles()).andReturn(list.toArray(new EncodingProfile[list.size()]));
    EasyMock.expect(composer.getProfile(profileId)).andReturn(profile);
    EasyMock.expect(composer.concat(EasyMock.eq(profileId), EasyMock.eq(new Dimension(640, 480)), (Track) EasyMock.notNull(), (Track) EasyMock.notNull())).andReturn(job);
    EasyMock.expect(composer.concat(EasyMock.eq(profileId), EasyMock.eq(new Dimension(640, 480)), EasyMock.gt(0.0f), (Track) EasyMock.notNull(), (Track) EasyMock.notNull())).andReturn(job);
    EasyMock.replay(composer);
    // Set up the rest endpoint
    restService = new ComposerRestService();
    restService.setComposerService(composer);
    restService.activate(null);
}
Also used : MediaPackageElementBuilder(org.opencastproject.mediapackage.MediaPackageElementBuilder) JobImpl(org.opencastproject.job.api.JobImpl) ComposerService(org.opencastproject.composer.api.ComposerService) ArrayList(java.util.ArrayList) EncodingProfileList(org.opencastproject.composer.api.EncodingProfileList) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) Dimension(org.opencastproject.composer.layout.Dimension) EncodingProfileImpl(org.opencastproject.composer.api.EncodingProfileImpl) Before(org.junit.Before)

Aggregations

Dimension (org.opencastproject.composer.layout.Dimension)14 Track (org.opencastproject.mediapackage.Track)11 Job (org.opencastproject.job.api.Job)8 ArrayList (java.util.ArrayList)7 LaidOutElement (org.opencastproject.composer.api.LaidOutElement)6 EncoderException (org.opencastproject.composer.api.EncoderException)5 Tuple (org.opencastproject.util.data.Tuple)5 Test (org.junit.Test)4 MultiShapeLayout (org.opencastproject.composer.layout.MultiShapeLayout)4 VideoStream (org.opencastproject.mediapackage.VideoStream)4 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)4 IOException (java.io.IOException)3 HorizontalCoverageLayoutSpec (org.opencastproject.composer.layout.HorizontalCoverageLayoutSpec)3 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)3 NotFoundException (org.opencastproject.util.NotFoundException)3 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)3 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)2