一:pom依賴
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-all-deps</artifactId>
<version>2.5.1</version>
</dependency>
二:代碼
@Slf4j
public class VideoTimeUtil {
/**
* 視頻時長
*
* @param fileUrl
* @return String[] 0=秒時長,1=展示時長(格式如 01:00:00)
*/
public static String[] parseDuration(String fileUrl) {
String[] length = new String[2];
try {
//
// URL source = new URL(fileUrl);
// 構造方法 接受URL物件
// MultimediaObject instance = new MultimediaObject(source);
// 構造方法 接受File物件
MultimediaObject instance = new MultimediaObject(new File(fileUrl));
MultimediaInfo result = instance.getInfo();
Long ls = result.getDuration() / 1000;
length[0] = String.valueOf(ls);
Integer hour = (int) (ls / 3600);
Integer minute = (int) (ls % 3600) / 60;
Integer second = (int) (ls - hour * 3600 - minute * 60);
String hr = hour.toString();
String mi = minute.toString();
String se = second.toString();
if (hr.length() < 2) {
hr = "0" + hr;
}
if (mi.length() < 2) {
mi = "0" + mi;
}
if (se.length() < 2) {
se = "0" + se;
}
String noHour = "00";
if (noHour.equals(hr)) {
length[1] = mi + ":" + se;
} else {
length[1] = hr + ":" + mi + ":" + se;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return length;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/389004.html
標籤:其他
下一篇:opencv——學習筆記(一)
