Search in sources :

Example 66 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class VideoManagerImpl method getFrame.

/**
 * write the the given frame at frameNumber in the frame leaf
 * @param videoResource videoresource
 * @param frameNumber the frameNumber at which the frame should be taken from
 * @param frame the VFSLeaf to write the picked image to
 */
@Override
public boolean getFrame(OLATResource videoResource, int frameNumber, VFSLeaf frame) {
    File videoFile = ((LocalFileImpl) getMasterVideoFile(videoResource)).getBasefile();
    try (RandomAccessFile randomAccessFile = new RandomAccessFile(videoFile, "r")) {
        FileChannel ch = randomAccessFile.getChannel();
        FileChannelWrapper in = new FileChannelWrapper(ch);
        FrameGrab frameGrab = new FrameGrab(in).seekToFrameSloppy(frameNumber);
        OutputStream frameOutputStream = frame.getOutputStream(false);
        BufferedImage bufImg = frameGrab.getFrame();
        ImageIO.write(bufImg, "JPG", frameOutputStream);
        // close everything to prevent resource leaks
        frameOutputStream.close();
        in.close();
        ch.close();
        return true;
    } catch (Exception | AssertionError e) {
        log.error("Could not get frame::" + frameNumber + " for video::" + videoFile.getAbsolutePath(), e);
        return false;
    }
}
Also used : FrameGrab(org.jcodec.api.FrameGrab) RandomAccessFile(java.io.RandomAccessFile) FileChannel(java.nio.channels.FileChannel) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileChannelWrapper(org.jcodec.common.FileChannelWrapper) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RandomAccessFile(java.io.RandomAccessFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException)

Example 67 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class VideoManagerImpl method hasVideoFile.

@Override
public boolean hasVideoFile(OLATResource videoResource) {
    VFSContainer masterContainer = getMasterContainer(videoResource);
    LocalFileImpl videoFile = (LocalFileImpl) masterContainer.resolve(FILENAME_VIDEO_MP4);
    return videoFile != null && videoFile.exists();
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 68 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

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);
    }
}
Also used : Crop(org.olat.core.commons.services.image.Crop) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VideoMeta(org.olat.modules.video.VideoMeta) Size(org.olat.core.commons.services.image.Size) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 69 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class CourseHandler method importGlossary.

private void importGlossary(ICourse course, Identity owner) {
    GlossaryManager gm = GlossaryManager.getInstance();
    RepositoryEntryImportExport importExport = gm.getRepositoryImportExport(course.getCourseExportDataDir().getBasefile());
    GlossaryResource resource = gm.createGlossary();
    if (resource == null) {
        log.error("Error adding glossary directry during repository reference import: " + importExport.getDisplayName());
        return;
    }
    // unzip contents
    VFSContainer glossaryContainer = gm.getGlossaryRootFolder(resource);
    File fExportedFile = importExport.importGetExportedFile();
    if (fExportedFile.exists()) {
        ZipUtil.unzip(new LocalFileImpl(fExportedFile), glossaryContainer);
    } else {
        log.warn("The actual contents of the glossary were not found in the export.");
    }
    // create repository entry
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
    RepositoryEntry importedRepositoryEntry = repositoryService.create(owner, null, importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
    // set the new glossary reference
    CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
    courseConfig.setGlossarySoftKey(importedRepositoryEntry.getSoftkey());
    CoreSpringFactory.getImpl(ReferenceManager.class).addReference(course, importedRepositoryEntry.getOlatResource(), GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER);
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
Also used : RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) GlossaryManager(org.olat.modules.glossary.GlossaryManager) File(java.io.File) GlossaryResource(org.olat.fileresource.types.GlossaryResource) RepositoryService(org.olat.repository.RepositoryService) CourseConfig(org.olat.course.config.CourseConfig) ReferenceManager(org.olat.resource.references.ReferenceManager)

Example 70 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class CourseHandler method importSharedFolder.

private void importSharedFolder(ICourse course, Identity owner) {
    SharedFolderManager sfm = SharedFolderManager.getInstance();
    RepositoryEntryImportExport importExport = sfm.getRepositoryImportExport(course.getCourseExportDataDir().getBasefile());
    SharedFolderFileResource resource = sfm.createSharedFolder();
    if (resource == null) {
        log.error("Error adding file resource during repository reference import: " + importExport.getDisplayName());
    }
    // unzip contents
    VFSContainer sfContainer = sfm.getSharedFolder(resource);
    File fExportedFile = importExport.importGetExportedFile();
    if (fExportedFile.exists()) {
        ZipUtil.unzip(new LocalFileImpl(fExportedFile), sfContainer);
    } else {
        log.warn("The actual contents of the shared folder were not found in the export.");
    }
    // create repository entry
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    OLATResource ores = OLATResourceManager.getInstance().findOrPersistResourceable(resource);
    RepositoryEntry importedRepositoryEntry = repositoryService.create(owner, null, importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), ores, 0);
    // set the new shared folder reference
    CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
    courseConfig.setSharedFolderSoftkey(importedRepositoryEntry.getSoftkey());
    CoreSpringFactory.getImpl(ReferenceManager.class).addReference(importedRepositoryEntry.getOlatResource(), course, SharedFolderManager.SHAREDFOLDERREF);
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
}
Also used : SharedFolderFileResource(org.olat.fileresource.types.SharedFolderFileResource) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) SharedFolderManager(org.olat.modules.sharedfolder.SharedFolderManager) RepositoryService(org.olat.repository.RepositoryService) CourseConfig(org.olat.course.config.CourseConfig) ReferenceManager(org.olat.resource.references.ReferenceManager)

Aggregations

LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)126 File (java.io.File)70 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 Size (org.olat.core.commons.services.image.Size)22 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 RandomAccessFile (java.io.RandomAccessFile)14 FileChannel (java.nio.channels.FileChannel)12 FileChannelWrapper (org.jcodec.common.FileChannelWrapper)12 CannotGenerateThumbnailException (org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)12 OLATResource (org.olat.resource.OLATResource)10 Date (java.util.Date)8 MP4Demuxer (org.jcodec.containers.mp4.demuxer.MP4Demuxer)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)8 VFSCPNamedItem (org.olat.ims.cp.ui.VFSCPNamedItem)8 BufferedImage (java.awt.image.BufferedImage)6 InputStream (java.io.InputStream)6