use of org.olat.modules.video.VideoMeta in project OpenOLAT by OpenOLAT.
the class VideoMetaDataEditFormController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("tab.video.metaDataConfig");
OLATResource videoResource = repoEntry.getOlatResource();
VideoMeta videoMetadata = videoManager.getVideoMetadata(videoResource);
uifactory.addStaticTextElement("video.config.duration", repoEntry.getExpenditureOfWork(), formLayout);
uifactory.addStaticTextElement("video.config.width", String.valueOf(videoMetadata.getWidth()) + "px", formLayout);
uifactory.addStaticTextElement("video.config.height", String.valueOf(videoMetadata.getHeight()) + "px", formLayout);
String aspcectRatio = videoManager.getAspectRatio(videoMetadata.getWidth(), videoMetadata.getHeight());
uifactory.addStaticTextElement("video.config.ratio", aspcectRatio, formLayout);
uifactory.addStaticTextElement("video.config.creationDate", StringHelper.formatLocaleDateTime(videoResource.getCreationDate().getTime(), getLocale()), formLayout);
uifactory.addStaticTextElement("video.config.fileSize", Formatter.formatBytes(videoManager.getVideoFile(videoResource).length()), formLayout);
}
use of org.olat.modules.video.VideoMeta in project openolat by klemens.
the class VideoMetadataDAOTest method deleteVideoMetadata.
@Test
public void deleteVideoMetadata() {
RepositoryEntry entry0 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry1 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry2 = JunitTestHelper.createAndPersistRepositoryEntry();
RepositoryEntry entry3 = JunitTestHelper.createAndPersistRepositoryEntry();
// create metadata entries
VideoMeta meta0 = videoMetadataDao.createVideoMetadata(entry0, 1500, "vid.mp4");
VideoMeta meta1 = videoMetadataDao.createVideoMetadata(entry1, 1100, "vide.mp4");
VideoMeta meta2 = videoMetadataDao.createVideoMetadata(entry2, 1200, "video.mov");
VideoMeta meta3 = videoMetadataDao.createVideoMetadata(entry3, 4500, "videos.mp4");
Assert.assertNotNull(meta1);
Assert.assertNotNull(meta3);
Assert.assertNotNull(meta2);
Assert.assertNotNull(meta0);
dbInstance.commitAndCloseSession();
// retrieve list of entries
List<VideoMetaImpl> metadata = videoMetadataDao.getAllVideoResourcesMetadata();
Assert.assertTrue(metadata.contains(meta0));
Assert.assertTrue(metadata.contains(meta1));
Assert.assertTrue(metadata.contains(meta2));
Assert.assertTrue(metadata.contains(meta3));
// delete entries
int deleted0 = videoMetadataDao.deleteVideoMetadata(entry0.getOlatResource());
int deleted3 = videoMetadataDao.deleteVideoMetadata(entry3.getOlatResource());
Assert.assertEquals(1, deleted0);
Assert.assertNotEquals(0, deleted3);
dbInstance.commitAndCloseSession();
// retrieve new list
List<VideoMetaImpl> deleteMetadata = videoMetadataDao.getAllVideoResourcesMetadata();
Assert.assertFalse(deleteMetadata.contains(meta0));
Assert.assertTrue(deleteMetadata.contains(meta1));
Assert.assertTrue(deleteMetadata.contains(meta2));
Assert.assertFalse(deleteMetadata.contains(meta3));
}
use of org.olat.modules.video.VideoMeta in project openolat by klemens.
the class VideoManagerImpl method setPosterframeResizeUploadfile.
/**
* Sets the posterframe resize uploadfile. Tries to fit image to dimensions of video.
*
* @param videoResource the video resource
* @param posterframe the newPosterFile
*/
@Override
public void setPosterframeResizeUploadfile(OLATResource videoResource, VFSLeaf newPosterFile) {
VideoMeta videoMetadata = getVideoMetadata(videoResource);
Size posterRes = imageHelper.getSize(newPosterFile, FILETYPE_JPG);
// file size needs to be bigger than target resolution, otherwise use image as it comes
if (posterRes != null && posterRes.getHeight() != 0 && posterRes.getWidth() != 0 && posterRes.getHeight() >= videoMetadata.getHeight() && posterRes.getWidth() >= videoMetadata.getWidth()) {
VFSLeaf oldPosterFile = getPosterframe(videoResource);
oldPosterFile.delete();
VFSContainer masterContainer = getMasterContainer(videoResource);
LocalFileImpl newPoster = (LocalFileImpl) masterContainer.createChildLeaf(FILENAME_POSTER_JPG);
// to shrink image file, resolution ratio needs to be equal, otherwise crop from top left corner
if (posterRes.getHeight() / posterRes.getWidth() == videoMetadata.getHeight() / videoMetadata.getWidth()) {
imageHelper.scaleImage(newPosterFile, newPoster, videoMetadata.getWidth(), videoMetadata.getHeight(), true);
} else {
Crop cropSelection = new Crop(0, 0, videoMetadata.getHeight(), videoMetadata.getWidth());
imageHelper.cropImage(((LocalFileImpl) newPosterFile).getBasefile(), newPoster.getBasefile(), cropSelection);
}
} else {
setPosterframe(videoResource, newPosterFile);
}
}
use of org.olat.modules.video.VideoMeta in project openolat by klemens.
the class VideoManagerImpl method updateVideoMetadata.
@Override
public void updateVideoMetadata(OLATResource videoResource, VFSLeaf uploadVideo) {
VideoMeta meta = getVideoMetadata(videoResource);
Size dimensions = movieService.getSize(uploadVideo, VideoManagerImpl.FILETYPE_MP4);
// update video duration
long duration = movieService.getDuration(uploadVideo, VideoTranscoding.FORMAT_MP4);
if (duration != -1) {
String length = Formatter.formatTimecode(duration);
meta.setSize(uploadVideo.getSize());
meta.setWidth(dimensions.getWidth());
meta.setHeight(dimensions.getHeight());
meta.setFormat(FilenameUtils.getExtension(uploadVideo.getName()));
meta.setLength(length);
}
}
use of org.olat.modules.video.VideoMeta in project openolat by klemens.
the class VideoResourceEditController method doReplaceFileAndUpdateMetadata.
private int doReplaceFileAndUpdateMetadata() {
VFSLeaf video = (VFSLeaf) vfsContainer.resolve(VIDEO_RESOURCE);
File uploadFile = uploadFileEl.getUploadFile();
// VideoMetadata videoMetadata = videoManager.getMetaDataFromOLATResource(videoResource);
VideoMeta meta = videoManager.getVideoMetadata(videoResource);
if (uploadFileEl.getUploadSize() > 0 && uploadFile.exists()) {
video.delete();
VFSLeaf uploadVideo = vfsContainer.createChildLeaf(VIDEO_RESOURCE);
VFSManager.copyContent(uploadFile, uploadVideo);
// update video dimensions
Size dimensions = movieService.getSize(uploadVideo, VideoManagerImpl.FILETYPE_MP4);
// update video duration
long duration = movieService.getDuration(uploadVideo, VideoTranscoding.FORMAT_MP4);
// exchange poster
videoManager.exchangePoster(videoResource);
if (duration != -1) {
String length = Formatter.formatTimecode(duration);
entry.setExpenditureOfWork(length);
meta.setSize(uploadFile.length());
meta.setWidth(dimensions.getWidth());
meta.setHeight(dimensions.getHeight());
meta.setFormat(FilenameUtils.getExtension(uploadVideo.getName()));
meta.setLength(length);
}
}
return meta.getHeight();
}
Aggregations