Search in sources :

Example 1 with VideoModule

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

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)

Example 2 with VideoModule

use of org.olat.modules.video.VideoModule 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 3 with VideoModule

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

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

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

VideoModule (org.olat.modules.video.VideoModule)4 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 VideoManager (org.olat.modules.video.VideoManager)2 VideoTranscoding (org.olat.modules.video.VideoTranscoding)2 OLATResource (org.olat.resource.OLATResource)2