rstp截图优化

This commit is contained in:
guoshengxiong 2024-10-30 10:09:03 +08:00
parent 82797de267
commit 2d1e6b582e

View File

@ -1,5 +1,6 @@
package com.zhgd.xmgl.util; package com.zhgd.xmgl.util;
import liquibase.pro.packaged.O;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.bytedeco.javacv.FFmpegFrameGrabber; import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame; import org.bytedeco.javacv.Frame;
@ -35,7 +36,7 @@ public class RtspUtils {
/** /**
* 遍历500次确保实时图片显示正常图片 * 遍历500次确保实时图片显示正常图片
*/ */
private static int COUNT = 100; private static int COUNT = 500;
/** /**
* 解析视频地址并截图 * 解析视频地址并截图
@ -45,6 +46,7 @@ public class RtspUtils {
* @throws Exception * @throws Exception
*/ */
public static void getVideoImagePathByRSTP(String path, String picPath) throws Exception { public static void getVideoImagePathByRSTP(String path, String picPath) throws Exception {
boolean have = false;
//创建rstp流对象 //创建rstp流对象
FFmpegFrameGrabber grabber = createGrabber(path); FFmpegFrameGrabber grabber = createGrabber(path);
try { try {
@ -70,9 +72,13 @@ public class RtspUtils {
File file = new File(picPath); File file = new File(picPath);
//输出文件 //输出文件
ImageIO.write(bufferedImage, "jpg", file); ImageIO.write(bufferedImage, "jpg", file);
have = true;
break; break;
} }
} }
if (!have) {
throw new RuntimeException("rstp截取图像失败");
}
} finally { } finally {
grabber.stop(); grabber.stop();
grabber.close(); grabber.close();