use of org.jcodec.containers.mp4.boxes.MovieBox in project openolat by klemens.
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;
}
use of org.jcodec.containers.mp4.boxes.MovieBox 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;
}
Aggregations