您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
本文实例为大家分享了Java解码H264格式视频流中的图片,供大家参考,具体内容如下
引入依赖
<dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv</artifactId> <version>1.4.3</version> </dependency> <dependency> <groupId>org.bytedeco.javacpp-presets</groupId> <artifactId>ffmpeg-platform</artifactId> <version>4.0.2-1.4.3</version> </dependency>
需要注意这两个包之间的版本有一个对应关系,如果版本不对应可能会出问题
解码过程
实现的一个简单功能是:
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; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。