Search in sources :

Example 6 with MP4Demuxer

use of org.jcodec.containers.mp4.demuxer.MP4Demuxer in project OpenOLAT by OpenOLAT.

the class MovieServiceImpl method getFrameCount.

@Override
public long getFrameCount(VFSLeaf media, String suffix) {
    File file = null;
    if (media instanceof VFSCPNamedItem) {
        media = ((VFSCPNamedItem) media).getDelegate();
    }
    if (media instanceof LocalFileImpl) {
        file = ((LocalFileImpl) media).getBasefile();
    }
    if (file == null) {
        return -1;
    }
    if (extensions.contains(suffix)) {
        try (RandomAccessFile accessFile = new RandomAccessFile(file, "r")) {
            FileChannel ch = accessFile.getChannel();
            FileChannelWrapper in = new FileChannelWrapper(ch);
            MP4Demuxer demuxer1 = new MP4Demuxer(in);
            return demuxer1.getVideoTrack().getFrameCount();
        } catch (Exception | AssertionError e) {
            log.error("Cannot extract num. of frames of: " + media, e);
        }
    }
    return -1;
}
Also used : VFSCPNamedItem(org.olat.ims.cp.ui.VFSCPNamedItem) RandomAccessFile(java.io.RandomAccessFile) MP4Demuxer(org.jcodec.containers.mp4.demuxer.MP4Demuxer) FileChannel(java.nio.channels.FileChannel) FileChannelWrapper(org.jcodec.common.FileChannelWrapper) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) CannotGenerateThumbnailException(org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)

Example 7 with MP4Demuxer

use of org.jcodec.containers.mp4.demuxer.MP4Demuxer in project OpenOLAT by OpenOLAT.

the class MovieServiceImpl method getDuration.

@Override
public long getDuration(VFSLeaf media, String suffix) {
    File file = null;
    if (media instanceof VFSCPNamedItem) {
        media = ((VFSCPNamedItem) media).getDelegate();
    }
    if (media instanceof LocalFileImpl) {
        file = ((LocalFileImpl) media).getBasefile();
    }
    if (file == null) {
        return -1;
    }
    if (extensions.contains(suffix)) {
        try (RandomAccessFile accessFile = new RandomAccessFile(file, "r")) {
            FileChannel ch = accessFile.getChannel();
            FileChannelWrapper in = new FileChannelWrapper(ch);
            MP4Demuxer demuxer1 = new MP4Demuxer(in);
            MovieBox movie = demuxer1.getMovie();
            long duration = movie.getDuration();
            int timescale = movie.getTimescale();
            if (timescale < 1) {
                timescale = 1;
            }
            // Simple calculation. Ignore NTSC and other issues for now
            return duration / timescale * 1000;
        } catch (Exception | AssertionError e) {
            log.error("Cannot extract duration of: " + media, e);
        }
    }
    return -1;
}
Also used : MP4Demuxer(org.jcodec.containers.mp4.demuxer.MP4Demuxer) FileChannel(java.nio.channels.FileChannel) FileChannelWrapper(org.jcodec.common.FileChannelWrapper) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) CannotGenerateThumbnailException(org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException) VFSCPNamedItem(org.olat.ims.cp.ui.VFSCPNamedItem) RandomAccessFile(java.io.RandomAccessFile) MovieBox(org.jcodec.containers.mp4.boxes.MovieBox) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 8 with MP4Demuxer

use of org.jcodec.containers.mp4.demuxer.MP4Demuxer in project openolat by klemens.

the class MovieServiceImpl method getFrameCount.

@Override
public long getFrameCount(VFSLeaf media, String suffix) {
    File file = null;
    if (media instanceof VFSCPNamedItem) {
        media = ((VFSCPNamedItem) media).getDelegate();
    }
    if (media instanceof LocalFileImpl) {
        file = ((LocalFileImpl) media).getBasefile();
    }
    if (file == null) {
        return -1;
    }
    if (extensions.contains(suffix)) {
        try (RandomAccessFile accessFile = new RandomAccessFile(file, "r")) {
            FileChannel ch = accessFile.getChannel();
            FileChannelWrapper in = new FileChannelWrapper(ch);
            MP4Demuxer demuxer1 = new MP4Demuxer(in);
            return demuxer1.getVideoTrack().getFrameCount();
        } catch (Exception | AssertionError e) {
            log.error("Cannot extract num. of frames of: " + media, e);
        }
    }
    return -1;
}
Also used : VFSCPNamedItem(org.olat.ims.cp.ui.VFSCPNamedItem) RandomAccessFile(java.io.RandomAccessFile) MP4Demuxer(org.jcodec.containers.mp4.demuxer.MP4Demuxer) FileChannel(java.nio.channels.FileChannel) FileChannelWrapper(org.jcodec.common.FileChannelWrapper) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) CannotGenerateThumbnailException(org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)

Aggregations

File (java.io.File)8 RandomAccessFile (java.io.RandomAccessFile)8 FileChannel (java.nio.channels.FileChannel)8 FileChannelWrapper (org.jcodec.common.FileChannelWrapper)8 MP4Demuxer (org.jcodec.containers.mp4.demuxer.MP4Demuxer)8 CannotGenerateThumbnailException (org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)8 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)8 VFSCPNamedItem (org.olat.ims.cp.ui.VFSCPNamedItem)8 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 MovieBox (org.jcodec.containers.mp4.boxes.MovieBox)2 Size (org.olat.core.commons.services.image.Size)2 FinalSize (org.olat.core.commons.services.thumbnail.FinalSize)2 FLVParser (org.olat.core.commons.services.video.spi.FLVParser)2