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--
It is believed that many inexperienced people don't know what to do about how to decode the pictures in the video stream of H264 format by Java. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Introduce dependency
Org.bytedeco javacv 1.4.3 org.bytedeco.javacpp-presets ffmpeg-platform 4.0.2-1.4.3
It should be noted that there is a corresponding relationship between the versions of the two packages, which may cause problems if the versions do not correspond to each other.
Decoding process
A simple function to implement is:
Get the video input stream from Socket (H264 format) get the frames in the video stream and convert each frame to BufferedImage
Package com.amwalle.walle.raspi.camera;import org.bytedeco.javacv.FFmpegFrameGrabber;import org.bytedeco.javacv.Frame;import org.bytedeco.javacv.Java2DFrameConverter;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import java.awt.image.BufferedImage;import java.io.IOException;import java.io.InputStream;import java.net.Socket;public class CameraHandler implements Runnable {private static final Logger logger = LoggerFactory.getLogger (CameraHandler.class); private final String LOCK = "LOCK"; private Socket cameraSocket; private static BufferedImage bufferedImage CameraHandler (Socket socket) throws IOException {this.cameraSocket = socket;} String getLock () {return LOCK;} @ Override public void run () {try {InputStream cameraStream = cameraSocket.getInputStream (); FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber (cameraStream); frameGrabber.setFrameRate (30); frameGrabber.setFormat ("h364"); frameGrabber.setVideoBitrate (15); frameGrabber.setVideoOption ("preset", "ultrafast"); frameGrabber.setNumBuffers (25000000); frameGrabber.start (); Frame frame = frameGrabber.grab (); Java2DFrameConverter converter = new Java2DFrameConverter () While (frame! = null) {BufferedImage bufferedImage = converter.convert (frame); setBufferedImage (bufferedImage); synchronized (LOCK) {LOCK.notifyAll ();} frame = frameGrabber.grab ();}} catch (IOException e) {logger.info ("Video handle error, exit..."); logger.info (e.getMessage ());} private void setBufferedImage (BufferedImage image) {bufferedImage = image;} BufferedImage getBufferedImage () {return bufferedImage;}}
After reading the above, have you mastered how Java decodes the pictures in the H264 format video stream? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.