Search in sources :

Example 6 with VideoManager

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

the class VideoHandler method copy.

@Override
public RepositoryEntry copy(Identity author, RepositoryEntry source, RepositoryEntry target) {
    OLATResource sourceResource = source.getOlatResource();
    OLATResource targetResource = target.getOlatResource();
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    videoManager.copyVideo(sourceResource, targetResource);
    return target;
}
Also used : OLATResource(org.olat.resource.OLATResource) VideoManager(org.olat.modules.video.VideoManager)

Example 7 with VideoManager

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

the class VideoHandler method cleanupOnDelete.

@Override
public boolean cleanupOnDelete(RepositoryEntry entry, OLATResourceable res) {
    boolean success = super.cleanupOnDelete(entry, res);
    if (success) {
        // remove transcodings
        VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
        success = videoManager.deleteVideoTranscodings(entry.getOlatResource());
        // remove metadata
        success &= videoManager.deleteVideoMetadata(entry.getOlatResource());
    }
    return success;
}
Also used : VideoManager(org.olat.modules.video.VideoManager)

Example 8 with VideoManager

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

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

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

the class VideoTranscodingJob method forkTranscodingProcess.

/**
 * Internal helper to fork a process with handbrake and read the values from the process
 * @param videoTranscoding
 * @return true: all ok; false: an error happend along the way
 */
private boolean forkTranscodingProcess(VideoTranscoding videoTranscoding) {
    OLATResource video = videoTranscoding.getVideoResource();
    VideoModule videoModule = CoreSpringFactory.getImpl(VideoModule.class);
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    File masterFile = videoManager.getVideoFile(video);
    File transcodingFolder = ((LocalFolderImpl) videoManager.getTranscodingContainer(video)).getBasefile();
    File transcodedFile = new File(transcodingFolder, Integer.toString(videoTranscoding.getResolution()) + masterFile.getName());
    // mark this as beeing transcoded by this local transcoder
    videoTranscoding.setTranscoder(VideoTranscoding.TRANSCODER_LOCAL);
    videoTranscoding = videoManager.updateVideoTranscoding(videoTranscoding);
    String resolution = Integer.toString(videoTranscoding.getResolution());
    // Legacy fallback
    String profile = "Normal";
    if (resolutionsWithProfile.contains(resolution)) {
        profile = videoModule.getVideoTranscodingProfile() + " " + resolution + "p30";
    }
    ArrayList<String> cmd = new ArrayList<>();
    String tasksetConfig = videoModule.getTranscodingTasksetConfig();
    if (tasksetConfig != null && !"Mac OS X".equals(System.getProperty("os.name"))) {
        cmd.add("taskset");
        cmd.add("-c");
        cmd.add(tasksetConfig);
    }
    cmd.add("HandBrakeCLI");
    cmd.add("-i");
    cmd.add(masterFile.getAbsolutePath());
    cmd.add("-o");
    cmd.add(transcodedFile.getAbsolutePath());
    // add video infos to header for web "fast start"
    cmd.add("--optimize");
    cmd.add("--preset");
    cmd.add(profile);
    cmd.add("--height");
    cmd.add(resolution);
    // do not crop
    cmd.add("--crop");
    cmd.add("0:0:0:0");
    Process process = null;
    try {
        if (log.isDebug()) {
            log.debug(cmd.toString());
        }
        ProcessBuilder builder = new ProcessBuilder(cmd);
        process = builder.start();
        return updateVideoTranscodingFromProcessOutput(process, videoTranscoding, transcodedFile);
    } catch (IOException e) {
        log.error("Could not spawn convert sub process", e);
        return false;
    } finally {
        if (process != null) {
            process.destroy();
            process = null;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) IOException(java.io.IOException) VideoManager(org.olat.modules.video.VideoManager) File(java.io.File) VideoModule(org.olat.modules.video.VideoModule) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 10 with VideoManager

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

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)

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