Search in sources :

Example 1 with VideoManager

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

the class VideoHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String fileName) {
    // 1) Create resource and repository entry
    FileResource ores = new VideoFileResource();
    OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(ores);
    RepositoryEntry repoEntry = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    if (fileName == null) {
        fileName = file.getName();
    }
    fileName = fileName.toLowerCase();
    VFSLeaf importFile = new LocalFileImpl(file);
    long filesize = importFile.getSize();
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    if (fileName.endsWith(".mp4") || fileName.endsWith(".mov") || fileName.endsWith(".m4v")) {
        // 2a) import video from raw mp4 master video file
        videoManager.importFromMasterFile(repoEntry, importFile);
    } else if (fileName.endsWith(".zip")) {
        // 2b) import video from archive from another OpenOLAT instance
        DBFactory.getInstance().commit();
        videoManager.importFromExportArchive(repoEntry, importFile);
    }
    // 3) Persist Meta data
    videoManager.createVideoMetadata(repoEntry, filesize, fileName);
    DBFactory.getInstance().commit();
    // 4) start transcoding process if enabled
    videoManager.startTranscodingProcessIfEnabled(resource);
    return repoEntry;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VideoFileResource(org.olat.fileresource.types.VideoFileResource) FileResource(org.olat.fileresource.types.FileResource) VideoFileResource(org.olat.fileresource.types.VideoFileResource) OLATResource(org.olat.resource.OLATResource) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) VideoManager(org.olat.modules.video.VideoManager) RepositoryService(org.olat.repository.RepositoryService)

Example 2 with VideoManager

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

the class VideoTranscodingJob method updateStatus.

private boolean updateStatus(VideoTranscoding videoTranscoding, File transcodedFile, int exitCode) {
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    MovieService movieService = CoreSpringFactory.getImpl(MovieService.class);
    videoTranscoding = videoManager.getVideoTranscoding(videoTranscoding.getKey());
    Size videoSize = movieService.getSize(new LocalFileImpl(transcodedFile), VideoManagerImpl.FILETYPE_MP4);
    if (videoSize != null) {
        videoTranscoding.setWidth(videoSize.getWidth());
        videoTranscoding.setHeight(videoSize.getHeight());
    } else {
        videoTranscoding.setWidth(0);
        videoTranscoding.setHeight(0);
    }
    if (transcodedFile.exists()) {
        videoTranscoding.setSize(transcodedFile.length());
    } else {
        videoTranscoding.setSize(0);
    }
    if (exitCode == 0) {
        videoTranscoding.setStatus(VideoTranscoding.TRANSCODING_STATUS_DONE);
    } else {
        log.error("Exit code " + videoTranscoding + ":" + exitCode);
        videoTranscoding.setStatus(VideoTranscoding.TRANSCODING_STATUS_ERROR);
    }
    videoTranscoding = videoManager.updateVideoTranscoding(videoTranscoding);
    DBFactory.getInstance().commitAndCloseSession();
    return exitCode == 0;
}
Also used : MovieService(org.olat.core.commons.services.video.MovieService) Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VideoManager(org.olat.modules.video.VideoManager)

Example 3 with VideoManager

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

the class VideoTranscodingJob method getNextVideo.

private VideoTranscoding getNextVideo() {
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    List<VideoTranscoding> videoTranscodings = videoManager.getVideoTranscodingsPendingAndInProgress();
    VideoTranscoding videoTranscoding = null;
    for (VideoTranscoding videoTrans : videoTranscodings) {
        String transcoder = videoTrans.getTranscoder();
        if (transcoder == null) {
            log.info("Start transcoding video with resolution::" + videoTrans.getResolution() + " for video resource::" + videoTrans.getVideoResource().getResourceableId());
            videoTrans.setTranscoder(VideoTranscoding.TRANSCODER_LOCAL);
            videoTranscoding = videoManager.updateVideoTranscoding(videoTrans);
            break;
        } else if (transcoder.equals(VideoTranscoding.TRANSCODER_LOCAL)) {
            log.info("Continue with transcoding video with resolution::" + videoTrans.getResolution() + " for video resource::" + videoTrans.getVideoResource().getResourceableId());
            videoTranscoding = videoTrans;
            break;
        }
    }
    return videoTranscoding;
}
Also used : VideoTranscoding(org.olat.modules.video.VideoTranscoding) VideoManager(org.olat.modules.video.VideoManager)

Example 4 with VideoManager

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

the class VideoTranscodingJob method updateStatus.

/**
 * Update the transcoding object in database.
 *
 * @param proc The transcoding process
 * @param videoTranscoding The video transcoding object
 * @return false if the transcoding object was deleted
 */
private boolean updateStatus(Process proc, VideoTranscoding videoTranscoding) {
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    try (InputStream stdout = proc.getInputStream();
        InputStreamReader isr = new InputStreamReader(stdout);
        BufferedReader br = new BufferedReader(isr)) {
        String line = null;
        while ((line = br.readLine()) != null) {
            // Parse the percentage. Logline looks like this:
            // Encoding: task 1 of 1, 85.90 % (307.59 fps, avg 330.35 fps, ETA 00h00m05s)
            int start = line.indexOf(",");
            if (start != -1) {
                line = line.substring(start);
                int end = line.indexOf(".");
                if (end != -1 && end < 5) {
                    String percent = line.substring(2, end);
                    log.debug("Output: " + percent);
                    // update version file for UI
                    try {
                        videoTranscoding.setStatus(Integer.parseInt(percent));
                        videoTranscoding = videoManager.updateVideoTranscoding(videoTranscoding);
                        DBFactory.getInstance().commitAndCloseSession();
                    } catch (ObjectDeletedException e) {
                        // deleted by other process
                        proc.destroy();
                        br.close();
                        return false;
                    }
                }
            }
        }
    } catch (IOException e) {
        log.error("", e);
    }
    return true;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ObjectDeletedException(org.hibernate.ObjectDeletedException) IOException(java.io.IOException) VideoManager(org.olat.modules.video.VideoManager)

Example 5 with VideoManager

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

the class VideoHandler method getAsMediaResource.

@Override
public MediaResource getAsMediaResource(OLATResourceable res, boolean backwardsCompatible) {
    RepositoryManager repoManager = CoreSpringFactory.getImpl(RepositoryManager.class);
    RepositoryEntry repoEntry = repoManager.lookupRepositoryEntry(res, false);
    if (repoEntry == null) {
        return new NotFoundMediaResource();
    }
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    VideoExportMediaResource exportResource = videoManager.getVideoExportMediaResource(repoEntry);
    return exportResource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VideoExportMediaResource(org.olat.modules.video.manager.VideoExportMediaResource) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) VideoManager(org.olat.modules.video.VideoManager)

Aggregations

VideoManager (org.olat.modules.video.VideoManager)16 OLATResource (org.olat.resource.OLATResource)6 IOException (java.io.IOException)4 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 ObjectDeletedException (org.hibernate.ObjectDeletedException)2 Size (org.olat.core.commons.services.image.Size)2 MovieService (org.olat.core.commons.services.video.MovieService)2 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 FileResource (org.olat.fileresource.types.FileResource)2 VideoFileResource (org.olat.fileresource.types.VideoFileResource)2 VideoModule (org.olat.modules.video.VideoModule)2 VideoTranscoding (org.olat.modules.video.VideoTranscoding)2