栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

javacv视频抽帧的实现过程详解(附代码)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

javacv视频抽帧的实现过程详解(附代码)

视频抽帧可以做一些处理,比如水印,去水印等操作,然后再合成视频。下面直接上代码:

引入maven步骤看javacv去水印的文章

这里直接上关键操作:

  
  public static List videoIntercept(File file, Integer start, Integer end) {
    frame frame = null;
    List files = Lists.newArrayList();
    FFmpegframeGrabber fFmpegframeGrabber = new FFmpegframeGrabber(file);
    String filePath = "D://video//images//";
    String fileTargetName = "movie";
    try {
      fFmpegframeGrabber.start();
      int ftp = fFmpegframeGrabber.getLengthInframes();
      System.out.println("开始视频提取帧");
      for (int i=0 ; i < ftp ; i++){
 if( i >= start && i <= end){
   frame = fFmpegframeGrabber.grabImage();
   doExecuteframe(frame, filePath, fileTargetName, i ,files);
 }
      }
      System.out.println("============运行结束============");
      fFmpegframeGrabber.stop();
    } catch (IOException E) {
//      Loggers.ERROR.error("视频抽帧异常", e);
    }
    return files;
  }

  public static void doExecuteframe(frame frame, String targetFilePath, String targetFileName, int index ,List files) {
    if ( frame == null || frame.image == null) {
      return;
    }
    Java2DframeConverter converter = new Java2DframeConverter();
    String imageMat = "jpg";
    String fileName = targetFilePath + targetFileName + "_" + index + "." + imageMat;
    BufferedImage bi = converter.getBufferedImage(frame);
    File output = new File(fileName);
    files.add(output);
    try{
      ImageIO.write(bi, imageMat, output);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
    List files = videoIntercept(new File("D://video//1553583033205-480p.mp4"), 10, 20);
    System.out.println(files);
  }

我们可以看到文件夹下抽取了视频的第10,20之间的帧。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/137666.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号