use of org.olat.modules.video.VideoTranscoding in project OpenOLAT by OpenOLAT.
the class VideoDisplayController method loadVideo.
/**
* Internal helper to do the actual video loading, checking for transcoded versions and captions
* @param ureq
* @param video
*/
private void loadVideo(UserRequest ureq, VFSLeaf video) {
mainVC.contextPut("title", entry.getDisplayname());
String desc = (descriptionText != null ? descriptionText : entry.getDescription());
setText(desc, "description");
String authors = entry.getAuthors();
mainVC.contextPut("authors", (StringHelper.containsNonWhitespace(authors) ? authors : null));
if (video != null) {
// get resolution of master video resource
Size masterResolution = videoManager.getVideoResolutionFromOLATResource(entry.getOlatResource());
String masterTitle = videoManager.getDisplayTitleForResolution(masterResolution.getHeight(), getTranslator());
String masterSize = " (" + Formatter.formatBytes(videoManager.getVideoMetadata(entry.getOlatResource()).getSize()) + ")";
boolean addMaster = true;
// Mapper for Video
String masterMapperId = "master-" + entry.getOlatResource().getResourceableId();
String masterUrl = registerCacheableMapper(ureq, masterMapperId, new VideoMediaMapper(videoManager.getMasterContainer(entry.getOlatResource())));
mainVC.contextPut("masterUrl", masterUrl);
// Mapper for versions specific because not in same base as the resource itself
String transcodingMapperId = "transcoding-" + entry.getOlatResource().getResourceableId();
VFSContainer transcodedContainer = videoManager.getTranscodingContainer(entry.getOlatResource());
String transcodedUrl = registerCacheableMapper(ureq, transcodingMapperId, new VideoMediaMapper(transcodedContainer));
mainVC.contextPut("transcodedUrl", transcodedUrl);
// Add transcoded versions
List<VideoTranscoding> videos = videoManager.getVideoTranscodings(entry.getOlatResource());
List<VideoTranscoding> readyToPlayVideos = new ArrayList<>();
List<String> displayTitles = new ArrayList<>();
int preferredAvailableResolution = 0;
for (VideoTranscoding videoTranscoding : videos) {
if (videoTranscoding.getStatus() == VideoTranscoding.TRANSCODING_STATUS_DONE) {
readyToPlayVideos.add(videoTranscoding);
// Check if at least one has equal height, else use master as resource
addMaster &= videoTranscoding.getHeight() < masterResolution.getHeight();
// Use the users preferred resolution or the next higher resolution
if (videoTranscoding.getResolution() >= userPreferredResolution.intValue()) {
preferredAvailableResolution = readyToPlayVideos.size() - 1;
}
// Calculate title. Standard title for standard resolution, original title if not standard resolution
String title = videoManager.getDisplayTitleForResolution(videoTranscoding.getResolution(), getTranslator());
displayTitles.add(title);
}
}
mainVC.contextPut("addMaster", addMaster);
mainVC.contextPut("masterTitle", masterTitle + masterSize);
mainVC.contextPut("videos", readyToPlayVideos);
mainVC.contextPut("displayTitles", displayTitles);
mainVC.contextPut("useSourceChooser", Boolean.valueOf(readyToPlayVideos.size() > 1));
mainVC.contextPut(GUIPREF_KEY_PREFERRED_RESOLUTION, preferredAvailableResolution);
// Check for null-value posters
VFSLeaf poster = videoManager.getPosterframe(entry.getOlatResource());
mainVC.contextPut("usePoster", Boolean.valueOf(poster != null && poster.getSize() > 0));
// Load the track from config
Map<String, String> trackfiles = new HashMap<String, String>();
Map<String, VFSLeaf> configTracks = videoManager.getAllTracks(entry.getOlatResource());
for (HashMap.Entry<String, VFSLeaf> track : configTracks.entrySet()) {
trackfiles.put(track.getKey(), track.getValue().getName());
}
mainVC.contextPut("trackfiles", trackfiles);
// Load video chapter if available
mainVC.contextPut("hasChapters", videoManager.hasChapters(entry.getOlatResource()));
// Add duration without preloading video
String duration = entry.getExpenditureOfWork();
if (!StringHelper.containsNonWhitespace(duration)) {
duration = "00:00";
}
mainVC.contextPut("duration", duration);
}
}
use of org.olat.modules.video.VideoTranscoding in project OpenOLAT by OpenOLAT.
the class VideoTranscodingDAOTest method getVideoTranscodingByKey.
@Test
public void getVideoTranscodingByKey() {
OLATResource resource = JunitTestHelper.createRandomResource();
VideoTranscoding vTranscoding = videoTranscodingDao.createVideoTranscoding(resource, 1080, "mp4");
dbInstance.commitAndCloseSession();
VideoTranscoding reloadedTranscoding = videoTranscodingDao.getVideoTranscoding(vTranscoding.getKey());
Assert.assertNotNull(reloadedTranscoding);
Assert.assertEquals(vTranscoding, reloadedTranscoding);
}
use of org.olat.modules.video.VideoTranscoding in project OpenOLAT by OpenOLAT.
the class VideoTranscodingDAOTest method deleteVideoTranscoding.
@Test
public void deleteVideoTranscoding() {
// void deleteVideoTranscoding(VideoTranscoding videoTranscoding) {
OLATResource resource = JunitTestHelper.createRandomResource();
// prepare transcodings
VideoTranscoding vTranscoding1 = videoTranscodingDao.createVideoTranscoding(resource, 1080, "mp4");
videoTranscodingDao.createVideoTranscoding(resource, 720, "mp4");
videoTranscodingDao.createVideoTranscoding(resource, 720, "mp4");
videoTranscodingDao.createVideoTranscoding(resource, 720, "mp4");
dbInstance.commitAndCloseSession();
// delete single transcoding
videoTranscodingDao.deleteVideoTranscoding(vTranscoding1);
dbInstance.commitAndCloseSession();
List<VideoTranscoding> results = videoTranscodingDao.getVideoTranscodings(resource);
Assert.assertEquals(3, results.size());
// delete all transcodings of resource
videoTranscodingDao.deleteVideoTranscodings(resource);
dbInstance.commitAndCloseSession();
results = videoTranscodingDao.getVideoTranscodings(resource);
Assert.assertEquals(0, results.size());
}
use of org.olat.modules.video.VideoTranscoding in project openolat by klemens.
the class VideoManagerImpl method startTranscodingProcess.
@Override
public void startTranscodingProcess(OLATResource video) {
List<VideoTranscoding> existingTranscodings = getVideoTranscodings(video);
VideoMeta videoMetadata = getVideoMetadata(video);
int height = videoMetadata.getHeight();
// 1) setup transcoding job for original file size
createTranscodingIfNotCreatedAlready(video, height, VideoTranscoding.FORMAT_MP4, existingTranscodings);
// 2) setup transcoding jobs for all configured sizes below the original size
int[] resolutions = videoModule.getTranscodingResolutions();
for (int resolution : resolutions) {
if (height <= resolution) {
continue;
}
createTranscodingIfNotCreatedAlready(video, resolution, VideoTranscoding.FORMAT_MP4, existingTranscodings);
}
// 3) Start transcoding immediately, force job execution
if (videoModule.isTranscodingLocal()) {
try {
scheduler.triggerJob(videoJobKey);
} catch (SchedulerException e) {
log.error("Error while starting video transcoding job", e);
}
}
}
use of org.olat.modules.video.VideoTranscoding 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;
}
Aggregations