|
@@ -1,18 +1,37 @@
|
|
package cn.efunbox.audio.utils;
|
|
package cn.efunbox.audio.utils;
|
|
|
|
|
|
-import javazoom.jl.decoder.Bitstream;
|
|
|
|
import javazoom.jl.decoder.BitstreamException;
|
|
import javazoom.jl.decoder.BitstreamException;
|
|
-import javazoom.jl.decoder.Header;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import ws.schild.jave.MultimediaInfo;
|
|
|
|
+import ws.schild.jave.MultimediaObject;
|
|
|
|
|
|
-import java.io.BufferedInputStream;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.net.URL;
|
|
|
|
-import java.net.URLConnection;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.nio.channels.FileChannel;
|
|
|
|
|
|
|
|
+@Slf4j
|
|
public class Test {
|
|
public class Test {
|
|
public static void main(String[] args) throws IOException, BitstreamException {
|
|
public static void main(String[] args) throws IOException, BitstreamException {
|
|
- URL urlfile = new URL("http://sc1.111ttt.com/2015/1/06/06/99060941326.mp3");
|
|
|
|
- URLConnection con = null;
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// getFileList("H:\\7m");
|
|
|
|
+
|
|
|
|
+ File source = new File("http://baidu-yuwen-video.ai160.com/vs2m/001/00103052/00103052001/00103052001.m3u8");
|
|
|
|
+
|
|
|
|
+ String strFileName = source.getName();
|
|
|
|
+ String readVideoTime = ReadVideoTime(source);
|
|
|
|
+ String s = ReadVideoSize(source);
|
|
|
|
+
|
|
|
|
+ log.info("title : {} ,time : {},size : {}",strFileName,readVideoTime,s);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/* URL urlfile = new URL("http://ai-admin-audio.ai160.com/audio/001/00103035/00103035019.mp3");
|
|
|
|
+ URLConnection con = null;
|
|
try {
|
|
try {
|
|
con = urlfile.openConnection();
|
|
con = urlfile.openConnection();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
@@ -22,9 +41,92 @@ public class Test {
|
|
int b = con.getContentLength();//
|
|
int b = con.getContentLength();//
|
|
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
|
|
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
|
|
Bitstream bt = new Bitstream(bis);
|
|
Bitstream bt = new Bitstream(bis);
|
|
|
|
+
|
|
Header h = bt.readFrame();
|
|
Header h = bt.readFrame();
|
|
|
|
+ int bitrate = h.calculate_framesize();
|
|
|
|
+ System.out.println(bitrate);
|
|
int time = (int) h.total_ms(b);
|
|
int time = (int) h.total_ms(b);
|
|
- System.out.println(time / 1000);
|
|
|
|
- }
|
|
|
|
|
|
+ System.out.println(time / 1000);*/
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static void getFileList(String strPath) {
|
|
|
|
+ File dir = new File(strPath);
|
|
|
|
+ File[] files = dir.listFiles(); // 该文件目录下文件全部放入数组
|
|
|
|
+ if (files != null) {
|
|
|
|
+ for (int i = 0; i < files.length; i++) {
|
|
|
|
+ String fileName = files[i].getName();
|
|
|
|
+ if (files[i].isDirectory()) { // 判断是文件还是文件夹
|
|
|
|
+ getFileList(files[i].getAbsolutePath()); // 获取文件绝对路径
|
|
|
|
+ } else if (fileName.endsWith("ts")) { // 判断文件名是否以.avi结尾
|
|
|
|
+
|
|
|
|
+ File file = files[i];
|
|
|
|
+
|
|
|
|
+ String strFileName = files[i].getName();
|
|
|
|
+ String readVideoTime = ReadVideoTime(file);
|
|
|
|
+ String s = ReadVideoSize(file);
|
|
|
|
+
|
|
|
|
+ log.info("title : {} ,time : {},size : {}",strFileName,readVideoTime,s);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return
|
|
|
|
+ * @描述:获取视频时长
|
|
|
|
+ * @时间:2018年8月28日 上午10:18:59
|
|
|
|
+ */
|
|
|
|
+ static String ReadVideoTime(File source) {
|
|
|
|
+ String length = "";
|
|
|
|
+ try {
|
|
|
|
+ MultimediaObject instance = new MultimediaObject(source);
|
|
|
|
+ MultimediaInfo result = instance.getInfo();
|
|
|
|
+ long ls = result.getDuration() / 1000;
|
|
|
|
+ int hour = (int) (ls / 3600);
|
|
|
|
+ int minute = (int) (ls % 3600) / 60;
|
|
|
|
+ int second = (int) (ls - hour * 3600 - minute * 60);
|
|
|
|
+ length = hour + "'" + minute + "''" + second + "'''";
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return length;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param source
|
|
|
|
+ * @return
|
|
|
|
+ * @描述:获取视频大小
|
|
|
|
+ * @时间:2018年8月28日 上午10:30:17
|
|
|
|
+ */
|
|
|
|
+ @SuppressWarnings({"resource"})
|
|
|
|
+ static String ReadVideoSize(File source) {
|
|
|
|
+ FileChannel fc = null;
|
|
|
|
+ String size = "";
|
|
|
|
+ try {
|
|
|
|
+ FileInputStream fis = new FileInputStream(source);
|
|
|
|
+ fc = fis.getChannel();
|
|
|
|
+ BigDecimal fileSize = new BigDecimal(fc.size());
|
|
|
|
+ size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ if (null != fc) {
|
|
|
|
+ try {
|
|
|
|
+ fc.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return size;
|
|
|
|
+ }
|
|
}
|
|
}
|