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