1、先导包
<dependency><groupId>ws.schildgroupId><artifactId>jave-all-depsartifactId><version>2.6.0version>dependency>
获取时长
@Test public void test01() { // 视频时长 long time = 0; try { String url = "http://xxxx.mp4"; MultimediaObject media = new MultimediaObject(new URL(url)); MultimediaInfo info = media.getInfo(); // 时长,毫秒级 long duration = info.getDuration(); // 毫秒级时长转化为秒 BigDecimal bigDecimal1 = new BigDecimal(duration); BigDecimal bigDecimal2 = new BigDecimal(1000); // 四舍五入,只保留整数 time = bigDecimal1.divide(bigDecimal2, 0, RoundingMode.HALF_UP).longValue(); // 获取媒体视频对象 VideoInfo video = info.getVideo(); // 码率 int bitRate = video.getBitRate(); // 帧率 float frameRate = video.getFrameRate(); // 分辨率-高 int height = video.getSize().getHeight(); // 分辨率-宽 int width = video.getSize().getWidth(); // 视频解码器名称 String decoder = video.getDecoder(); } catch (Exception e) { e.getMessage(); } System.out.println("时长:" + time); }
来源地址:https://blog.csdn.net/qq_42182034/article/details/129995390