jsp网站使用ffmpeg实现为.flv格式视频截图

ffmpeg.jsp文件
<body>      
  <%
        String ffmpegPath = "C:\\apache-tomcat-6.0.30\\webapps\\project001\\ffmpeg";//ffmpeg.exe和pthreadGC2.dll文件所在的文件夹路径
        String sourcePath = "C:\\apache-tomcat-6.0.30\\webapps\\project001\\flash\\good.flv";//视频所在路径
        String destPath = "C:\\apache-tomcat-6.0.30\\webapps\\project\\flash";//截取出来的图片文件保存到的路径
        String fileName = "good";//截取出来的图片文件名称
        int a = com.adouteam.www.util.ffmpeg.videoIntercept(ffmpegPath, sourcePath, destPath, fileName);//调用java文件,执行截取
     %>
</body>
com.adouteam.www.util.ffmpeg.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文件
            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;
        }
 }
注意点:1、图片生成路径destPath须与视频所在路径sourcePath相同
              2、命令行关键参数,"-ss 8"表示8秒的时候进行截取图片,"600*500"表示图片大小
              3、ffmpeg还有其他很多功能,这里只通过从视频截取图片作为示例,其他命令参考如下链接
              4、欢迎高手纠错
扩展Ffmpeg快速命令使用参考链接:

本文出自 “学海无涯” 博客,请务必保留此出处http://ijustdoit.blog.51cto.com/5682691/968414

转载于:https://my.oschina.net/ijustdoit/blog/207427

猜你喜欢

转载自blog.csdn.net/weixin_33720078/article/details/92055068
今日推荐