In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how java uses OpenCV to get frames from video files. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
The details are as follows
Function: use Java to obtain image frames in mp4, mov, avi and other video files, get one image per second, and save the environment requirements: need to install Opencv, install FFmpeg, download javacv package operating system: the Ubuntu system used in this experiment
Experimental code
Import com.googlecode.javacv.cpp.opencv_highgui;import org.opencv.core.Core;import org.opencv.core.Mat;import org.opencv.highgui.Highgui;import org.opencv.highgui.VideoCapture / * Created by fang on 17-4-6.* realize the operation of capturing a picture and saving it locally every second the video is played * without using ffmpeg Can only read video in avi format * download opencv_ffmpeg_64.dll file in google javcv.jar* sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next* sudo apt-get update* sudo apt-get install ffmpeg* / home/fang/BigDataSoft/opencv-2.4.13/3rdparty/ffmpeg * cannot parse video Prompt: moov atom not found is a file error * / public class GetFrameFormVideo {public static void main (String [] args) {/ / 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 ()); / / load the local OpenCV library so that you can use it to call Java APISystem.loadLibrary (Core.NATIVE_LIBRARY_NAME); run2 ();} public static void run2 () {/ / read the video file VideoCapture cap = new VideoCapture ("/ home/fang/Downloads/src_11.mp4") System.out.println (cap.isOpened ()); / / determine whether the video is open if (cap.isOpened ()) {/ / Total number of frames double frameCount = cap.get (opencv_highgui.CV_CAP_PROP_FRAME_COUNT); System.out.println ("Total number of Video frames:" + frameCount); / / frame rate double fps = cap.get (opencv_highgui.CV_CAP_PROP_FPS); System.out.println ("Video frame rate" + fps); / / time length double len = frameCount / fps System.out.println ("total video duration:" + len); Double dudes = new Double (len); System.out.println (d_s.intValue ()); Mat frame = new Mat (); for (int I = 0; I < d_s.intValue (); iTunes +) {/ / set the position of the video (in milliseconds) cap.set (opencv_highgui.CV_CAP_PROP_POS_MSEC, I * 1000) / / read the next frame if (cap.read (frame)) {System.out.println ("saving"); / / Save the picture to the local directory Highgui.imwrite ("/ home/fang/images/" + I + ".jpg", frame);}} / / close the video file cap.release ();}
Errors that have occurred
When parsing the Mp4 file, it appeared: moov atom not found thought that ffmpeg was not installed correctly, went to the Internet to find a solution, and later found that there was a problem with his video file.
This is the end of the article on "how java uses OpenCV to get frames from video files". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.