通过javacv对视频每隔1秒钟截取1张图片
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.bytedeco.javacpp.Loader.load(Loader.java:385)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2249)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:346)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:340)
http://stackoverflow.com/questions/27733142/could-not-initialize-class-org-bytedeco-javacpp-avutil-on-os-x-along-with-maven
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.0</version>
</dependency>
FFmpegFrameGrabber g = new FFmpegFrameGrabber("textures/video/anim.mp4");
g.start();
for (int i = 0 ; i < 50 ; i++) {
ImageIO.write(g.grab().getBufferedImage(), "png", new File("frame-dump/video-frame-" + System.currentTimeMillis() + ".png"));
}
g.stop();
http://stackoverflow.com/questions/15735716/how-can-i-get-a-frame-sample-jpeg-from-a-video-mov
https://github.com/bytedeco/javacv/
JavaCV 随机获取视频中的某些帧的图片
package com.egova.ffmpeg.java; import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import javax.imageio.ImageIO; import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FrameGrabber.Exception;
import org.bytedeco.javacv.Java2DFrameConverter; public abstract class FrameGrabberKit { public static void main(String[] args) throws Exception {
randomGrabberFFmpegImage("F:/CodeSpace/java/ffmpeg_java/resource/月赋情长.mp4", "./target", "月赋情长", 10);
} public static void randomGrabberFFmpegImage(String filePath, String targerFilePath, String targetFileName, int randomSize)
throws Exception {
FFmpegFrameGrabber ff = FFmpegFrameGrabber.createDefault(filePath);
ff.start();
int ffLength = ff.getLengthInFrames();
List<Integer> randomGrab = random(ffLength, randomSize);
int maxRandomGrab = randomGrab.get(randomGrab.size() - 1);
Frame f;
int i = 0;
while (i < ffLength) {
f = ff.grabImage();
if (randomGrab.contains(i)) {
doExecuteFrame(f, targerFilePath, targetFileName, i);
}
if (i >= maxRandomGrab) {
break;
}
i++;
}
ff.stop();
} public static void doExecuteFrame(Frame f, String targerFilePath, String targetFileName, int index) {
if (null == f || null == f.image) {
return;
} Java2DFrameConverter converter = new Java2DFrameConverter(); String imageMat = "jpg";
String FileName = targerFilePath + File.separator + targetFileName + "_" + index + "." + imageMat;
BufferedImage bi = converter.getBufferedImage(f);
File output = new File(FileName);
try {
ImageIO.write(bi, imageMat, output);
} catch (IOException e) {
e.printStackTrace();
}
} public static List<Integer> random(int baseNum, int length) { List<Integer> list = new ArrayList<>(length);
while (list.size() < length) {
Integer next = (int) (Math.random() * baseNum);
if (list.contains(next)) {
continue;
}
list.add(next);
}
Collections.sort(list);
return list;
}
}
之前每一秒钟截取一张图片,发现有些图片报了“[mpeg4 @ 05938aa0] warning: first frame is no keyframe”这个警告,而且截出的图片都是灰屏,根本没有图片。后来在网上找了很久,终于弄明白了,原来是ffmpeg它有“关键帧”这个说法,所以如果设置的帧的位置不是关键帧的位置的话,就可能截出的图片有问题。后来经过改进,终于搞定了。
public static void main(String[] args) {
System.out.println(System.getProperty("java.library.path"));
// System.out.println("Welcome to OpenCV " + Core.VERSION);
// System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
// System.out.println("m = " + m.dump());
// 加载本地的OpenCV库,这样就可以用它来调用Java API
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Test t = new Test();
// t.test();
// t.run();
// t.run2();
t.run3();
// System.out.println(t.CmpPic("d:/img/219.jpg"));
}
public void run3() {
CvCapture capture = opencv_highgui.cvCreateFileCapture("D:/085402.crf");
//帧率
int fps = (int) opencv_highgui.cvGetCaptureProperty(capture, opencv_highgui.CV_CAP_PROP_FPS);
System.out.println("帧率:"+fps);
IplImage frame = null;
double pos1 = 0;
int rootCount = 0;
while (true) {
//读取关键帧
frame = opencv_highgui.cvQueryFrame(capture);
rootCount = fps;
while(rootCount > 0 ){
//这一段的目的是跳过每一秒钟的帧数,也就是说fps是帧率(一秒钟有多少帧),在读取一帧后,跳过fps数量的帧就相当于跳过了1秒钟。
frame = opencv_highgui.cvQueryFrame(capture);
rootCount--;
}
//获取当前帧的位置
pos1 = opencv_highgui.cvGetCaptureProperty(capture,opencv_highgui.CV_CAP_PROP_POS_FRAMES);
System.out.println(pos1);
if (null == frame)
break;
opencv_highgui.cvSaveImage("d:/img/" + pos1 + ".jpg",frame);
}
opencv_highgui.cvReleaseCapture(capture);
}
http://www.voidcn.com/blog/kouwoo/article/p-4830734.html
http://stackoverflow.com/questions/33319899/java-lang-unsatisfiedlinkerror-no-opencv-java300-in-java-library-path-only-whil
http://git.oschina.net/leixiaohua1020/simplest_video_website
https://ffmpeg.zeranoe.com/builds/
通过javacv对视频每隔1秒钟截取1张图片的更多相关文章
- 使用 jQuery 中的淡入淡出动画,实现图片的轮播效果,每隔 2 秒钟切换一张图片,共 6 张图片
查看本章节 查看作业目录 需求说明: 使用 jQuery 中的淡入淡出动画,实现图片的轮播效果,每隔 2 秒钟切换一张图片,共 6 张图片,切换到第 6 张后从头开始切换,在图片的下方显示 6 个小圆 ...
- Java 数量为5的线程池同时运行5个窗口买票,每隔一秒钟卖一张票
/** * 1.创建线程数量为5的线程池 * 2.同时运行5个买票窗口 * 3.总票数为100,每隔一秒钟卖一张票 * @author Administrator * */ public class ...
- Python每隔一秒钟打印当地时间
import threading,time global t def sayHello(): print time.strftime('%Y-%m-%d %H:%M:%S',time.localtim ...
- 使用JavaCV播放视频、摄像头、人脸识别
一.导入Maven依赖包 <dependencies> <!-- https://mvnrepository.com/artifact/org.bytedeco/javacv-pla ...
- 每隔10秒钟打印一个“Helloworld”
/** * 每隔10秒钟打印一个“Helloworld” */ public class Test03 { public static void main(String[] args) throws ...
- 定时器每隔10秒钟刷新一次jqgrid
//console.log('每隔*秒钟刷新一次'); var timer = window.setInterval(function() { $("#table_list_1") ...
- shell每隔一秒钟就记录下netstat状态
说明 木马可能类似随机发送心跳包的操作,随机sleep.对这类情况写好了一个监听shell脚本,每隔一秒钟就记录下netstat状态. 代码 #!/bin/bash #功能:用于定时执行lsof 和 ...
- javacv获取视频第一帧
第一种是用ffmpeg工具,不过还得安装客户端软件,于是放弃了,还有一种是javacv开源工具,所以选择第二种: 第一种:ffmpeg工具 需要安装ffmpeg软件,支持windows和linux,视 ...
- OpenCV计算机视觉学习(1)——图像基本操作(图像视频读取,ROI区域截取,常用cv函数解释)
1,计算机眼中的图像 我们打开经典的 Lena图片,看看计算机是如何看待图片的: 我们点击图中的一个小格子,发现计算机会将其分为R,G,B三种通道.每个通道分别由一堆0~256之间的数字组成,那Ope ...
随机推荐
- python3中numpy函数tile的用法
tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组.比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题 ...
- HDU 1214 圆桌会议 圆环逆序
http://acm.hdu.edu.cn/showproblem.php?pid=1214 题目大意: 一群人围着桌子座,如果在一分钟内一对相邻的人交换位置,问多少分钟后才能得到与原始状态相反的座位 ...
- JVM学习:方法重载的优先级
重载:方法名一致,参数长度或者类型不一致. 先放总结,下面为例子 参数具有继承.实现关系,优先考虑子类: 在不考虑对基本类型自动装拆箱(auto-boxing,auto-unboxing),以及可变长 ...
- 初识OpenStack(1)
初识OpenStack(1) 首先 先来说说我与openstack的渊源吧.那是在上个月中旬.学张的一个朋友给我打电话说让一起来搞一个云平台,当时也不知道是什么.就非常高兴的答应下来了,到了周末,就过 ...
- linux下查看动态链接库依赖关系的命令 x86: ldd *.so arm: arm-linux-readelf -d *.so 实际例子: 以项目中用到的库librtsp.so分析: lijun@ubuntu:~/workspace$ arm-hisiv100nptl-linux-ld -d librtsp.so arm-hisiv100nptl-linux-ld:
linux下查看动态链接库依赖关系的命令 x86:ldd *.so arm:arm-linux-readelf -d *.so 实际例子:以项目中用到的库librtsp.so分析:l ...
- FATFS在SD卡里,写入多行数据出的问题
串口接收的数据存入数组,然后把数组截取有效部分,存入SD卡里的一行没有问题 但是从SD卡读出这一行之后,重新写入SD卡就有了问题,经过调试发现,错误在于 \n 一直是这一串数据,为什么会出错呢??? ...
- 【微信小程序】自定义模态框实例
原文链接:https://mp.weixin.qq.com/s/23wPVFUGY-lsTiQBtUdhXA 1 概述 由于官方API提供的显示模态弹窗,只能简单地显示文字内容,不能对对话框内容进行自 ...
- 微服务API模拟框架frock介绍
本文来源于我在InfoQ中文站翻译的文章,原文地址是:http://www.infoq.com/cn/news/2016/02/introducing-frock Urban Airship是一家帮助 ...
- js实现操作等待提示loading……
js实现操作等待功能,防止重复提交,界面友好,底部为灰色遮罩层,防止用户重复操作. 先看效果图: 接着看js代码: //关闭等待窗口 function closeWaiting() { var b ...
- solaris 11 stdio.h: No such file or directory
http://www.zendo.name/solaris-11-stdio-h%EF%BC%9A-no-such-file-or-directory/ Posted on 2012 年 3 月 23 ...