您好,登錄后才能下訂單哦!
本文實例為大家分享了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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。