用java从视频中提取帧的编解码器?
我正在从视频中提取帧,但到目前为止,我无法选择甚至运行代码。因此,如果您能给出方向,那么它可能会有所帮助。@Syed,我可以使用JavaCV 3.0从网络摄像头视频中提取帧,代码非常简单,但是JavaCV准备起来并不简单 为了使用JavaCV您需要在您的系统中安装所有必需的依赖项,否则您将不会停止出错 就我而言,我运行的是Ubuntu 14.04 64位。经过多次尝试,我决定编译JavaCV和OpenCV。通过这种方式,我最终能够安装所有必需的依赖项 我必须安装:用java从视频中提取帧的编解码器?,java,Java,我正在从视频中提取帧,但到目前为止,我无法选择甚至运行代码。因此,如果您能给出方向,那么它可能会有所帮助。@Syed,我可以使用JavaCV 3.0从网络摄像头视频中提取帧,代码非常简单,但是JavaCV准备起来并不简单 为了使用JavaCV您需要在您的系统中安装所有必需的依赖项,否则您将不会停止出错 就我而言,我运行的是Ubuntu 14.04 64位。经过多次尝试,我决定编译JavaCV和OpenCV。通过这种方式,我最终能够安装所有必需的依赖项 我必须安装:ffmpeg,flycaptur
ffmpeg
,flycapture
,libdc1394
,libfreenect
,videoinput
,artoolkitplus
,flandmark
和fftw
。如果您使用的是MS Windows,则这可能略有不同
我使用JavaCV捕获帧的代码基于Ben Davenport的示例代码,如下所示:
import org.bytedeco.javacpp.opencv_core.IplImage;
import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FrameRecorder.Exception;
import org.bytedeco.javacv.OpenCVFrameConverter;
import org.bytedeco.javacv.OpenCVFrameGrabber;
public class WebCamTest {
public static void main(String[] args) throws Exception, org.bytedeco.javacv.FrameGrabber.Exception {
//Here you have to put index number of grabber device, it depends on your system
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(1);
grabber.start();
CanvasFrame cFrame = new CanvasFrame(
"Capture Preview",
CanvasFrame.getDefaultGamma() / grabber.getGamma());
Frame capturedFrame = null;
OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
while ((capturedFrame = grabber.grab()) != null) {
if (cFrame.isVisible()) {
IplImage converted = converter.convert(capturedFrame);
// TODO: Do what you want if Captured IPLImage
// ...
}
}
cFrame.dispose();
grabber.stop();
}
}
希望有帮助
编辑
尝试使用此pom.xml
简化编译、打包和执行:
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>video-capture</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>WebCamTest</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
测试
视频捕获
罐子
0.0.1-快照
org.bytedeco
爪哇
1
${project.artifactId}
org.apache.maven.plugins
maven编译器插件
3.1
7.
7.
org.codehaus.mojo
execmaven插件
1.2.1
JAVA
网络摄像机测试
Xuggle、JMF和JAVACVAnd我将尝试使用ffmpegThanks-Malagunait@Syed,您正在使用GNU/Linux吗?基于Debian的发行版?如果是这样的话,我可以给你精确的指示,让你准备好JavaCV.Nah。我使用的windowsI构建源代码有:JavaCPP、JavaCPP预设(也可以从源代码OpenCV
、ffmpeg
、…)和JavaCV。但你不必这么做。安装我告诉过你的windows软件,注意32或64版本,然后在我的示例中试用。我编辑了我的答案,为您提供了一个示例pom.xml
,以便于代码管理。