Search in sources :

Example 26 with LocalFileImpl

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

the class WebDocumentRunController method getWebDocument.

private LocalFileImpl getWebDocument(RepositoryEntry entry) {
    OLATResource resource = entry.getOlatResource();
    VFSContainer fResourceFileroot = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
    LocalFileImpl document = null;
    for (VFSItem item : fResourceFileroot.getItems()) {
        if (item instanceof VFSLeaf && item instanceof LocalImpl) {
            LocalFileImpl localItem = (LocalFileImpl) item;
            if (localItem != null && !localItem.getBasefile().isHidden()) {
                document = (LocalFileImpl) item;
            }
        }
    }
    return document;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VFSItem(org.olat.core.util.vfs.VFSItem) LocalImpl(org.olat.core.util.vfs.LocalImpl)

Example 27 with LocalFileImpl

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

the class FileDocumentFactoryTest method getVFSFile.

private VFSLeaf getVFSFile(String filename) {
    try {
        URL url = FileDocumentFactoryTest.class.getResource(filename);
        File file = new File(url.toURI());
        return new LocalFileImpl(file);
    } catch (URISyntaxException e) {
        log.error("", e);
        return null;
    }
}
Also used : LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URL(java.net.URL)

Example 28 with LocalFileImpl

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

the class VideoFileResource method validate.

/**
 * @param file
 *            file to validate
 * @param fileName
 *            name of the file. Necessary since the file.filename contains
 *            gliberish during upload
 * @param eval the resource validation. Is set to valid if file is accepted
 */
public static void validate(File file, String fileName, ResourceEvaluation eval) {
    if (!videomodule.isEnabled()) {
        return;
    }
    // accept raw mp4 files
    // accept also mov files as iOS saves mp4 movis as mov, but check if the file can be parsed as mp4 file
    boolean isMP4 = movieService.isMP4(new LocalFileImpl(file), fileName);
    if (isMP4) {
        eval.setValid(true);
        eval.setDisplayname(fileName + " - " + Formatter.formatShortDateFilesystem(new Date()));
    } else if (fileName.endsWith(".zip")) {
        // check if zip contains an exported video resource
        videoManager.validateVideoExportArchive(file, eval);
    }
}
Also used : LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Date(java.util.Date)

Example 29 with LocalFileImpl

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

the class VideoHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String fileName) {
    // 1) Create resource and repository entry
    FileResource ores = new VideoFileResource();
    OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(ores);
    RepositoryEntry repoEntry = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    if (fileName == null) {
        fileName = file.getName();
    }
    fileName = fileName.toLowerCase();
    VFSLeaf importFile = new LocalFileImpl(file);
    long filesize = importFile.getSize();
    VideoManager videoManager = CoreSpringFactory.getImpl(VideoManager.class);
    if (fileName.endsWith(".mp4") || fileName.endsWith(".mov") || fileName.endsWith(".m4v")) {
        // 2a) import video from raw mp4 master video file
        videoManager.importFromMasterFile(repoEntry, importFile);
    } else if (fileName.endsWith(".zip")) {
        // 2b) import video from archive from another OpenOLAT instance
        DBFactory.getInstance().commit();
        videoManager.importFromExportArchive(repoEntry, importFile);
    }
    // 3) Persist Meta data
    videoManager.createVideoMetadata(repoEntry, filesize, fileName);
    DBFactory.getInstance().commit();
    // 4) start transcoding process if enabled
    videoManager.startTranscodingProcessIfEnabled(resource);
    return repoEntry;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VideoFileResource(org.olat.fileresource.types.VideoFileResource) FileResource(org.olat.fileresource.types.FileResource) VideoFileResource(org.olat.fileresource.types.VideoFileResource) OLATResource(org.olat.resource.OLATResource) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) VideoManager(org.olat.modules.video.VideoManager) RepositoryService(org.olat.repository.RepositoryService)

Example 30 with LocalFileImpl

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

the class VideoManagerImpl method getFrameWithFilter.

@Override
public boolean getFrameWithFilter(OLATResource videoResource, int frameNumber, long duration, VFSLeaf frame) {
    File videoFile = ((LocalFileImpl) getMasterVideoFile(videoResource)).getBasefile();
    BufferedImage bufImg = null;
    boolean imgBlack = true;
    int countBlack = 0;
    try (RandomAccessFile randomAccessFile = new RandomAccessFile(videoFile, "r")) {
        OutputStream frameOutputStream = frame.getOutputStream(false);
        FileChannel ch = randomAccessFile.getChannel();
        FileChannelWrapper in = new FileChannelWrapper(ch);
        FrameGrab frameGrab = new FrameGrab(in).seekToFrameSloppy(frameNumber);
        bufImg = frameGrab.getFrame();
        int xmin = bufImg.getMinX();
        int ymin = bufImg.getMinY();
        int xmax = xmin + bufImg.getWidth();
        int ymax = ymin + bufImg.getHeight();
        int pixelCount = bufImg.getWidth() * bufImg.getHeight();
        for (int x = xmin; x < xmax; x++) {
            for (int y = ymin; y < ymax; y++) {
                int rgb = bufImg.getRGB(x, y);
                // int alpha = (0xff000000 & rgb) >>> 24;
                int r = (0x00ff0000 & rgb) >> 16;
                int g = (0x0000ff00 & rgb) >> 8;
                int b = (0x000000ff & rgb);
                if (r < 30 && g < 30 && b < 30) {
                    countBlack++;
                }
            }
        }
        if (countBlack > (int) (0.7F * pixelCount)) {
            imgBlack = true;
        } else {
            imgBlack = false;
            ImageIO.write(bufImg, "JPG", frameOutputStream);
        }
        // avoid endless loop
        if (frameNumber > duration) {
            imgBlack = false;
        }
        // close everything to prevent resource leaks
        frameOutputStream.close();
        in.close();
        ch.close();
        return imgBlack;
    } catch (Exception | AssertionError e) {
        log.error("Could not get frame::" + frameNumber + " for video::" + videoFile.getAbsolutePath(), e);
        return false;
    }
}
Also used : 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) BufferedImage(java.awt.image.BufferedImage) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) FrameGrab(org.jcodec.api.FrameGrab) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

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