Search in sources :

Example 56 with Attachment

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);
        }
    }
}
Also used : TimelinePreviewsException(org.opencastproject.timelinepreviews.api.TimelinePreviewsException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) UnknownFileTypeException(org.opencastproject.util.UnknownFileTypeException) Attachment(org.opencastproject.mediapackage.Attachment) TimelinePreviewsException(org.opencastproject.timelinepreviews.api.TimelinePreviewsException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) FileNotFoundException(java.io.FileNotFoundException) UnknownFileTypeException(org.opencastproject.util.UnknownFileTypeException)

Example 57 with Attachment

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]);
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 58 with Attachment

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);
}
Also used : TranscriptionService(org.opencastproject.transcription.api.TranscriptionService) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) Attachment(org.opencastproject.mediapackage.Attachment) URI(java.net.URI) Date(java.util.Date) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) CaptionService(org.opencastproject.caption.api.CaptionService) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 59 with Attachment

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]);
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Test(org.junit.Test)

Example 60 with Attachment

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);
    }
}
Also used : Attachment(org.opencastproject.mediapackage.Attachment) Properties(java.util.Properties)

Aggregations

Attachment (org.opencastproject.mediapackage.Attachment)64 MediaPackage (org.opencastproject.mediapackage.MediaPackage)28 URI (java.net.URI)24 IOException (java.io.IOException)20 Job (org.opencastproject.job.api.Job)20 NotFoundException (org.opencastproject.util.NotFoundException)19 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)18 Track (org.opencastproject.mediapackage.Track)16 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)16 Test (org.junit.Test)15 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)15 Catalog (org.opencastproject.mediapackage.Catalog)14 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)12 InputStream (java.io.InputStream)11 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)10 File (java.io.File)9 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 AttachmentImpl (org.opencastproject.mediapackage.attachment.AttachmentImpl)8 Workspace (org.opencastproject.workspace.api.Workspace)8