Search in sources :

Example 11 with VideoMeta

use of org.olat.modules.video.VideoMeta in project openolat by klemens.

the class VideoQualityTableFormController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source instanceof FormLink && ((FormLink) source).getCmd().equals("viewQuality")) {
        if (cmc == null) {
            // initialize preview controller only once
            previewVC = createVelocityContainer("video_preview");
            cmc = new CloseableModalController(getWindowControl(), "close", previewVC);
            listenTo(cmc);
        }
        // Get the user object from the link to access version object
        FormLink link = (FormLink) source;
        VideoTranscoding videoTranscoding = (VideoTranscoding) link.getUserObject();
        if (videoTranscoding == null) {
            // this is the master video
            // VideoMetadata videoMetadata = videoManager.readVideoMetadataFile(videoResource);
            VideoMeta videoMetadata = videoManager.getVideoMetadata(videoResource);
            previewVC.contextPut("width", videoMetadata.getWidth());
            previewVC.contextPut("height", videoMetadata.getHeight());
            previewVC.contextPut("filename", "video.mp4");
            VFSContainer container = videoManager.getMasterContainer(videoResource);
            String transcodedUrl = registerMapper(ureq, new VideoMediaMapper(container));
            previewVC.contextPut("mediaUrl", transcodedUrl);
        } else {
            // this is a version
            previewVC.contextPut("width", videoTranscoding.getWidth());
            previewVC.contextPut("height", videoTranscoding.getHeight());
            previewVC.contextPut("filename", videoTranscoding.getResolution() + "video.mp4");
            VFSContainer container = videoManager.getTranscodingContainer(videoResource);
            String transcodedUrl = registerMapper(ureq, new VideoMediaMapper(container));
            previewVC.contextPut("mediaUrl", transcodedUrl);
        }
        // activate dialog to bring it in front
        cmc.activate();
    } else if (source instanceof FormLink && ((FormLink) source).getCmd().equals("deleteQuality")) {
        FormLink link = (FormLink) source;
        VideoTranscoding videoTranscoding = (VideoTranscoding) link.getUserObject();
        videoManager.deleteVideoTranscoding(videoTranscoding);
    } else if (source instanceof FormLink && ((FormLink) source).getCmd().equals("startTranscoding")) {
        videoManager.createTranscoding(videoResource, (int) source.getUserObject(), "mp4");
    }
    initTable();
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) VideoTranscoding(org.olat.modules.video.VideoTranscoding) VFSContainer(org.olat.core.util.vfs.VFSContainer) VideoMediaMapper(org.olat.modules.video.manager.VideoMediaMapper) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 12 with VideoMeta

use of org.olat.modules.video.VideoMeta in project OpenOLAT by OpenOLAT.

the class VideoManagerImpl method setPosterframeResizeUploadfile.

/**
 * Sets the posterframe resize uploadfile. Tries to fit image to dimensions of video.
 *
 * @param videoResource the video resource
 * @param posterframe the newPosterFile
 */
@Override
public void setPosterframeResizeUploadfile(OLATResource videoResource, VFSLeaf newPosterFile) {
    VideoMeta videoMetadata = getVideoMetadata(videoResource);
    Size posterRes = imageHelper.getSize(newPosterFile, FILETYPE_JPG);
    // file size needs to be bigger than target resolution, otherwise use image as it comes
    if (posterRes != null && posterRes.getHeight() != 0 && posterRes.getWidth() != 0 && posterRes.getHeight() >= videoMetadata.getHeight() && posterRes.getWidth() >= videoMetadata.getWidth()) {
        VFSLeaf oldPosterFile = getPosterframe(videoResource);
        oldPosterFile.delete();
        VFSContainer masterContainer = getMasterContainer(videoResource);
        LocalFileImpl newPoster = (LocalFileImpl) masterContainer.createChildLeaf(FILENAME_POSTER_JPG);
        // to shrink image file, resolution ratio needs to be equal, otherwise crop from top left corner
        if (posterRes.getHeight() / posterRes.getWidth() == videoMetadata.getHeight() / videoMetadata.getWidth()) {
            imageHelper.scaleImage(newPosterFile, newPoster, videoMetadata.getWidth(), videoMetadata.getHeight(), true);
        } else {
            Crop cropSelection = new Crop(0, 0, videoMetadata.getHeight(), videoMetadata.getWidth());
            imageHelper.cropImage(((LocalFileImpl) newPosterFile).getBasefile(), newPoster.getBasefile(), cropSelection);
        }
    } else {
        setPosterframe(videoResource, newPosterFile);
    }
}
Also used : Crop(org.olat.core.commons.services.image.Crop) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VideoMeta(org.olat.modules.video.VideoMeta) Size(org.olat.core.commons.services.image.Size) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 13 with VideoMeta

use of org.olat.modules.video.VideoMeta in project OpenOLAT by OpenOLAT.

the class VideoManagerImpl method startTranscodingProcess.

@Override
public void startTranscodingProcess(OLATResource video) {
    List<VideoTranscoding> existingTranscodings = getVideoTranscodings(video);
    VideoMeta videoMetadata = getVideoMetadata(video);
    int height = videoMetadata.getHeight();
    // 1) setup transcoding job for original file size
    createTranscodingIfNotCreatedAlready(video, height, VideoTranscoding.FORMAT_MP4, existingTranscodings);
    // 2) setup transcoding jobs for all configured sizes below the original size
    int[] resolutions = videoModule.getTranscodingResolutions();
    for (int resolution : resolutions) {
        if (height <= resolution) {
            continue;
        }
        createTranscodingIfNotCreatedAlready(video, resolution, VideoTranscoding.FORMAT_MP4, existingTranscodings);
    }
    // 3) Start transcoding immediately, force job execution
    if (videoModule.isTranscodingLocal()) {
        try {
            scheduler.triggerJob(videoJobKey);
        } catch (SchedulerException e) {
            log.error("Error while starting video transcoding job", e);
        }
    }
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) SchedulerException(org.quartz.SchedulerException) VideoTranscoding(org.olat.modules.video.VideoTranscoding)

Example 14 with VideoMeta

use of org.olat.modules.video.VideoMeta in project OpenOLAT by OpenOLAT.

the class VideoMetadataDAOTest method deleteVideoMetadata.

@Test
public void deleteVideoMetadata() {
    RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry3 = JunitTestHelper.createAndPersistRepositoryEntry();
    // create metadata entries
    VideoMeta meta0 = videoMetadataDao.createVideoMetadata(entry0, 1500, "vid.mp4");
    VideoMeta meta1 = videoMetadataDao.createVideoMetadata(entry1, 1100, "vide.mp4");
    VideoMeta meta2 = videoMetadataDao.createVideoMetadata(entry2, 1200, "video.mov");
    VideoMeta meta3 = videoMetadataDao.createVideoMetadata(entry3, 4500, "videos.mp4");
    Assert.assertNotNull(meta1);
    Assert.assertNotNull(meta3);
    Assert.assertNotNull(meta2);
    Assert.assertNotNull(meta0);
    dbInstance.commitAndCloseSession();
    // retrieve list of entries
    List<VideoMetaImpl> metadata = videoMetadataDao.getAllVideoResourcesMetadata();
    Assert.assertTrue(metadata.contains(meta0));
    Assert.assertTrue(metadata.contains(meta1));
    Assert.assertTrue(metadata.contains(meta2));
    Assert.assertTrue(metadata.contains(meta3));
    // delete entries
    int deleted0 = videoMetadataDao.deleteVideoMetadata(entry0.getOlatResource());
    int deleted3 = videoMetadataDao.deleteVideoMetadata(entry3.getOlatResource());
    Assert.assertEquals(1, deleted0);
    Assert.assertNotEquals(0, deleted3);
    dbInstance.commitAndCloseSession();
    // retrieve new list
    List<VideoMetaImpl> deleteMetadata = videoMetadataDao.getAllVideoResourcesMetadata();
    Assert.assertFalse(deleteMetadata.contains(meta0));
    Assert.assertTrue(deleteMetadata.contains(meta1));
    Assert.assertTrue(deleteMetadata.contains(meta2));
    Assert.assertFalse(deleteMetadata.contains(meta3));
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) VideoMetaImpl(org.olat.modules.video.model.VideoMetaImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 15 with VideoMeta

use of org.olat.modules.video.VideoMeta in project openolat by klemens.

the class VideoManagerImpl method startTranscodingProcess.

@Override
public void startTranscodingProcess(OLATResource video) {
    List<VideoTranscoding> existingTranscodings = getVideoTranscodings(video);
    VideoMeta videoMetadata = getVideoMetadata(video);
    int height = videoMetadata.getHeight();
    // 1) setup transcoding job for original file size
    createTranscodingIfNotCreatedAlready(video, height, VideoTranscoding.FORMAT_MP4, existingTranscodings);
    // 2) setup transcoding jobs for all configured sizes below the original size
    int[] resolutions = videoModule.getTranscodingResolutions();
    for (int resolution : resolutions) {
        if (height <= resolution) {
            continue;
        }
        createTranscodingIfNotCreatedAlready(video, resolution, VideoTranscoding.FORMAT_MP4, existingTranscodings);
    }
    // 3) Start transcoding immediately, force job execution
    if (videoModule.isTranscodingLocal()) {
        try {
            scheduler.triggerJob(videoJobKey);
        } catch (SchedulerException e) {
            log.error("Error while starting video transcoding job", e);
        }
    }
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) SchedulerException(org.quartz.SchedulerException) VideoTranscoding(org.olat.modules.video.VideoTranscoding)

Aggregations

VideoMeta (org.olat.modules.video.VideoMeta)18 Size (org.olat.core.commons.services.image.Size)6 VideoTranscoding (org.olat.modules.video.VideoTranscoding)6 Test (org.junit.Test)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Crop (org.olat.core.commons.services.image.Crop)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2 VideoMediaMapper (org.olat.modules.video.manager.VideoMediaMapper)2 VideoMetaImpl (org.olat.modules.video.model.VideoMetaImpl)2 OLATResource (org.olat.resource.OLATResource)2 SchedulerException (org.quartz.SchedulerException)2