diff --git a/src/main/java/org/olat/core/commons/services/video/MovieServiceImpl.java b/src/main/java/org/olat/core/commons/services/video/MovieServiceImpl.java index 5f22f86038cf608b9b5299600122f8e69b94d593..36a935b05e3a4563c47380b85ed7dee1df9f05cb 100644 --- a/src/main/java/org/olat/core/commons/services/video/MovieServiceImpl.java +++ b/src/main/java/org/olat/core/commons/services/video/MovieServiceImpl.java @@ -99,8 +99,30 @@ public class MovieServiceImpl implements MovieService, ThumbnailSPI { FileChannelWrapper in = new FileChannelWrapper(ch); MP4Demuxer demuxer1 = new MP4Demuxer(in); org.jcodec.common.model.Size size = demuxer1.getMovie().getDisplaySize(); + // Case 1: standard case, get dimension from movie int w = size.getWidth(); int h = size.getHeight(); + // Case 2: landscape movie from iOS: width and height is negative, no dunny why + if (w < 0 && h < 0) { + w = 0 - w; + h = 0 - h; + } + if (w == 0) { + // Case 3: portrait movie from iOS: movie dimensions are not set, but there + // something in the track box. + try { + // This code is the way it is just because I don't know + // how to safely read the rotation/portrait/landscape + // flag of the movie. Those mp4 guys are really + // secretive folks, did not find any documentation about + // this. Best guess. + org.jcodec.common.model.Size size2 = demuxer1.getVideoTrack().getBox().getCodedSize(); + w = size2.getHeight(); + h = size2.getWidth(); + } catch(Exception e) { + log.debug("can not get size from box " + e.getMessage()); + } + } return new Size(w, h, false); } catch (Exception | AssertionError e) { log.error("Cannot extract size of: " + media, e); diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/elements/FileElement.java b/src/main/java/org/olat/core/gui/components/form/flexible/elements/FileElement.java index 7c1442120b410e4a6b5224677b2f36234e4ef954..4092fd8fa5257bbe04fe23e285c2f13b975b09f2 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/elements/FileElement.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/elements/FileElement.java @@ -135,6 +135,15 @@ public interface FileElement extends FormMultipartItem { */ public String getUploadFileName(); + /** + * Set the filename of the uploaded file. Use this if you want the final filename + * to be something different than file name from the upload. Whenever a file is + * uploaded again, this name is replaced again by the browser provided upload file name + * + * @param the uploaded file name + */ + public void setUploadFileName(String uploadFileName); + /** * The mime type is first looked up by servletContext.getMimeType(). If no * mime type is available, the browser supplied mime type is used. diff --git a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/FileElementImpl.java b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/FileElementImpl.java index 13bb290644e972e568660ec0075c37887b876f26..a74801a12275be33b6f1b954a1a76f6e1e4621dd 100644 --- a/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/FileElementImpl.java +++ b/src/main/java/org/olat/core/gui/components/form/flexible/impl/elements/FileElementImpl.java @@ -464,6 +464,12 @@ public class FileElementImpl extends FormItemImpl public String getUploadFileName() { return uploadFilename; } + + @Override + public void setUploadFileName(String uploadFileName) { + this.uploadFilename = uploadFileName; + this.uploadMimeType = WebappHelper.getMimeType(uploadFilename); + } /** * @see org.olat.core.gui.components.form.flexible.elements.FileElement#getUploadMimeType() diff --git a/src/main/java/org/olat/modules/webFeed/ui/podcast/EpisodeFormController.java b/src/main/java/org/olat/modules/webFeed/ui/podcast/EpisodeFormController.java index ce2aecd920ff6c33a9c15db7060b505c2c219b4f..ccb04522550caeb49718ae10b32f794e04f79b14 100644 --- a/src/main/java/org/olat/modules/webFeed/ui/podcast/EpisodeFormController.java +++ b/src/main/java/org/olat/modules/webFeed/ui/podcast/EpisodeFormController.java @@ -22,6 +22,8 @@ package org.olat.modules.webFeed.ui.podcast; import java.io.File; import java.util.Date; +import org.olat.core.commons.services.image.Size; +import org.olat.core.commons.services.video.MovieService; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; @@ -42,12 +44,15 @@ import org.olat.core.util.FileUtils; import org.olat.core.util.Formatter; import org.olat.core.util.StringHelper; import org.olat.core.util.WebappHelper; +import org.olat.core.util.vfs.LocalFileImpl; import org.olat.core.util.vfs.Quota; import org.olat.core.util.vfs.VFSContainer; +import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback; import org.olat.modules.webFeed.managers.FeedManager; import org.olat.modules.webFeed.models.Feed; import org.olat.modules.webFeed.models.Item; +import org.springframework.beans.factory.annotation.Autowired; /** * Provides a form for editing episode data (title, description, file ...) @@ -75,6 +80,9 @@ public class EpisodeFormController extends FormBasicController { private FileElement file; private FormLink cancelButton; + @Autowired + private MovieService movieService; + /** * @param ureq * @param control @@ -151,8 +159,23 @@ public class EpisodeFormController extends FormBasicController { file.clearError(); if (file.isUploadSuccess()) { - String newFilename = file.getUploadFileName(); - boolean isValidFileType = newFilename.toLowerCase().matches(MIME_TYPES_ALLOWED); + String newFilename = file.getUploadFileName().toLowerCase(); + VFSLeaf movie = new LocalFileImpl(file.getUploadFile()); + // remove spaces + newFilename = newFilename.replaceAll(" ", "_"); + file.setUploadFileName(newFilename); + + if (newFilename.endsWith("mov") || newFilename.endsWith("m4v")) { + // Check if it actually is a mp4 file, if so rename file to + // mp4 to make later processes work smoothly. MOV is used + // when uploading a video from an iOS device. + if (movieService.isMP4(movie, newFilename)) { + newFilename = newFilename.substring(0, newFilename.length() - 3) + "mp4"; + file.setUploadFileName(newFilename); + } + + } + boolean isValidFileType = newFilename.matches(MIME_TYPES_ALLOWED); boolean isFilenameValid = validateFilename(newFilename); if (!isValidFileType || !isFilenameValid) { if(!isValidFileType) { @@ -160,6 +183,17 @@ public class EpisodeFormController extends FormBasicController { } else if (!isFilenameValid) { file.setErrorKey("podcastfile.name.notvalid", null); } + } else { + // try to autodetect width and height for movies, prefill for user if possible + Size size = movieService.getSize(movie, FileUtils.getFileSuffix(newFilename)); + if (size != null) { + if (size.getWidth() > 1) { + widthEl.setValue(size.getWidth() + ""); + } + if (size.getHeight() > 1) { + heightEl.setValue(size.getHeight() + ""); + } + } } } }