use of org.olat.modules.video.VideoTranscoding in project openolat by klemens.
the class VideoAdminTranscodingController method queueCreateTranscoding.
// state orders for inexistent transcodings
private void queueCreateTranscoding(TranscodingRow source) {
List<VideoTranscoding> allVideoTranscodings = videoManager.getOneVideoResolution(source.getResolution());
Map<OLATResource, Set<Integer>> availableTranscodings = new HashMap<>();
for (VideoTranscoding videoTranscoding : allVideoTranscodings) {
if (availableTranscodings.containsKey(videoTranscoding.getVideoResource())) {
availableTranscodings.get(videoTranscoding.getVideoResource()).add(videoTranscoding.getResolution());
} else {
Set<Integer> availableresolutions = new HashSet<>();
availableresolutions.add(videoTranscoding.getResolution());
availableTranscodings.put(videoTranscoding.getVideoResource(), availableresolutions);
}
}
for (OLATResource videoResource : nativeResolutions.keySet()) {
if (availableTranscodings.get(videoResource) == null || !availableTranscodings.get(videoResource).contains(source.getResolution())) {
if (nativeResolutions.get(videoResource) >= source.getResolution()) {
videoManager.createTranscoding(videoResource, source.getResolution(), "mp4");
}
}
}
}
use of org.olat.modules.video.VideoTranscoding in project openolat by klemens.
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 klemens.
the class VideoQualityTableFormController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source instanceof FormLink && ((FormLink) source).getCmd().equals("viewQuality")) {
if (cmc == null) {
// initialize preview controller only once
previewVC = createVelocityContainer("video_preview");
cmc = new CloseableModalController(getWindowControl(), "close", previewVC);
listenTo(cmc);
}
// Get the user object from the link to access version object
FormLink link = (FormLink) source;
VideoTranscoding videoTranscoding = (VideoTranscoding) link.getUserObject();
if (videoTranscoding == null) {
// this is the master video
// VideoMetadata videoMetadata = videoManager.readVideoMetadataFile(videoResource);
VideoMeta videoMetadata = videoManager.getVideoMetadata(videoResource);
previewVC.contextPut("width", videoMetadata.getWidth());
previewVC.contextPut("height", videoMetadata.getHeight());
previewVC.contextPut("filename", "video.mp4");
VFSContainer container = videoManager.getMasterContainer(videoResource);
String transcodedUrl = registerMapper(ureq, new VideoMediaMapper(container));
previewVC.contextPut("mediaUrl", transcodedUrl);
} else {
// this is a version
previewVC.contextPut("width", videoTranscoding.getWidth());
previewVC.contextPut("height", videoTranscoding.getHeight());
previewVC.contextPut("filename", videoTranscoding.getResolution() + "video.mp4");
VFSContainer container = videoManager.getTranscodingContainer(videoResource);
String transcodedUrl = registerMapper(ureq, new VideoMediaMapper(container));
previewVC.contextPut("mediaUrl", transcodedUrl);
}
// activate dialog to bring it in front
cmc.activate();
} else if (source instanceof FormLink && ((FormLink) source).getCmd().equals("deleteQuality")) {
FormLink link = (FormLink) source;
VideoTranscoding videoTranscoding = (VideoTranscoding) link.getUserObject();
videoManager.deleteVideoTranscoding(videoTranscoding);
} else if (source instanceof FormLink && ((FormLink) source).getCmd().equals("startTranscoding")) {
videoManager.createTranscoding(videoResource, (int) source.getUserObject(), "mp4");
}
initTable();
}
use of org.olat.modules.video.VideoTranscoding in project OpenOLAT by OpenOLAT.
the class VideoAdminErrorController method initTable.
private void initTable() {
List<VideoTranscoding> videoTranscodings = videoManager.getFailedVideoTranscodings();
List<TranscodingQueueTableRow> rows = new ArrayList<>();
for (VideoTranscoding videoTranscoding : videoTranscodings) {
String title = videoManager.getDisplayTitleForResolution(videoTranscoding.getResolution(), getTranslator());
String resid = String.valueOf(videoTranscoding.getVideoResource().getResourceableId());
FormLink resourceLink = uifactory.addFormLink("res_" + counter++, "viewResource", resid, resid, flc, Link.LINK + Link.NONTRANSLATED);
resourceLink.setUserObject(videoTranscoding);
FormLink deleteLink = uifactory.addFormLink("del_" + counter++, "deleteQuality", "quality.delete", "quality.delete", flc, Link.LINK);
deleteLink.setUserObject(videoTranscoding);
deleteLink.setIconLeftCSS("o_icon o_icon_delete_item o_icon-fw");
FormLink retranscodeLink = uifactory.addFormLink("trans_" + counter++, "retranscode", "queue.retranscode", "queue.retranscode", flc, Link.LINK);
retranscodeLink.setUserObject(videoTranscoding);
retranscodeLink.setIconLeftCSS("o_icon o_icon_refresh o_icon-fw");
Object[] failureReason = new Object[] { -1, "" };
if (videoTranscoding.getStatus() == VideoTranscoding.TRANSCODING_STATUS_INEFFICIENT) {
failureReason[0] = VideoTranscoding.TRANSCODING_STATUS_INEFFICIENT;
failureReason[1] = translate("transcoding.inefficient");
} else if (videoTranscoding.getStatus() == VideoTranscoding.TRANSCODING_STATUS_ERROR) {
failureReason[0] = VideoTranscoding.TRANSCODING_STATUS_ERROR;
failureReason[1] = translate("transcoding.error");
} else if (videoTranscoding.getStatus() == VideoTranscoding.TRANSCODING_STATUS_TIMEOUT) {
failureReason[0] = VideoTranscoding.TRANSCODING_STATUS_TIMEOUT;
failureReason[1] = translate("transcoding.timeout");
}
RepositoryEntry videoRe = repositoryService.loadByResourceKey(videoTranscoding.getVideoResource().getKey());
if (videoRe == null)
continue;
String displayname = videoRe.getDisplayname();
String initialAuthor = videoRe.getInitialAuthor();
String fullName = userManager.getUserDisplayName(initialAuthor);
FormLink authorLink = uifactory.addFormLink("author_" + counter++, "viewAuthor", fullName, fullName, flc, Link.LINK + Link.NONTRANSLATED);
authorLink.setUserObject(initialAuthor);
Date creationDate = videoTranscoding.getCreationDate();
TranscodingQueueTableRow transcodingrow = new TranscodingQueueTableRow(resourceLink, displayname, creationDate, authorLink, title, null, videoTranscoding.getFormat(), deleteLink);
transcodingrow.setFailureReason(failureReason);
transcodingrow.setRetranscodeLink(retranscodeLink);
rows.add(transcodingrow);
}
tableModel.setObjects(rows);
if (flc.hasFormComponent(tableEl)) {
flc.remove(tableEl);
}
if (flc.hasFormComponent(refreshButton)) {
flc.remove(refreshButton);
}
tableEl = uifactory.addTableElement(getWindowControl(), "queue", tableModel, getTranslator(), flc);
tableEl.setCustomizeColumns(false);
tableEl.setNumOfRowsEnabled(false);
refreshButton = uifactory.addFormLink("button.refresh", flc, Link.BUTTON);
refreshButton.setIconLeftCSS("o_icon o_icon_refresh o_icon-fw");
}
use of org.olat.modules.video.VideoTranscoding in project OpenOLAT by OpenOLAT.
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);
}
}
}
Aggregations