From 1e6561acc89b7105c1dcbf5395845d6046f1453d Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期五, 21 二月 2025 16:55:09 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV --- pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/files/FileCtrl.java | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 55 insertions(+), 3 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/files/FileCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/files/FileCtrl.java index f8e6734..02626f9 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/files/FileCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/files/FileCtrl.java @@ -3,14 +3,16 @@ import com.dy.common.util.NumUtil; import com.dy.pipIrrWebFile.util.*; import lombok.extern.slf4j.Slf4j; +import org.jcodec.scale.AWTUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import java.io.File; -import java.io.InputStream; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.*; /** * web鏂囦欢涓婁紶, 鍐呴儴璋冪敤锛屽嵆鐢卞叾浠栧瓙妯″潡璋冪敤锛� @@ -24,6 +26,9 @@ @Value("${dy.photoZipWidth}") private String photoZipWidthStr ; + + private static final String VideoZipPicFileType = "jpg"; + private static final Integer VideoZipPicFromFrame = 5 ; /** * web鍒嗗竷寮忔枃浠剁郴缁熶繚瀛樼収鐗囨枃浠� @@ -65,7 +70,7 @@ String zipFilePath1 = filePath.substring(0, index) ; String zipFilePath2 = filePath.substring(index) ; String zipFilePath = zipFilePath1 + "_" + zipFilePath2 ; - InputStream zipFileInput = null ; + InputStream zipFileInput ; if(zipFilePath2.equalsIgnoreCase(".png")){ zipFileInput = ZipImg.zipToPng(fPic, photoZipWidth, photoZipWidth) ; }else{ @@ -152,6 +157,26 @@ String filePath = absolutePath + fileRelativePath ; if(!fUtil.saveFile(filePath, input)){ fileRelativePath = null ; + }else { + //瀛樺偍鎴愬姛, 鐢熸垚缂╃暐鍥� + BufferedImage bufImg = new VideoUtils(VideoZipPicFileType, VideoZipPicFromFrame).fetchFrame(file) ; + // 鍚戝彸鏃嬭浆90搴� + // bufImg = AWTUtil.rotate90ToRight(bufImg) ; + String zipFilePath = filePath.substring(0, filePath.lastIndexOf(".")) + "_." + VideoZipPicFileType ; + Integer photoZipWidth = 400 ; + if(photoZipWidthStr != null && NumUtil.isPlusIntNumber(photoZipWidthStr)){ + photoZipWidth = Integer.parseInt(photoZipWidthStr) ; + } + InputStream zipFileInput = ZipImg.zipToJpg(bufImg, photoZipWidth, photoZipWidth) ; + if(zipFileInput.available() > 0){ + new FileUtil().saveFile(zipFilePath, zipFileInput) ; + }else{ + //濡傛灉鍘嬬缉鏂囦欢涓嶅瓨鍦ㄦ垨鐢熸垚澶辫触锛屽垯澶嶅埗婧愭枃浠� + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageIO.write(bufImg, VideoZipPicFileType, os); + InputStream in = new ByteArrayInputStream(os.toByteArray()); + new FileUtil().saveFile(zipFilePath, in) ; + } } } } @@ -199,4 +224,31 @@ return fileRelativePath ; } + + public static void main(String[] args) throws Exception{ + String photoZipWidthStr = "400" ; + String VideoZipPicFileType = "jpg"; + //瀛樺偍鎴愬姛, 鐢熸垚缂╃暐鍥� + String filePath = "D:\\mp4\\test.mp4" ; + BufferedImage bufImg = new VideoUtils("jpg", 0).fetchFrame(filePath) ; + int index = filePath.lastIndexOf(".") ; + String basePath = filePath.substring(0, index) ; + Integer photoZipWidth = 400 ; + if(photoZipWidthStr != null && NumUtil.isPlusIntNumber(photoZipWidthStr)){ + photoZipWidth = Integer.parseInt(photoZipWidthStr) ; + } + String zipFilePath = basePath + "_." + VideoZipPicFileType ; + InputStream zipFileInput = null ; + zipFileInput = ZipImg.zipToJpg(bufImg, photoZipWidth, photoZipWidth) ; + if(zipFileInput.available() > 0){ + new FileUtil().saveFile(zipFilePath, zipFileInput) ; + }else{ + //濡傛灉鍘嬬缉鏂囦欢涓嶅瓨鍦ㄦ垨鐢熸垚澶辫触锛屽垯澶嶅埗婧愭枃浠� + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageIO.write(bufImg, VideoZipPicFileType, os); + InputStream in = new ByteArrayInputStream(os.toByteArray()); + new FileUtil().saveFile(zipFilePath, in) ; + } + } + } -- Gitblit v1.8.0