use of org.olat.core.commons.services.video.spi.FLVParser in project OpenOLAT by OpenOLAT.
the class MovieServiceImpl method getSize.
@Override
public Size getSize(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 null;
}
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);
org.jcodec.common.model.Size size = demuxer1.getMovie().getDisplaySize();
// Case 1: standard case, get dimension from movie
int w = size.getWidth();
int h = size.getHeight();
// Case 2: landscape movie from iOS: width and height is negative, no dunny why
if (w < 0 && h < 0) {
w = 0 - w;
h = 0 - h;
}
if (w == 0) {
// something in the track box.
try {
// This code is the way it is just because I don't know
// how to safely read the rotation/portrait/landscape
// flag of the movie. Those mp4 guys are really
// secretive folks, did not find any documentation about
// this. Best guess.
org.jcodec.common.model.Size size2 = demuxer1.getVideoTrack().getBox().getCodedSize();
w = size2.getHeight();
h = size2.getWidth();
} catch (Exception e) {
log.debug("can not get size from box " + e.getMessage());
}
}
return new Size(w, h, false);
} catch (Exception | AssertionError e) {
log.error("Cannot extract size of: " + media, e);
}
} else if (suffix.equals("flv")) {
try (InputStream stream = new FileInputStream(file)) {
FLVParser infos = new FLVParser();
infos.parse(stream);
if (infos.getWidth() > 0 && infos.getHeight() > 0) {
int w = infos.getWidth();
int h = infos.getHeight();
return new Size(w, h, false);
}
} catch (Exception e) {
log.error("Cannot extract size of: " + media, e);
}
}
return null;
}
use of org.olat.core.commons.services.video.spi.FLVParser in project openolat by klemens.
the class MovieServiceImpl method getSize.
@Override
public Size getSize(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 null;
}
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);
org.jcodec.common.model.Size size = demuxer1.getMovie().getDisplaySize();
// Case 1: standard case, get dimension from movie
int w = size.getWidth();
int h = size.getHeight();
// Case 2: landscape movie from iOS: width and height is negative, no dunny why
if (w < 0 && h < 0) {
w = 0 - w;
h = 0 - h;
}
if (w == 0) {
// something in the track box.
try {
// This code is the way it is just because I don't know
// how to safely read the rotation/portrait/landscape
// flag of the movie. Those mp4 guys are really
// secretive folks, did not find any documentation about
// this. Best guess.
org.jcodec.common.model.Size size2 = demuxer1.getVideoTrack().getBox().getCodedSize();
w = size2.getHeight();
h = size2.getWidth();
} catch (Exception e) {
log.debug("can not get size from box " + e.getMessage());
}
}
return new Size(w, h, false);
} catch (Exception | AssertionError e) {
log.error("Cannot extract size of: " + media, e);
}
} else if (suffix.equals("flv")) {
try (InputStream stream = new FileInputStream(file)) {
FLVParser infos = new FLVParser();
infos.parse(stream);
if (infos.getWidth() > 0 && infos.getHeight() > 0) {
int w = infos.getWidth();
int h = infos.getHeight();
return new Size(w, h, false);
}
} catch (Exception e) {
log.error("Cannot extract size of: " + media, e);
}
}
return null;
}
Aggregations