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张图片的更多相关文章

  1. 使用 jQuery 中的淡入淡出动画,实现图片的轮播效果,每隔 2 秒钟切换一张图片,共 6 张图片

    查看本章节 查看作业目录 需求说明: 使用 jQuery 中的淡入淡出动画,实现图片的轮播效果,每隔 2 秒钟切换一张图片,共 6 张图片,切换到第 6 张后从头开始切换,在图片的下方显示 6 个小圆 ...

  2. Java 数量为5的线程池同时运行5个窗口买票,每隔一秒钟卖一张票

    /** * 1.创建线程数量为5的线程池 * 2.同时运行5个买票窗口 * 3.总票数为100,每隔一秒钟卖一张票 * @author Administrator * */ public class ...

  3. Python每隔一秒钟打印当地时间

    import threading,time global t def sayHello(): print time.strftime('%Y-%m-%d %H:%M:%S',time.localtim ...

  4. 使用JavaCV播放视频、摄像头、人脸识别

    一.导入Maven依赖包 <dependencies> <!-- https://mvnrepository.com/artifact/org.bytedeco/javacv-pla ...

  5. 每隔10秒钟打印一个“Helloworld”

    /** * 每隔10秒钟打印一个“Helloworld” */ public class Test03 { public static void main(String[] args) throws ...

  6. 定时器每隔10秒钟刷新一次jqgrid

    //console.log('每隔*秒钟刷新一次'); var timer = window.setInterval(function() { $("#table_list_1") ...

  7. shell每隔一秒钟就记录下netstat状态

    说明 木马可能类似随机发送心跳包的操作,随机sleep.对这类情况写好了一个监听shell脚本,每隔一秒钟就记录下netstat状态. 代码 #!/bin/bash #功能:用于定时执行lsof 和 ...

  8. javacv获取视频第一帧

    第一种是用ffmpeg工具,不过还得安装客户端软件,于是放弃了,还有一种是javacv开源工具,所以选择第二种: 第一种:ffmpeg工具 需要安装ffmpeg软件,支持windows和linux,视 ...

  9. OpenCV计算机视觉学习(1)——图像基本操作(图像视频读取,ROI区域截取,常用cv函数解释)

    1,计算机眼中的图像 我们打开经典的 Lena图片,看看计算机是如何看待图片的: 我们点击图中的一个小格子,发现计算机会将其分为R,G,B三种通道.每个通道分别由一堆0~256之间的数字组成,那Ope ...

随机推荐

  1. UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂)

    UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂) 题目链接 题目大意:假设有一个合数.然后它满足随意大于1小于n的整数a, 满足a^n%n = a;这种合数叫做Ca ...

  2. php实现运气模型(命运随机,克服困难)

    php实现运气模型(命运随机,克服困难) 一.总结 1.应该用表格来布局的,这种多列的用表格布局比div和span布局方便很多 2.span标签设置宽度:变成行内快元素:display:inline- ...

  3. (转)把Sublime Text 2 加入右键菜单(带图标),Edit with Sublime Text

    转自 http://www.turen.me/archives/509 Sublime Text 2 是现在很受大家欢迎的编辑器了,不仅是在web前端,在书定简单的php.Js等代码时,也是相当的好用 ...

  4. 关于Altium Designer的一些设置

    把原理图设置成A4纸张,是为了便于打印机打印出原理图来 原理图一定一定要和pcb图保持一致,这样是为了以后查找错误方便...

  5. 每天一个JavaScript实例-操作元素定位元素

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  6. 网站访问优化(二):开启apache服务器gzip压缩

    昨天,把带宽从1M升级到2M,使用cdn版本的jquery之后,网站访问速度由平均5s(在禁止缓存的情况下,使用缓存大概在2.8s)下降到2.8s的样子. 今天,继续优化. 第1步:   把图片进行了 ...

  7. 创建ListView的基本步骤 分类: H1_ANDROID 2013-10-31 23:25 1276人阅读 评论(0) 收藏

    参考<疯狂android讲义>第2.5节P94 1.创建一个或者多个ListView <LinearLayout xmlns:android="http://schemas ...

  8. linux java配置环境变量

    export JAVA_HOME=/alidata/server/java/jdk1.8.0_65export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME ...

  9. 关于pptpd log日志文件的配置

    如何开启pptpd默认日志记录功能. 修改/etc/ppp/options.pptpd中的nologfd,默认没有开,把nologfd注释掉,然后添加 logfile /var/log/pptpd.l ...

  10. C++对象模型——对象成员的效率 (Object Member Efficiency)(第三章)

    3.5 对象成员的效率 (Object Mem ber Efficiency) 以下某个測试,目的在測试聚合(aggregation).封装(encapsulation),以及继承(Inheritan ...