更新版本

This commit is contained in:
xgc 2024-01-19 12:37:55 +08:00
parent 1e13507381
commit 37443ef64b
3 changed files with 75 additions and 2 deletions

View File

@ -16,7 +16,7 @@ rtsp、rtmp流地址转换成flv浏览器播放
<dependency> <dependency>
<groupId>io.github.javpower</groupId> <groupId>io.github.javpower</groupId>
<artifactId>rtsp-converter-flv-spring-boot-starter</artifactId> <artifactId>rtsp-converter-flv-spring-boot-starter</artifactId>
<version>1.5.9</version> <version>1.5.9.1</version>
</dependency> </dependency>
``` ```
### 第二步实现interface ### 第二步实现interface

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>io.github.javpower</groupId> <groupId>io.github.javpower</groupId>
<artifactId>rtsp-converter-flv-spring-boot-starter</artifactId> <artifactId>rtsp-converter-flv-spring-boot-starter</artifactId>
<version>1.5.9</version> <version>1.5.9.1</version>
<name>rtsp-converter-flv-spring-boot-starter</name> <name>rtsp-converter-flv-spring-boot-starter</name>
<description>a tool about easy rtsp-converter-flv</description> <description>a tool about easy rtsp-converter-flv</description>
<url>https://github.com/javpower/easy-flv</url> <url>https://github.com/javpower/easy-flv</url>

View File

@ -0,0 +1,73 @@
package com.gc.easy.flv.util;
import com.alibaba.fastjson.JSONObject;
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FrameGrabber;
import org.bytedeco.javacv.Java2DFrameConverter;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class FlvUtil {
private static BufferedImage getBufferedImageByFrame(String filePath) throws IOException {
FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault(filePath);
return getBufferedImageByFrame(grabber);
}
private static BufferedImage getBufferedImageByFrame(FFmpegFrameGrabber grabber)
throws FrameGrabber.Exception {
grabber.start();
Frame frame;
frame = grabber.grabImage();
Java2DFrameConverter converter = new Java2DFrameConverter();
BufferedImage buffer = converter.getBufferedImage(frame);
grabber.stop();
return buffer;
}
public static byte[] getFlvImg(String path) throws Exception {
return bufferedImageToByteArray(getBufferedImageByFrame(path));
}
/**
* 将BufferedImage转换为byte[]
*
* @param image
* @return
*/
public static byte[] bufferedImageToByteArray(BufferedImage image) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", os);
return os.toByteArray();
}
/**
* 上传文件
*
* @param data 文件数据
* @param url 上传地址
* @param fileName 文件名称
* @return
*/
public static JSONObject postFile(byte[] data, String url, String fileName) {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
ByteArrayResource contentsAsResource = new ByteArrayResource(data) {
@Override
public String getFilename() {
return fileName;
}
};
paramMap.add("file", contentsAsResource);
return restTemplate.postForObject(url, paramMap, JSONObject.class);
}
}