java 截取视频帧、视频相关信息

 视频帧截取,处理类(ffmpeg.exe

 

import java.io.IOException;

/**
 *  文件信息处理公共类
 *
 * @author com.fhy.xyb
 * @date  2014-6-30 上午09:08:29
 * 
 *
 */
public class FileUtil {
	
	/**
	 * 获取WEB-INF目录下面的文件路径
	 * 
	 *@author com.fhy.xyb
	 *@createTime 上午09:14:42
	 *@createTime 上午09:14:42
	 */
	public String getFilePath(String fileName){
		
		//获取WEB-INF全路径
		String filepath = Thread.currentThread().getContextClassLoader().getResource("").toString();
		//将/换成\
		filepath = filepath.replace("/", "\\");
		//去掉file
		filepath = filepath.replace("file:", "");
		//去掉class\
		filepath = filepath.replace("classes\\", "");
		//去掉第一个\
		filepath = filepath.substring(1);
		//得到文件全路径
		filepath = filepath+fileName;
		return filepath;
	}
	
	/**
	 * 视频帧截取处理方法
	 * ffmpeg.exe文件限定WEB-INF下
	 *@author com.fhy.xyb
	 *@createTime 上午11:35:53
	 *@createTime 上午11:35:53
	 */
	@SuppressWarnings("unused")
	public boolean createVideoFrame(String videoLocation, String imageLocation,String fileName,long playLength) {
		FileUtil file  = new FileUtil();
		//调用runtime使应用程序能够与其运行的环境相连接
		Runtime runtime = Runtime.getRuntime();
		String cmd	= "";
		Process proce = null;		
		//拼接cmd命令
		String cut = " "+ file.getFilePath(fileName)+ " -i "+ videoLocation
					+ " -y -f image2 -ss " + playLength/2/1000 + " -t 0.001 -s 352x240 " + imageLocation;
		
		System.out.println(cut);
		String cutCmd = cmd + cut;
		try {
			proce = runtime.exec(cutCmd);
			return true;
		} catch (IOException e1) {
			e1.printStackTrace();
			return false;
		}
	}
}

 

  获取视频信息              

                Encoder encoder = new Encoder();
		File fileServiceUlrl = new File(path);
		try {
			System.out.println(fileServiceUlrl.length());
			MultimediaInfo m = encoder.getInfo(fileServiceUlrl);
			AudioInfo info = m.getAudio();
			material.setLength((int) m.getDuration());
			material.setCodedFormat(info.getDecoder());
			material.setSize((int) file.getSize());
			material.setBitRate(Integer.toString(info.getBitRate()));
			material.setSamplingRate(Integer.toString(info.getSamplingRate()));
		} catch (InputFormatException e) {
			System.out.println("读取文件失败");
			e.printStackTrace();
		} catch (EncoderException e) {
			System.out.println("编码错误");
			e.printStackTrace();
		}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值