//MAVEN 引用 <dependency> <groupId>org.mp4parser</groupId> <artifactId>isoparser</artifactId> <version>1.9.41</version> </dependency>
关键代码
String videoFilePath = tmpFile.getAbsolutePath();
File videoFile = new File(videoFilePath);
IsoFile isoFile = new IsoFile(new FileInputStream(videoFile).getChannel());
if (!videoFile.exists()) {
throw new FileNotFoundException("File " + videoFilePath + " not exists");
}
if (!videoFile.canRead()) {
throw new IllegalStateException("No read permissions to file " + videoFilePath);
}
MovieBox movieBox = org.mp4parser.tools.Path.getPath(isoFile, "moov");
// 可以打印这个 movieBox toString 看看里面有啥
List<Box> boxes = movieBox.getBoxes();
// 宽高时长获取
long duration = movieBox.getMovieHeaderBox().getDuration();
int width = 0;
int height = 0;
for (Box box : boxes) {
if (box instanceof TrackBox) {
TrackBox tBbx = (TrackBox) box;
width = (int) tBbx.getTrackHeaderBox().getWidth();
height = (int) tBbx.getTrackHeaderBox().getHeight();
break;
}
}
isoFile.close();