java获取视频的各种数据(长宽 大小等)

package com.amigo.online.provider.manager.util.video.size;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.math.BigDecimal;

import java.math.RoundingMode;

import java.nio.channels.FileChannel;

import com.amigo.online.provider.manager.util.param.dto.PageDto;

import it.sauronsoftware.jave.Encoder;

public class ReadVideo {

	public static PageDto videosize(String video) {
		File source = new File(video);
		Encoder encoder = new Encoder();
		try {
			it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(source);

			PageDto page = new PageDto();
			page.setVideoHeight(m.getVideo().getSize().getHeight());
			page.setVideoWidth(m.getVideo().getSize().getWidth());
			return page;
			// System.out.println("此视频高度为:"+m.getVideo().getSize().getHeight());
			// System.out.println("此视频宽度为:"+m.getVideo().getSize().getWidth());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}

	
	public static void main(String[] args) {

		File source = new File("D:\\image\\a3.mp4");

		Encoder encoder = new Encoder();

		FileChannel fc = null;

		String size = "";

		try {

			it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(source);

			long ls = m.getDuration();

			System.out.println("此视频时长为:" + ls / 60000 + "分" + (ls) / 1000 + "秒!");

			// 视频帧宽高

			System.out.println("此视频高度为:" + m.getVideo().getSize().getHeight());

			System.out.println("此视频宽度为:" + m.getVideo().getSize().getWidth());

			System.out.println("此视频格式为:" + m.getFormat());

			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";

			System.out.println("此视频大小为" + size);

		} catch (Exception e) {

			e.printStackTrace();

		} finally {

			if (null != fc) {

				try {

					fc.close();

				} catch (IOException e) {

					e.printStackTrace();

				}

			}

		}

	}

}
上述需要一个jar包:
    链接:https://pan.baidu.com/s/1nyPTC4VGynaKm1wzb-TMQA 密码:bd1h
    源自:http://www.sauronsoftware.it/projects/jave/index.php

 

你可能感兴趣的:(java菜鸟苦逼前进史)