use of org.olat.modules.video.VideoManager 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;
}
}
}
use of org.olat.modules.video.VideoManager in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.modules.video.VideoManager in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.modules.video.VideoManager in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.modules.video.VideoManager in project openolat by klemens.
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;
}
Aggregations