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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations