简体   繁体   English

OpenCV Android(Java) --- 从 MP4 文件中提取帧

[英]OpenCV Android(Java) --- Extract frames from MP4 file

I am trying to read an MP4 file in OpenCV Java on Android Studio but having no success.我正在尝试在 Android Studio 上读取 OpenCV Java 中的 MP4 文件,但没有成功。 I create a VideoCapture object and pass the video as the argument to it but the videoCapture.read() method always returns false.我创建了一个 VideoCapture object 并将视频作为参数传递给它,但 videoCapture.read() 方法始终返回 false。 I know that the file exists at that path because I am able to use FFmpeg and MediaExtractor libraries to read the video at that path but IDK why OpenCV never succeeds.我知道该文件存在于该路径中,因为我能够使用 FFmpeg 和 MediaExtractor 库读取该路径中的视频,但 IDK 为什么 OpenCV 永远不会成功。 Also, I am able to process the same video file using OpenCV in Python.此外,我能够在 Python 中使用 OpenCV 处理相同的视频文件。

Here's a code snippet:这是一个代码片段:

VideoCapture camera = new VideoCapture(filePath);
            if(camera.read(imageMat)){
                System.out.println("read");
            }
            else{
                System.out.println("not read");
            }

ImageMat is the matrix I want to read my video frames into. ImageMat 是我想将视频帧读入的矩阵。

I would really appreciate if anyone has any suggestions/ resources on how to read a video file using OpenCV in Java/Android Studio.如果有人对如何在 Java/Android Studio 中使用 OpenCV 读取视频文件有任何建议/资源,我将不胜感激。

OpenCV doesn't support.mp4 video format. OpenCV 不支持.mp4 视频格式。 If you want to use OpenCV then please use the.avi video format.如果您想使用 OpenCV 请使用.avi 视频格式。

For more information you can refer to this medium post: blog有关更多信息,您可以参考这篇中篇文章: 博客

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM