From fb4341f5557cd48319304478781e2f66cf8bf87d Mon Sep 17 00:00:00 2001 From: liqin <liqin@wisenergy.cn> Date: Fri, 2 Apr 2021 20:47:25 +0800 Subject: [PATCH] bug fixed --- pom.xml | 13 ++++ .../party/common/video/FrameGrabberKit.java | 59 +++++++++++++++++++ .../controller/ExhibitionBoardController.java | 1 + .../web/controller/FileUploadController.java | 2 +- .../controller/LearningContentController.java | 6 +- .../controller/VideoContentController.java | 1 + 6 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/main/java/cn/wisenergy/chnmuseum/party/common/video/FrameGrabberKit.java diff --git a/pom.xml b/pom.xml index 81e81ac..82728aa 100644 --- a/pom.xml +++ b/pom.xml @@ -264,6 +264,19 @@ <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> + + <!--javacv基础包,包å«javacvå’Œjavacpp,必须--> + <dependency> + <groupId>org.bytedeco</groupId> + <artifactId>javacv</artifactId> + <version>1.5.5</version> + </dependency> + <!-- ffmpeg,å¯é€‰ --> + <dependency> + <groupId>org.bytedeco</groupId> + <artifactId>ffmpeg-platform</artifactId> + <version>4.3.2-1.5.5</version> + </dependency> </dependencies> <build> diff --git a/src/main/java/cn/wisenergy/chnmuseum/party/common/video/FrameGrabberKit.java b/src/main/java/cn/wisenergy/chnmuseum/party/common/video/FrameGrabberKit.java new file mode 100644 index 0000000..98c28ff --- /dev/null +++ b/src/main/java/cn/wisenergy/chnmuseum/party/common/video/FrameGrabberKit.java @@ -0,0 +1,59 @@ +package cn.wisenergy.chnmuseum.party.common.video; + +import org.bytedeco.javacv.FFmpegFrameGrabber; +import org.bytedeco.javacv.Frame; +import org.bytedeco.javacv.Java2DFrameConverter; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +/** + * 截å–视频图片 + */ +public class FrameGrabberKit { + + /** + * 获å–指定视频的帧并ä¿å˜ä¸ºå›¾ç‰‡è‡³æŒ‡å®šç›®å½• + */ + public static InputStream fetchFrame(String videoUrl) throws Exception { + FFmpegFrameGrabber ff = new FFmpegFrameGrabber(videoUrl); + ff.start(); + int lenght = ff.getLengthInFrames(); + int i = 0; + int interceptionFrames = 30;//截å–ç¬¬å‡ å¸§ + //默认截å–第50帧,如果第50帧大于视频总帧数的8æˆç›´æŽ¥å–长度lenght * 0.3 + if (interceptionFrames >= lenght * 0.8) { + interceptionFrames = (int) (lenght * 0.3); + } + Frame f = null; + while (i < lenght) { + // 过滤 å‰ interceptionFrames 帧,é¿å…出现全黑的图片,ä¾è‡ªå·±æƒ…况而定 + f = ff.grabFrame(); + if ((i > interceptionFrames) && (f.image != null)) { + break; + } + i++; + } + + int imageWidth = f.imageWidth; + int imageHeight = f.imageHeight; + // 对截å–的帧进行ç‰æ¯”例缩放 +// int width = 800; +// int height = (int) (((double) width / owidth) * oheight); + Java2DFrameConverter converter = new Java2DFrameConverter(); + BufferedImage fecthedImage = converter.getBufferedImage(f); + BufferedImage bi = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR); + bi.getGraphics().drawImage(fecthedImage.getScaledInstance(imageWidth, imageHeight, Image.SCALE_SMOOTH), 0, 0, null); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ImageIO.write(bi, "png", baos); + InputStream inputStream = new ByteArrayInputStream(baos.toByteArray()); + //ff.flush(); + ff.stop(); + return inputStream; + } + +} diff --git a/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/ExhibitionBoardController.java b/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/ExhibitionBoardController.java index 9e3a189..4e0450a 100644 --- a/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/ExhibitionBoardController.java +++ b/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/ExhibitionBoardController.java @@ -207,6 +207,7 @@ public class ExhibitionBoardController extends BaseController { if (boardCopyrightOwnerIdList != null && !boardCopyrightOwnerIdList.isEmpty()) { lambdaQueryWrapper.in(ExhibitionBoard::getBoardCopyrightOwnerId, boardCopyrightOwnerIdList); } + lambdaQueryWrapper.orderByDesc(ExhibitionBoard::getCreateTime); List<ExhibitionBoard> exhibitionBoardList = exhibitionBoardService.list(); for (ExhibitionBoard exhibitionBoard : exhibitionBoardList) { if (exhibitionBoard.getBoardCopyrightOwnerId() != null) { diff --git a/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/FileUploadController.java b/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/FileUploadController.java index 0f686e7..e2845af 100644 --- a/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/FileUploadController.java +++ b/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/FileUploadController.java @@ -343,7 +343,7 @@ public class FileUploadController extends BaseController { @PostMapping(value = "/video/content/upload", headers = "content-type=multipart/form-data", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @RequiresPermissions("file:video:content:upload") @ApiOperation(value = "展æ¿è§†é¢‘ä¸Šä¼ ", notes = "展æ¿è§†é¢‘ä¸Šä¼ ") - public Map<String, Object> uploadContentVideo(@RequestPart("file") MultipartFile[] files) throws IOException { + public Map<String, Object> uploadContentVideo(@RequestPart("file") MultipartFile[] files) throws Exception { if (files == null || files.length == 0) { throw new InterfaceException(RESPONSE_CODE_ENUM.SERVER_ERROR.getResultCode(), "没有文件å¯ä¾›ä¸Šä¼ "); } diff --git a/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/LearningContentController.java b/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/LearningContentController.java index ee7291f..bf32731 100644 --- a/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/LearningContentController.java +++ b/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/LearningContentController.java @@ -107,12 +107,12 @@ public class LearningContentController extends BaseController { for (String exhibitionBoardId : exhibitionBoardIdList) { LearningContentBoard learningContentBoard = LearningContentBoard.builder().exhibitionBoardId(exhibitionBoardId).learningContentId(learningContentId).build(); QueryWrapper<LearningContentBoard> learningContentBoardQueryWrapper = new QueryWrapper<>(); - queryWrapper.select("max(sortorder) as sortorder"); + learningContentBoardQueryWrapper.select("max(sortorder) as sortorder"); LearningContentBoard one = this.learningContentBoardService.getOne(learningContentBoardQueryWrapper); if (one != null && one.getSortorder() != null) { - learningContentBoard.setSortorder(one.getSortorder() + 1); + learningContent.setSortorder(one.getSortorder() + 1); } else { - learningContentBoard.setSortorder(1); + learningContent.setSortorder(1); } this.learningContentBoardService.save(learningContentBoard); } diff --git a/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/VideoContentController.java b/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/VideoContentController.java index 7a33c8c..6aea21b 100644 --- a/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/VideoContentController.java +++ b/src/main/java/cn/wisenergy/chnmuseum/party/web/controller/VideoContentController.java @@ -175,6 +175,7 @@ public class VideoContentController extends BaseController { if (StringUtils.isNotBlank(videoContentCopyrightOwnerId)) { lambdaQueryWrapper.eq(VideoContent::getVideoContentCopyrightOwnerId, videoContentCopyrightOwnerId); } + lambdaQueryWrapper.orderByDesc(VideoContent::getCreateTime); List<VideoContent> videoContentList = videoContentService.list(lambdaQueryWrapper); return getResult(videoContentList); } -- 2.18.1