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;
}
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;
}
}
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);
}
}
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;
}
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;
}
}
Aggregations