From 24d66c8d82b628a06e93dbb1abfea2049b3d45ab Mon Sep 17 00:00:00 2001 From: zhangnaisong <2434969829@qq.com> Date: 星期六, 05 八月 2023 08:28:11 +0800 Subject: [PATCH] 删除app巡检计划提交 --- ard-work/src/main/java/com/ruoyi/device/hiksdk/util/imageUtil/waterMarkUtil.java | 114 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 96 insertions(+), 18 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/imageUtil/waterMarkUtil.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/imageUtil/waterMarkUtil.java index 4b5e098..919cf10 100644 --- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/imageUtil/waterMarkUtil.java +++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/util/imageUtil/waterMarkUtil.java @@ -1,5 +1,19 @@ package com.ruoyi.device.hiksdk.util.imageUtil; +import org.bytedeco.ffmpeg.global.avutil; +import org.bytedeco.javacv.FFmpegFrameGrabber; +import org.bytedeco.javacv.FFmpegFrameRecorder; +import org.bytedeco.javacv.Frame; +import org.bytedeco.javacv.Java2DFrameUtils; +import org.bytedeco.opencv.opencv_core.IplImage; +import javax.imageio.ImageIO; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Random; +import java.awt.*; +import java.awt.image.BufferedImage; /** * @ClassName WaterMarkUtil * @Description: @@ -8,13 +22,6 @@ * @Version 1.0 */ -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; /** * 鍥剧墖姘村嵃宸ュ叿绫� @@ -22,13 +29,13 @@ public class waterMarkUtil { // 姘村嵃閫忔槑搴� - private static final float alpha = 0.8f; + private static final float alpha = 0.3f; // 姘村嵃妯悜浣嶇疆 - private static int positionWidth = 100; + private static int positionWidth = 500; // 姘村嵃绾靛悜浣嶇疆 - private static int positionHeight = 300; + private static int positionHeight = 500; // 姘村嵃鏂囧瓧瀛椾綋 - private static final Font font = new Font("瀹嬩綋", Font.BOLD, 30); + private static final Font font = new Font("寰蒋闆呴粦", Font.BOLD, 80); // 姘村嵃鏂囧瓧棰滆壊 private static final Color color = Color.blue; @@ -152,13 +159,84 @@ } } + public static void markVideo(String text, String srcImgPath, String targetPath) { + avutil.av_log_set_level(avutil.AV_LOG_ERROR); + File file = new File(srcImgPath); + //鎶撳彇瑙嗛璧勬簮 + FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(file); + // + Frame frame = null; + FFmpegFrameRecorder recorder = null; + // String fileName = null; + try { + frameGrabber.start(); + //Random random = new Random(); +// fileName = file.getAbsolutePath() + random.nextInt(100)+".mp4"; +// System.out.println("鏂囦欢鍚�-->>"+fileName); + frameGrabber.setFrameRate(25); // 璁剧疆姣忕澶勭悊10甯� + recorder = new FFmpegFrameRecorder(targetPath, frameGrabber.getImageWidth(), frameGrabber.getImageHeight(), frameGrabber.getAudioChannels()); + //recorder.setFormat("mp4"); + recorder.setSampleRate(frameGrabber.getSampleRate()); + recorder.setFrameRate( frameGrabber.getFrameRate()); + recorder.setTimestamp(frameGrabber.getTimestamp()); + recorder.setVideoBitrate(frameGrabber.getVideoBitrate()); + recorder.setVideoCodec(frameGrabber.getVideoCodec()); + recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P); + + recorder.start(); + int index = 0; + while (true) { + frame = frameGrabber.grabFrame(); + if (frame == null) { + System.out.println("瑙嗛澶勭悊瀹屾垚"); + break; + } + //鍒ゆ柇闊抽 + // System.out.println("闊抽==" + (frame.samples == null) + "瑙嗛==" + (frame.image == null)); + //鍒ゆ柇鍥剧墖甯� + if (frame.image != null) { + IplImage iplImage = Java2DFrameUtils.toIplImage(frame); + BufferedImage buffImg = Java2DFrameUtils.toBufferedImage(iplImage); + Graphics2D graphics = buffImg.createGraphics(); + graphics.setColor(color); + graphics.setFont(font); + // 璁剧疆閫忔槑搴� + float alpha = 0.5f; // 璁剧疆閫忔槑搴﹀�硷紝鑼冨洿涓� 0.0锛堝畬鍏ㄩ�忔槑锛夊埌 1.0锛堝畬鍏ㄤ笉閫忔槑锛� + AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); + graphics.setComposite(alphaComposite); + graphics.drawString(text, positionWidth, positionHeight); + graphics.dispose(); + Frame newFrame = Java2DFrameUtils.toFrame(buffImg); + recorder.record(newFrame); + } + //璁剧疆闊抽 +// if (frame.samples != null) { +// recorder.recordSamples(frame.sampleRate, frame.audioChannels, frame.samples); +// } + // System.out.println("甯у��=" + index); + index++; + } + + recorder.stop(); + recorder.release(); + frameGrabber.stop(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + public static void main(String[] args) { - String srcImgPath = "G:\\data\\pic\\7aad76110e7c478598da6b82d7446246.jpeg"; - String text = "synjones"; - // 缁欏浘鐗囨坊鍔犳按鍗版枃瀛� - //markImage(text, srcImgPath, "G:\\data\\pic\\寰俊鎴浘姘村嵃.png"); - // 缁欏浘鐗囨坊鍔犳按鍗版枃瀛�,姘村嵃鏂囧瓧鏃嬭浆-45 - markImage(text, srcImgPath, "G:\\data\\pic\\7aad76110e7c478598da6b82d7446246姘村嵃.png", 45); - System.out.println("缁欏浘鐗囨坊鍔犳按鍗版枃瀛楀畬姣�"); +// String srcImgPath = "G:\\data\\pic\\7aad76110e7c478598da6b82d7446246.jpeg"; +// String text = "synjones"; +// // 缁欏浘鐗囨坊鍔犳按鍗版枃瀛� +// //markImage(text, srcImgPath, "G:\\data\\pic\\寰俊鎴浘姘村嵃.png"); +// // 缁欏浘鐗囨坊鍔犳按鍗版枃瀛�,姘村嵃鏂囧瓧鏃嬭浆-45 +// markImage(text, srcImgPath, "G:\\data\\pic\\7aad76110e7c478598da6b82d7446246姘村嵃.png", 45); +// System.out.println("缁欏浘鐗囨坊鍔犳按鍗版枃瀛楀畬姣�"); + + String videoPath="D:\\1.mp4"; + markVideo("瀹夌憺杈剧鎶�",videoPath,"D:\\2.mp4"); + System.out.println("缁欒棰戞坊鍔犳按鍗版枃瀛楀畬姣�"); } } -- Gitblit v1.9.3