Search in sources :

Example 1 with VideoMeta

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

the class VideoMetadataDAOTest method createVideoMetadata.

@Test
public void createVideoMetadata() {
    RepositoryEntry entry1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry entry2 = JunitTestHelper.createAndPersistRepositoryEntry();
    // create metadata entries
    VideoMeta meta1 = videoMetadataDao.createVideoMetadata(entry1, 1500, "vid.mp4");
    Assert.assertNotNull(meta1);
    VideoMeta meta2 = videoMetadataDao.createVideoMetadata(entry2, 5500, "vid.mov");
    Assert.assertNotNull(meta2);
    dbInstance.commitAndCloseSession();
    // retrieve by olat resource
    VideoMeta reloadMeta1 = videoMetadataDao.getVideoMetadata(entry1.getOlatResource());
    Assert.assertNotNull(reloadMeta1);
    Assert.assertEquals(1500, reloadMeta1.getSize());
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 2 with VideoMeta

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

the class VideoQualityTableFormController method initTable.

private void initTable() {
    List<QualityTableRow> rows = new ArrayList<>();
    VideoMeta videoMetadata = videoManager.getVideoMetadata(videoResource);
    // Add master video file
    FormLink previewMasterLink = uifactory.addFormLink("view", "viewQuality", "quality.master", "quality.master", flc, Link.LINK);
    Object[] statusMaster = new Object[] { 100, Formatter.formatBytes(videoManager.getVideoFile(videoResource).length()) };
    rows.add(new QualityTableRow(previewMasterLink, videoMetadata.getWidth() + "x" + videoMetadata.getHeight(), statusMaster, "mp4", null));
    // Add all the transcoded versions
    List<VideoTranscoding> videoTranscodings = videoManager.getVideoTranscodings(videoResource);
    for (VideoTranscoding videoTranscoding : videoTranscodings) {
        String title = videoManager.getDisplayTitleForResolution(videoTranscoding.getResolution(), getTranslator());
        FormLink previewVersionLink = uifactory.addFormLink("res_" + count++, "viewQuality", title, title, flc, Link.LINK + Link.NONTRANSLATED);
        FormLink deleteLink = uifactory.addFormLink("del_" + count++, "deleteQuality", "quality.delete", "quality.delete", flc, Link.LINK);
        deleteLink.setUserObject(videoTranscoding);
        deleteLink.setIconLeftCSS("o_icon o_icon_delete_item o_icon-fw");
        previewVersionLink.setUserObject(videoTranscoding);
        if (videoTranscoding.getStatus() < VideoTranscoding.TRANSCODING_STATUS_DONE) {
            previewVersionLink.setEnabled(false);
        }
        int width = videoTranscoding.getWidth();
        int height = videoTranscoding.getHeight();
        String dimension = width + "x" + height;
        String fileSize = "";
        int status = videoTranscoding.getStatus();
        if (videoTranscoding.getSize() != 0 && status > -1) {
            fileSize = Formatter.formatBytes(videoTranscoding.getSize());
        } else if (status == VideoTranscoding.TRANSCODING_STATUS_WAITING) {
            fileSize = translate("transcoding.waiting");
        } else if (status <= VideoTranscoding.TRANSCODING_STATUS_DONE && status > -1) {
            fileSize = translate("transcoding.processing") + ": " + videoTranscoding.getStatus() + "%";
        } else if (status == VideoTranscoding.TRANSCODING_STATUS_INEFFICIENT) {
            fileSize = translate("transcoding.inefficient");
        } else if (status == VideoTranscoding.TRANSCODING_STATUS_ERROR) {
            fileSize = translate("transcoding.error");
        } else if (status == VideoTranscoding.TRANSCODING_STATUS_TIMEOUT) {
            fileSize = translate("transcoding.timeout");
        }
        Object[] statusTranscoding = new Object[] { status, fileSize };
        rows.add(new QualityTableRow(previewVersionLink, dimension, statusTranscoding, videoTranscoding.getFormat(), deleteLink));
    }
    List<Integer> missingResolutions = videoManager.getMissingTranscodings(videoResource);
    if (videoModule.isTranscodingEnabled()) {
        for (Integer missingRes : missingResolutions) {
            if (missingRes <= videoMetadata.getHeight()) {
                String title = videoManager.getDisplayTitleForResolution(missingRes, getTranslator());
                FormLink transcodeLink = uifactory.addFormLink("res_" + count++, "startTranscoding", "quality.transcode", "quality.transcode", flc, Link.LINK);
                transcodeLink.setUserObject(missingRes);
                transcodeLink.setIconLeftCSS("o_icon o_icon_refresh o_icon-fw");
                FormLink previewMissingLink = uifactory.addFormLink("res_" + count++, "viewQuality", title, title, flc, Link.LINK + Link.NONTRANSLATED);
                previewMissingLink.setEnabled(false);
                Object[] status = new Object[] { -1, "-" };
                rows.add(new QualityTableRow(previewMissingLink, missingRes.toString(), status, "mp4", transcodeLink));
            }
        }
    }
    rows.sort(new VideoComparator());
    tableModel.setObjects(rows);
    if (flc.hasFormComponent(tableEl)) {
        flc.remove(tableEl);
    }
    if (flc.hasFormComponent(refreshbtn)) {
        flc.remove(refreshbtn);
    }
    tableEl = uifactory.addTableElement(getWindowControl(), "qualityTable", tableModel, getTranslator(), flc);
    tableEl.setCustomizeColumns(false);
    tableEl.setNumOfRowsEnabled(false);
    refreshbtn = uifactory.addFormLink("button.refresh", flc, Link.BUTTON);
    refreshbtn.setIconLeftCSS("o_icon o_icon_refresh o_icon-fw");
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) VideoTranscoding(org.olat.modules.video.VideoTranscoding) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 3 with VideoMeta

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

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 4 with VideoMeta

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

the class VideoResourceEditController method doReplaceFileAndUpdateMetadata.

private int doReplaceFileAndUpdateMetadata() {
    VFSLeaf video = (VFSLeaf) vfsContainer.resolve(VIDEO_RESOURCE);
    File uploadFile = uploadFileEl.getUploadFile();
    // VideoMetadata videoMetadata = videoManager.getMetaDataFromOLATResource(videoResource);
    VideoMeta meta = videoManager.getVideoMetadata(videoResource);
    if (uploadFileEl.getUploadSize() > 0 && uploadFile.exists()) {
        video.delete();
        VFSLeaf uploadVideo = vfsContainer.createChildLeaf(VIDEO_RESOURCE);
        VFSManager.copyContent(uploadFile, uploadVideo);
        // update video dimensions
        Size dimensions = movieService.getSize(uploadVideo, VideoManagerImpl.FILETYPE_MP4);
        // update video duration
        long duration = movieService.getDuration(uploadVideo, VideoTranscoding.FORMAT_MP4);
        // exchange poster
        videoManager.exchangePoster(videoResource);
        if (duration != -1) {
            String length = Formatter.formatTimecode(duration);
            entry.setExpenditureOfWork(length);
            meta.setSize(uploadFile.length());
            meta.setWidth(dimensions.getWidth());
            meta.setHeight(dimensions.getHeight());
            meta.setFormat(FilenameUtils.getExtension(uploadVideo.getName()));
            meta.setLength(length);
        }
    }
    return meta.getHeight();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VideoMeta(org.olat.modules.video.VideoMeta) Size(org.olat.core.commons.services.image.Size) File(java.io.File)

Example 5 with VideoMeta

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

the class VideoManagerImpl method updateVideoMetadata.

@Override
public void updateVideoMetadata(OLATResource videoResource, VFSLeaf uploadVideo) {
    VideoMeta meta = getVideoMetadata(videoResource);
    Size dimensions = movieService.getSize(uploadVideo, VideoManagerImpl.FILETYPE_MP4);
    // update video duration
    long duration = movieService.getDuration(uploadVideo, VideoTranscoding.FORMAT_MP4);
    if (duration != -1) {
        String length = Formatter.formatTimecode(duration);
        meta.setSize(uploadVideo.getSize());
        meta.setWidth(dimensions.getWidth());
        meta.setHeight(dimensions.getHeight());
        meta.setFormat(FilenameUtils.getExtension(uploadVideo.getName()));
        meta.setLength(length);
    }
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) Size(org.olat.core.commons.services.image.Size)

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