use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class TimelinePreviewsServiceImpl method generatePreviewImages.
/**
* Starts generation of timeline preview images for the given video track
* and returns an attachment containing one image that contains all the
* timeline preview images.
*
* @param job
* @param track the element to analyze
* @param imageCount number of preview images that will be generated
* @return an attachment containing the resulting timeline previews image
* @throws TimelinePreviewsException
* @throws org.opencastproject.mediapackage.MediaPackageException
*/
protected Attachment generatePreviewImages(Job job, Track track, int imageCount) throws TimelinePreviewsException, MediaPackageException {
// Make sure the element can be analyzed using this analysis implementation
if (!track.hasVideo()) {
logger.error("Element {} is not a video track", track.getIdentifier());
throw new TimelinePreviewsException("Element is not a video track");
}
try {
if (track.getDuration() == null)
throw new MediaPackageException("Track " + track + " does not have a duration");
double duration = track.getDuration() / 1000.0;
double seconds = duration / (double) (imageCount);
seconds = seconds <= 0.0 ? 1.0 : seconds;
// calculate number of tiles for row and column in tiled image
int imageSize = (int) Math.ceil(Math.sqrt(imageCount));
Attachment composedImage = createPreviewsFFmpeg(track, seconds, resolutionX, resolutionY, imageSize, imageSize, duration);
if (composedImage == null)
throw new IllegalStateException("Unable to compose image");
// Set the mimetype
try {
composedImage.setMimeType(MimeTypes.parseMimeType(mimetype));
} catch (IllegalArgumentException e) {
logger.warn("Invalid mimetype provided for timeline previews image");
try {
composedImage.setMimeType(MimeTypes.fromURI(composedImage.getURI()));
} catch (UnknownFileTypeException ex) {
logger.warn("No valid mimetype could be found for timeline previews image");
}
}
composedImage.getProperties().put("imageCount", String.valueOf(imageCount));
return composedImage;
} catch (Exception e) {
logger.warn("Error creating timeline preview images for " + track, e);
if (e instanceof TimelinePreviewsException) {
throw (TimelinePreviewsException) e;
} else {
throw new TimelinePreviewsException(e);
}
}
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class AttachTranscriptionOperationHandlerTest method testStartWebVtt.
@Test
public void testStartWebVtt() throws Exception {
EasyMock.expect(captionService.convert(EasyMock.anyObject(Attachment.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(job2);
EasyMock.replay(captionService);
operation.setConfiguration(AttachTranscriptionOperationHandler.TRANSCRIPTION_JOB_ID, "transcriptionJob");
// operation.setConfiguration(AttachTranscriptionOperationHandler.TARGET_FLAVOR, "captions/timedtext");
operation.setConfiguration(AttachTranscriptionOperationHandler.TARGET_TAG, "tag1,tag2");
operation.setConfiguration(AttachTranscriptionOperationHandler.TARGET_CAPTION_FORMAT, "vtt");
WorkflowOperationResult result = operationHandler.start(workflowInstance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackage updatedMp = result.getMediaPackage();
Attachment[] attachments = updatedMp.getAttachments(MediaPackageElementFlavor.parseFlavor("captions/vtt+en"));
Assert.assertNotNull(attachments);
Assert.assertEquals(1, attachments.length);
Assert.assertNotNull(attachments[0].getTags());
Assert.assertEquals(3, attachments[0].getTags().length);
Assert.assertEquals("lang:en", attachments[0].getTags()[0]);
Assert.assertEquals("tag1", attachments[0].getTags()[1]);
Assert.assertEquals("tag2", attachments[0].getTags()[2]);
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class AttachTranscriptionOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// Media package set up
URI mediaPackageURI = StartTranscriptionOperationHandlerTest.class.getResource("/mp.xml").toURI();
mediaPackage = builder.loadFromXml(mediaPackageURI.toURL().openStream());
URI dfxpURI = StartTranscriptionOperationHandlerTest.class.getResource("/attachment_dfxp.xml").toURI();
String dfxpXml = FileUtils.readFileToString(new File(dfxpURI));
Attachment captionDfxp = (Attachment) MediaPackageElementParser.getFromXml(dfxpXml);
URI vttURI = StartTranscriptionOperationHandlerTest.class.getResource("/attachment_vtt.xml").toURI();
String vttXml = FileUtils.readFileToString(new File(vttURI));
Attachment captionVtt = (Attachment) MediaPackageElementParser.getFromXml(vttXml);
// Service registry set up
job1 = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job1.getId()).andReturn(1L);
EasyMock.expect(job1.getPayload()).andReturn(dfxpXml).anyTimes();
EasyMock.expect(job1.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job1.getDateCreated()).andReturn(new Date());
EasyMock.expect(job1.getDateStarted()).andReturn(new Date());
EasyMock.expect(job1.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job1);
job2 = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job2.getId()).andReturn(2L);
EasyMock.expect(job2.getPayload()).andReturn(vttXml).anyTimes();
EasyMock.expect(job2.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job2.getDateCreated()).andReturn(new Date());
EasyMock.expect(job2.getDateStarted()).andReturn(new Date());
EasyMock.expect(job2.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job2);
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job1);
EasyMock.expect(serviceRegistry.getJob(2L)).andReturn(job2);
EasyMock.replay(serviceRegistry);
// Transcription service set up
service = EasyMock.createStrictMock(TranscriptionService.class);
EasyMock.expect(service.getGeneratedTranscription("mpId1", "transcriptionJob")).andReturn(captionDfxp);
EasyMock.expect(service.getLanguage()).andReturn("en").once();
EasyMock.expect(service.getGeneratedTranscription("mpId2", "transcriptionJob")).andReturn(captionVtt);
EasyMock.expect(service.getLanguage()).andReturn("en").once();
EasyMock.replay(service);
// Caption service set up
captionService = EasyMock.createNiceMock(CaptionService.class);
// Workspace set up
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo(EasyMock.anyObject(URI.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(// just something valid
new URI("http://opencast.server.com/captions.xml"));
EasyMock.replay(workspace);
// Workflow set up
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("DCE-start-transcription");
def.setPublished(true);
workflowInstance = new WorkflowInstanceImpl(def, mediaPackage, null, null, null, null);
workflowInstance.setId(1);
operation = new WorkflowOperationInstanceImpl("attach-transcript", OperationState.RUNNING);
List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
operationList.add(operation);
workflowInstance.setOperations(operationList);
// Operation handler set up
operationHandler = new AttachTranscriptionOperationHandler();
operationHandler.setTranscriptionService(service);
operationHandler.setServiceRegistry(serviceRegistry);
operationHandler.setCaptionService(captionService);
operationHandler.setWorkspace(workspace);
operationHandler.setJobBarrierPollingInterval(1L);
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class AttachTranscriptionOperationHandlerTest method testStartDfxp.
@Test
public void testStartDfxp() throws Exception {
EasyMock.expect(captionService.convert(EasyMock.anyObject(Attachment.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(job1);
EasyMock.replay(captionService);
operation.setConfiguration(AttachTranscriptionOperationHandler.TRANSCRIPTION_JOB_ID, "transcriptionJob");
// operation.setConfiguration(AttachTranscriptionOperationHandler.TARGET_FLAVOR, "captions/timedtext");
operation.setConfiguration(AttachTranscriptionOperationHandler.TARGET_TAG, "tag1,tag2");
operation.setConfiguration(AttachTranscriptionOperationHandler.TARGET_CAPTION_FORMAT, "dfxp");
WorkflowOperationResult result = operationHandler.start(workflowInstance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackage updatedMp = result.getMediaPackage();
Attachment[] attachments = updatedMp.getAttachments(MediaPackageElementFlavor.parseFlavor("captions/dfxp+en"));
Assert.assertNotNull(attachments);
Assert.assertEquals(1, attachments.length);
Assert.assertNotNull(attachments[0].getTags());
Assert.assertEquals(3, attachments[0].getTags().length);
Assert.assertEquals("lang:en", attachments[0].getTags()[0]);
Assert.assertEquals("tag1", attachments[0].getTags()[1]);
Assert.assertEquals("tag2", attachments[0].getTags()[2]);
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class ImportWorkflowPropertiesWOH method start.
@Override
public WorkflowOperationResult start(WorkflowInstance wi, JobContext context) throws WorkflowOperationException {
logger.info("Start importing workflow properties for workflow {}", wi);
final String sourceFlavor = getConfig(wi, SOURCE_FLAVOR_PROPERTY);
Opt<Attachment> propertiesElem = loadPropertiesElementFromMediaPackage(MediaPackageElementFlavor.parseFlavor(sourceFlavor), wi);
if (propertiesElem.isSome()) {
Properties properties = loadPropertiesFromXml(workspace, propertiesElem.get().getURI());
final Set<String> keys = $(getOptConfig(wi, KEYS_PROPERTY)).bind(Strings.splitCsv).toSet();
return createResult(wi.getMediaPackage(), convertToWorkflowProperties(properties, keys), CONTINUE, 0);
} else {
logger.info("No attachment with workflow properties found, skipping...");
return createResult(wi.getMediaPackage(), SKIP);
}
}
Aggregations