Java 获取视频的各种数据(长宽 大小等)
1 package com.amigo.online.provider.manager.util.video.size; 2 import java.io.File; 3 import java.io.FileInputStream; 4 import java.io.IOException; 5 import java.math.BigDecimal; 6 import java.math.RoundingMode; 7 import java.nio.channels.FileChannel; 8 import com.amigo.online.provider.manager.util.param.dto.PageDto; 9 import it.sauronsoftware.jave.Encoder; 10 public class ReadVideo { 11 public static PageDto videosize(String video) { 12 File source = new File(video); 13 Encoder encoder = new Encoder(); 14 try { 15 it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(source); 16 PageDto page = new PageDto(); 17 page.setVideoHeight(m.getVideo().getSize().getHeight()); 18 page.setVideoWidth(m.getVideo().getSize().getWidth()); 19 return page; 20 // System.out.println("此视频高度为:"+m.getVideo().getSize().getHeight()); 21 // System.out.println("此视频宽度为:"+m.getVideo().getSize().getWidth()); 22 } catch (Exception e) { 23 e.printStackTrace(); 24 return null; 25 } 26 } 27 28 public static void main(String[] args) { 29 File source = new File("D:\\image\\a3.mp4"); 30 Encoder encoder = new Encoder(); 31 FileChannel fc = null; 32 String size = ""; 33 try { 34 it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(source); 35 long ls = m.getDuration(); 36 System.out.println("此视频时长为:" + ls / 60000 + "分" + (ls) / 1000 + "秒!"); 37 // 视频帧宽高 38 System.out.println("此视频高度为:" + m.getVideo().getSize().getHeight()); 39 System.out.println("此视频宽度为:" + m.getVideo().getSize().getWidth()); 40 System.out.println("此视频格式为:" + m.getFormat()); 41 FileInputStream fis = new FileInputStream(source); 42 fc = fis.getChannel(); 43 BigDecimal fileSize = new BigDecimal(fc.size()); 44 size = fileSize.divide(new BigDecimal(1048576), 2, 45 RoundingMode.HALF_UP) + "MB"; 46 System.out.println("此视频大小为" + size); 47 } catch (Exception e) { 48 e.printStackTrace(); 49 } finally { 50 if (null != fc) { 51 try { 52 fc.close(); 53 } catch (IOException e) { 54 e.printStackTrace(); 55 } 56 } 57 } 58 } 59 }
上述需要一个jar包:百度网盘 请输入提取码 密码:bd1h