导入 jar 包:可下载: Google 云盘地址
pox.xml
<dependencies>
<!-- jave核心包 -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-core</artifactId>
<version>2.4.6</version>
</dependency>
<!-- window64位 ffmpeg -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-native-win64</artifactId>
<version>2.4.6</version>
</dependency>
<!-- linux64位 ffmpeg -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-native-linux64</artifactId>
<version>2.4.6</version>
</dependency>
<!-- Mac ffmpeg -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-native-osx64</artifactId>
<version>2.4.6</version>
</dependency>
Java 代码:
public Long timeSum() throws EncoderException {
// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
String endpoint = "oss-cn-hangzhou.aliyuncs.com";
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
String accessKeyId = "LTAI4GEkaccessKeyId4GEk";
String accessKeySecret = "FeNwLwaccessKeySecretZQkEt";
// 填写Bucket名称,例如examplebucket。
String bucketName = "xihu-new";
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// String[] years = new String[]{"2021", "2022"};
String[] years = new String[]{"2020", "2021", "2022"};
String[] days = new String[]{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"};
String[] months = new String[]{
"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};
long totalSeconds = 0;
long i = 0;
for (String year : years) {
for (String month : months) {
for (String day : days) {
keyPrefix = "video/" + year + "/" + month + "/" + day + "/";
ObjectListing objectListing = ossClient.listObjects(new ListObjectsRequest(bucketName).withPrefix(keyPrefix));
List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
for (OSSObjectSummary s : sums) {
try {
String fileName = s.getKey();
// 视频地址 URL
String url = "https://xihu-new.oss-cn-hangzhou.aliyuncs.com/" + fileName;
File mediaFile = new File(url);
FfmpegFileInfo ffmpegFileInfo = new FfmpegFileInfo(mediaFile);
MultimediaInfo multimediaInfo = ffmpegFileInfo.getInfo(url);
long playTime = multimediaInfo.getDuration();
long seconds = playTime / 1000;
totalSeconds = seconds + totalSeconds;
i++;
System.out.println(keyPrefix + "......第 " + i + " 个视频 总视频总时长数:" + totalSeconds + " 秒");
} catch (Exception ignored) {
}
}
}
}
}
return totalSeconds
}
运行结果: