Search in sources :

Example 6 with VideoMeta

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

the class VideoMetaDataEditFormController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("tab.video.metaDataConfig");
    OLATResource videoResource = repoEntry.getOlatResource();
    VideoMeta videoMetadata = videoManager.getVideoMetadata(videoResource);
    uifactory.addStaticTextElement("video.config.duration", repoEntry.getExpenditureOfWork(), formLayout);
    uifactory.addStaticTextElement("video.config.width", String.valueOf(videoMetadata.getWidth()) + "px", formLayout);
    uifactory.addStaticTextElement("video.config.height", String.valueOf(videoMetadata.getHeight()) + "px", formLayout);
    String aspcectRatio = videoManager.getAspectRatio(videoMetadata.getWidth(), videoMetadata.getHeight());
    uifactory.addStaticTextElement("video.config.ratio", aspcectRatio, formLayout);
    uifactory.addStaticTextElement("video.config.creationDate", StringHelper.formatLocaleDateTime(videoResource.getCreationDate().getTime(), getLocale()), formLayout);
    uifactory.addStaticTextElement("video.config.fileSize", Formatter.formatBytes(videoManager.getVideoFile(videoResource).length()), formLayout);
}
Also used : VideoMeta(org.olat.modules.video.VideoMeta) OLATResource(org.olat.resource.OLATResource)

Example 7 with VideoMeta

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

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

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

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

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

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)

Example 10 with VideoMeta

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

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)

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