Search in sources :

Example 26 with VideoTranscoding

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

the class VideoDisplayController method loadVideo.

/**
 * Internal helper to do the actual video loading, checking for transcoded versions and captions
 * @param ureq
 * @param video
 */
private void loadVideo(UserRequest ureq, VFSLeaf video) {
    mainVC.contextPut("title", entry.getDisplayname());
    String desc = (descriptionText != null ? descriptionText : entry.getDescription());
    setText(desc, "description");
    String authors = entry.getAuthors();
    mainVC.contextPut("authors", (StringHelper.containsNonWhitespace(authors) ? authors : null));
    if (video != null) {
        // get resolution of master video resource
        Size masterResolution = videoManager.getVideoResolutionFromOLATResource(entry.getOlatResource());
        String masterTitle = videoManager.getDisplayTitleForResolution(masterResolution.getHeight(), getTranslator());
        String masterSize = " (" + Formatter.formatBytes(videoManager.getVideoMetadata(entry.getOlatResource()).getSize()) + ")";
        boolean addMaster = true;
        // Mapper for Video
        String masterMapperId = "master-" + entry.getOlatResource().getResourceableId();
        String masterUrl = registerCacheableMapper(ureq, masterMapperId, new VideoMediaMapper(videoManager.getMasterContainer(entry.getOlatResource())));
        mainVC.contextPut("masterUrl", masterUrl);
        // Mapper for versions specific because not in same base as the resource itself
        String transcodingMapperId = "transcoding-" + entry.getOlatResource().getResourceableId();
        VFSContainer transcodedContainer = videoManager.getTranscodingContainer(entry.getOlatResource());
        String transcodedUrl = registerCacheableMapper(ureq, transcodingMapperId, new VideoMediaMapper(transcodedContainer));
        mainVC.contextPut("transcodedUrl", transcodedUrl);
        // Add transcoded versions
        List<VideoTranscoding> videos = videoManager.getVideoTranscodings(entry.getOlatResource());
        List<VideoTranscoding> readyToPlayVideos = new ArrayList<>();
        List<String> displayTitles = new ArrayList<>();
        int preferredAvailableResolution = 0;
        for (VideoTranscoding videoTranscoding : videos) {
            if (videoTranscoding.getStatus() == VideoTranscoding.TRANSCODING_STATUS_DONE) {
                readyToPlayVideos.add(videoTranscoding);
                // Check if at least one has equal height, else use master as resource
                addMaster &= videoTranscoding.getHeight() < masterResolution.getHeight();
                // Use the users preferred resolution or the next higher resolution
                if (videoTranscoding.getResolution() >= userPreferredResolution.intValue()) {
                    preferredAvailableResolution = readyToPlayVideos.size() - 1;
                }
                // Calculate title. Standard title for standard resolution, original title if not standard resolution
                String title = videoManager.getDisplayTitleForResolution(videoTranscoding.getResolution(), getTranslator());
                displayTitles.add(title);
            }
        }
        mainVC.contextPut("addMaster", addMaster);
        mainVC.contextPut("masterTitle", masterTitle + masterSize);
        mainVC.contextPut("videos", readyToPlayVideos);
        mainVC.contextPut("displayTitles", displayTitles);
        mainVC.contextPut("useSourceChooser", Boolean.valueOf(readyToPlayVideos.size() > 1));
        mainVC.contextPut(GUIPREF_KEY_PREFERRED_RESOLUTION, preferredAvailableResolution);
        // Check for null-value posters
        VFSLeaf poster = videoManager.getPosterframe(entry.getOlatResource());
        mainVC.contextPut("usePoster", Boolean.valueOf(poster != null && poster.getSize() > 0));
        // Load the track from config
        Map<String, String> trackfiles = new HashMap<String, String>();
        Map<String, VFSLeaf> configTracks = videoManager.getAllTracks(entry.getOlatResource());
        for (HashMap.Entry<String, VFSLeaf> track : configTracks.entrySet()) {
            trackfiles.put(track.getKey(), track.getValue().getName());
        }
        mainVC.contextPut("trackfiles", trackfiles);
        // Load video chapter if available
        mainVC.contextPut("hasChapters", videoManager.hasChapters(entry.getOlatResource()));
        // Add duration without preloading video
        String duration = entry.getExpenditureOfWork();
        if (!StringHelper.containsNonWhitespace(duration)) {
            duration = "00:00";
        }
        mainVC.contextPut("duration", duration);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) Size(org.olat.core.commons.services.image.Size) VFSContainer(org.olat.core.util.vfs.VFSContainer) VideoTranscoding(org.olat.modules.video.VideoTranscoding) ArrayList(java.util.ArrayList) VideoMediaMapper(org.olat.modules.video.manager.VideoMediaMapper)

Example 27 with VideoTranscoding

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

the class VideoTranscodingDAOTest method getVideoTranscodingByKey.

@Test
public void getVideoTranscodingByKey() {
    OLATResource resource = JunitTestHelper.createRandomResource();
    VideoTranscoding vTranscoding = videoTranscodingDao.createVideoTranscoding(resource, 1080, "mp4");
    dbInstance.commitAndCloseSession();
    VideoTranscoding reloadedTranscoding = videoTranscodingDao.getVideoTranscoding(vTranscoding.getKey());
    Assert.assertNotNull(reloadedTranscoding);
    Assert.assertEquals(vTranscoding, reloadedTranscoding);
}
Also used : VideoTranscoding(org.olat.modules.video.VideoTranscoding) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 28 with VideoTranscoding

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

the class VideoTranscodingDAOTest method deleteVideoTranscoding.

@Test
public void deleteVideoTranscoding() {
    // void deleteVideoTranscoding(VideoTranscoding videoTranscoding) {
    OLATResource resource = JunitTestHelper.createRandomResource();
    // prepare transcodings
    VideoTranscoding vTranscoding1 = videoTranscodingDao.createVideoTranscoding(resource, 1080, "mp4");
    videoTranscodingDao.createVideoTranscoding(resource, 720, "mp4");
    videoTranscodingDao.createVideoTranscoding(resource, 720, "mp4");
    videoTranscodingDao.createVideoTranscoding(resource, 720, "mp4");
    dbInstance.commitAndCloseSession();
    // delete single transcoding
    videoTranscodingDao.deleteVideoTranscoding(vTranscoding1);
    dbInstance.commitAndCloseSession();
    List<VideoTranscoding> results = videoTranscodingDao.getVideoTranscodings(resource);
    Assert.assertEquals(3, results.size());
    // delete all transcodings of resource
    videoTranscodingDao.deleteVideoTranscodings(resource);
    dbInstance.commitAndCloseSession();
    results = videoTranscodingDao.getVideoTranscodings(resource);
    Assert.assertEquals(0, results.size());
}
Also used : VideoTranscoding(org.olat.modules.video.VideoTranscoding) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 29 with VideoTranscoding

use of org.olat.modules.video.VideoTranscoding 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)

Example 30 with VideoTranscoding

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

the class VideoTranscodingJob method doExecute.

/**
 * Implementation of job execution
 * @param context
 * @return
 * @throws JobExecutionException
 */
private boolean doExecute(JobExecutionContext context) throws JobExecutionException {
    VideoModule videoModule = CoreSpringFactory.getImpl(VideoModule.class);
    if (!videoModule.isTranscodingLocal()) {
        log.debug("Skipping execution of video transcoding job, local transcoding disabled");
        return false;
    }
    // Find first one to work with
    boolean allOk = true;
    for (VideoTranscoding videoTranscoding = getNextVideo(); videoTranscoding != null; videoTranscoding = getNextVideo()) {
        allOk &= forkTranscodingProcess(videoTranscoding);
    }
    return allOk;
}
Also used : VideoTranscoding(org.olat.modules.video.VideoTranscoding) VideoModule(org.olat.modules.video.VideoModule)

Aggregations

VideoTranscoding (org.olat.modules.video.VideoTranscoding)34 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)12 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 OLATResource (org.olat.resource.OLATResource)8 Test (org.junit.Test)6 VideoMeta (org.olat.modules.video.VideoMeta)6 HashMap (java.util.HashMap)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VideoMediaMapper (org.olat.modules.video.manager.VideoMediaMapper)4 VideoTranscodingImpl (org.olat.modules.video.model.VideoTranscodingImpl)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Size (org.olat.core.commons.services.image.Size)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 VideoManager (org.olat.modules.video.VideoManager)2 VideoModule (org.olat.modules.video.VideoModule)2 SchedulerException (org.quartz.SchedulerException)2