JSP ffmpeg实现视频截图

需要 ffmpeg.exe和 pthreadGC2.dll


jsp页面:

头文件引入 <%@page import="com.xxx.xxx.ffmpeg"%>

  <body>
      <%
        String ffmpegPath = "D://软件//tomcat//apache-tomcat-6.0.35//webapps//ffmpegTest//ffmpeg";//ffmpeg.exe和pthreadGC2.dll文件所在的文件夹路径
        String sourcePath = "D://软件//tomcat//apache-tomcat-6.0.35//webapps//ffmpegTest//video//video1.mp4";//视频所在路径
        String destPath = "D://软件//tomcat//apache-tomcat-6.0.35//webapps//ffmpegTest//video";//截取出来的图片文件保存到的路径
        String fileName = "good";//截取出来的图片文件名称
        int a = ffmpeg.videoIntercept(ffmpegPath, sourcePath, destPath, fileName);//调用java文件,执行截取
        out.print(a);
     %>
  </body>

java代码:

public class ffmpeg {
	public static int videoIntercept(String ffmpegPath, String sourcePath, String destPath, String fileName) throws IOException {
        // 目标路径不存在则建立目标路径
        File dest = new File(destPath);
        if (!dest.exists()) {
            dest.mkdirs();
        }
        // 源文件(视频)路径不存在则返回
        File source = new File(sourcePath);
        if (!source.exists()) {
            return 0;
        }


        Runtime rt = Runtime.getRuntime();//新建RunTime
        // 调用ffmpeg命令进行截图        

        try{
            //生成命令行,并调用ffmpeg命令生成600*500jpg文件
            String cmd = ffmpegPath + "//ffmpeg.exe -i " + sourcePath + " -y -f image2 -ss 8 -t 0.001 -s  600*500 " + destPath + "//" + fileName + ".jpg";
            rt.exec(cmd);
            return 1;
        }catch(IOException e) {
            e.printStackTrace();
            return 0;
        }
	}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值