suntianwu 3 年 前
コミット
afa61ca47c

+ 22 - 0
pom.xml

@@ -269,6 +269,28 @@
             <scope>system</scope>
             <systemPath>${project.basedir}/lib/AIMCFaceMonitor.jar</systemPath>
         </dependency>
+
+        <dependency>
+            <groupId>org.bytedeco</groupId>
+            <artifactId>javacv</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.bytedeco</groupId>
+            <artifactId>javacpp</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.bytedeco.javacpp-presets</groupId>
+            <artifactId>opencv-platform</artifactId>
+            <version>3.4.1-1.4.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.bytedeco.javacpp-presets</groupId>
+            <artifactId>ffmpeg-platform</artifactId>
+            <version>3.4.2-1.4.1</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 8 - 11
src/main/java/com/iden/bms/controller/PersonController.java

@@ -120,10 +120,13 @@ public class PersonController {
     })
     @CrossOrigin
     @PostMapping(value = "/uploadImage", headers="content-type=multipart/form-data",produces = "application/json;charset=UTF-8")
-    public Result<String> uploadImage( @ApiParam(value="图像",required=true) MultipartFile file,
-                                     @RequestHeader(name = "token") String token) {
+    public Result<String> uploadImage(
+                                    @RequestHeader(name = "token") String token,
+                                    @ApiParam(value="图像", required=true) MultipartFile file,
+                                    @RequestParam(value = "communityId", required = true) Long communityId
+                                     ) {
         try {
-            String image = personService.uploadImage(file);
+            String image = personService.uploadImage(file,communityId);
             return  Result.success("上传成功!",image);
         } catch (BDException e) {
             log.error("图像上传出现异常",e);
@@ -146,14 +149,8 @@ public class PersonController {
         try {
 
             UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
-            int flag = this.personService.createPerson(vo,loginUser);
-            if (flag == 1) {
-                return  Result.error("证件号码已存在!");
-            }  else if (flag == 0) {
-                return  Result.success("新增成功!");
-            } else {
-                return  Result.error("新增失败!");
-            }
+            this.personService.createPerson(vo,loginUser);
+            return  Result.success("新增成功!");
 
         }catch (BDException e) {
             log.error("新增人员-出现异常",e);

+ 6 - 11
src/main/java/com/iden/bms/controller/TraceController.java

@@ -87,17 +87,12 @@ public class TraceController {
     }
 
 
-
-
-
-
-
-//    @GetMapping("/cameraPlay/{id}")
-//    @ApiOperation(value = "摄像机播放")
-//    public Result<TraceVO> cameraPlay(HttpServletRequest request, @RequestHeader("token") String token, @PathVariable("id") Long id){
-//        TraceVO orderInfo = this.traceService.getTraceById(id);
-//        return  Result.success("查询成功!",orderInfo);
-//    }
+    @GetMapping("/cameraVideo`Play/{id}")
+    @ApiOperation(value = "摄像机视频播放")
+    public Result<TraceVO> cameraVideoPlay(HttpServletRequest request, @RequestHeader("token") String token, @PathVariable("id") Long id){
+        this.traceService.cameraVideoPlay(id);
+        return  Result.success("查询成功!");
+    }
 
 
 }

+ 1 - 1
src/main/java/com/iden/bms/controller/WarningPersonController.java

@@ -89,7 +89,7 @@ public class WarningPersonController {
                                                        @RequestParam(value = "endDate", required = false) String endDate){
         try {
             UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
-            List<TraceVO> datas = this.traceService.listTrace(uid,beginDate,endDate,loginUser);
+            List<TraceVO> datas = this.warningPersonService.listTrace(uid,beginDate,endDate,loginUser);
             return Result.success(datas);
         }catch (Exception e) {
             log.error("预警管理: 点击预警人员获取目标轨迹列表出现异常",e);

+ 9 - 17
src/main/java/com/iden/bms/face/FaceIdenService.java

@@ -80,7 +80,12 @@ public class FaceIdenService {
 
                 //初始化引擎,加载人员图像人脸特征库
                 String personImageDir = idenRoot + "data/final/person";
-                File[] imgPersonFiles = new File(personImageDir).listFiles();
+
+                List<File> imgPersonFileList = new ArrayList<>();
+                imgPersonFileList = FileUtil.getFiles(new File(personImageDir),imgPersonFileList);
+                File[] imgPersonFiles = new File[imgPersonFileList.size()];
+                imgPersonFiles = imgPersonFileList.toArray(imgPersonFiles);
+
                 FaceMonitor faceMonitorPerson = FaceIdenTool.initFaceMonitor(idenRoot,imgPersonFiles);
 
                 for(File cameraCodedir : cameraCodeDirs) {
@@ -107,8 +112,8 @@ public class FaceIdenService {
                                 if (faceModels[i] != null) {
                                     String featPtr = ByteUtil.byte2Hex(faceModels[i].getFeatValue());
                                     //没有人脸的、不是正面的、不符合标准的,连拍的图片
-                                    if(isBad(featPtr) || isContinuation(cameraCode,imgFileName,featPtr)) {
-                                        File discardDir = new File(imgFile.getParentFile().getAbsolutePath().replace("origin","discardDir"));
+                                    if(FaceIdenTool.isBad(featPtr) || isContinuation(cameraCode,imgFileName,featPtr)) {
+                                        File discardDir = new File(imgFile.getParentFile().getAbsolutePath().replace("origin","discard"));
                                         if(!discardDir.exists()){
                                             discardDir.mkdirs();
                                         }
@@ -229,19 +234,6 @@ public class FaceIdenService {
 
     }
 
-    private boolean isBad(String featPtr){
-        if (StringUtils.isEmpty(featPtr)) {
-            return true;
-        }
-        char[] chars = featPtr.toCharArray();
-
-        for (char c : chars){
-            if(!String.valueOf(c).equals("0")){
-                return false;
-            }
-        }
-        return true;
-    }
 
    //是否连拍
     private boolean isContinuation(String cameraCode,String imgFileName, String featPtr) {
@@ -276,7 +268,7 @@ public class FaceIdenService {
 
     }
     /**
-     *
+     * 把摄像头上传的图像解开为一帧帧图片,放到图像目录下,等待识别引擎处理
      * @throws Exception
      */
 

+ 15 - 0
src/main/java/com/iden/bms/face/FaceIdenTool.java

@@ -7,6 +7,7 @@ import com.face.monitor.model.Image;
 import com.face.monitor.model.RecogResult;
 import com.iden.common.util.ByteUtil;
 import com.iden.common.vo.FaceRetrieveResultVO;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
@@ -92,6 +93,20 @@ public class FaceIdenTool {
     }
 
 
+    public static boolean isBad(String featPtr){
+        if (StringUtils.isEmpty(featPtr)) {
+            return true;
+        }
+        char[] chars = featPtr.toCharArray();
+
+        for (char c : chars){
+            if(!String.valueOf(c).equals("0")){
+                return false;
+            }
+        }
+        return true;
+    }
+
     /**
      * faceModel在faceMonitor的人脸特征库中检索命中的index
      * @param faceMonitor

+ 56 - 9
src/main/java/com/iden/bms/service/PersonService.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.iden.bms.face.FaceIdenTool;
+import com.iden.common.entity.IdenCommunity;
 import com.iden.common.entity.IdenCrowd;
 import com.iden.common.entity.IdenPerson;
 
@@ -14,6 +15,7 @@ import com.iden.common.entity.IdenPersonCrowdRef;
 import com.iden.common.enums.PersonTypeEnum;
 import com.iden.common.enums.PopulationTypeEnum;
 import com.iden.common.exception.BDException;
+import com.iden.common.service.IdenCommunityService;
 import com.iden.common.service.IdenCrowdService;
 import com.iden.common.service.IdenPersonCrowdRefService;
 import com.iden.common.service.IdenPersonService;
@@ -51,6 +53,8 @@ public class PersonService {
     private IdenPersonCrowdRefService idenPersonCrowdRefService;
     @Resource
     private IdenCrowdService idenCrowdService;
+    @Resource
+    private IdenCommunityService idenCommunityService;
 
     @Value("${iden.root:#{null}}")
     private String idenRoot;
@@ -212,7 +216,15 @@ public class PersonService {
      * @param file
      * @return  访问URL
      */
-    public String uploadImage(MultipartFile file) throws BDException {
+    public String uploadImage(MultipartFile file,Long communityId) throws BDException {
+        if(communityId == null ){
+            throw new BDException("必须选择小区");
+        }
+        IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
+        if(idenCommunity == null ){
+            throw new BDException("小区不能为空");
+        }
+
         String image = null;
         try {
             if (file != null) {
@@ -225,8 +237,9 @@ public class PersonService {
                 if (!ImgUtil.isImg(fileName)) {
                     throw new BDException("图像文件必须是图片格式!");
                 }
+
                 String saveFileName = DateUtils.getCurrYyyyMMddHHmmssDate() + "_" + UUID.randomUUID().toString()  + fileName.substring(fileName.lastIndexOf("."), fileName.length());
-                String picFullFileName = idenRoot + "data/final/person/" + saveFileName;
+                String picFullFileName = idenRoot + "data/final/person/" + idenCommunity.getCode() + "/" + saveFileName;
                 FileOutputStream fos = new FileOutputStream(picFullFileName);
                 fos.write(file.getBytes());
                 image = fileUrl + "person/" + saveFileName;
@@ -247,8 +260,15 @@ public class PersonService {
      * @param vo
      */
     @Transactional(rollbackFor = Exception.class)
-    public int createPerson(PersonVO vo, UserLoginedConvertVO loginUser){
-
+    public void createPerson(PersonVO vo, UserLoginedConvertVO loginUser) throws BDException {
+        Long communityId = vo.getCommunityId();
+        if(communityId == null ){
+            throw new BDException("必须选择小区");
+        }
+        IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
+        if(idenCommunity == null ){
+            throw new BDException("小区不能为空");
+        }
         //保存人员
         IdenPerson idenPerson = new IdenPerson();
         BeanUtil.copyProperties(vo,idenPerson);
@@ -258,13 +278,22 @@ public class PersonService {
         String image = idenPerson.getImage();
         if(StringUtils.isNotEmpty(image)){
             String fileName = image.substring(image.lastIndexOf("/"));
-            File imgFile = new File(idenRoot + "data/final/person/" + fileName);
+            File imgFile = new File(idenRoot + "data/final/person/"+ idenCommunity.getCode() + "/"  + fileName);
             String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFile);
+            if (FaceIdenTool.isBad(featPtr)) {
+                File discardDir = new File(imgFile.getParentFile().getAbsolutePath().replace("final","discard"));
+                if(!discardDir.exists()){
+                    discardDir.mkdirs();
+                }
+                File discardImgFile = new File(discardDir, fileName);
+                imgFile.renameTo(discardImgFile);//移动到废弃目录
+                throw new BDException("图像识别失败,请上传正确人脸图像");
+            }
             idenPerson.setFeatPtr(featPtr);
         }
 
         this.idenPersonService.save(idenPerson);
-        return 0;
+
     }
 
     /**
@@ -272,7 +301,15 @@ public class PersonService {
      * @param vo
      */
     @Transactional(rollbackFor = Exception.class)
-    public void updatePerson(PersonVO vo){
+    public void updatePerson(PersonVO vo) throws BDException {
+        Long communityId = vo.getCommunityId();
+        if(communityId == null ){
+            throw new BDException("必须选择小区");
+        }
+        IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
+        if(idenCommunity == null ){
+            throw new BDException("小区不能为空");
+        }
         //保存人员
         IdenPerson idenPerson = new IdenPerson();
         String oldImage = idenPerson.getImage();
@@ -281,13 +318,23 @@ public class PersonService {
         if (StringUtils.isNotEmpty(newImage) && !newImage.equals(oldImage)){
             //识别
             String fileNameNew = newImage.substring(newImage.lastIndexOf("/"));
-            File imgFileNew = new File(idenRoot + "data/final/person/" + fileNameNew);
+            File imgFileNew = new File(idenRoot + "data/final/person/" + idenCommunity.getCode() + "/" + fileNameNew);
             String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFileNew);
+            if (FaceIdenTool.isBad(featPtr)){
+                File discardDir = new File(imgFileNew.getParentFile().getAbsolutePath().replace("final","discard"));
+                if(!discardDir.exists()){
+                    discardDir.mkdirs();
+                }
+                File discardImgFile = new File(discardDir, fileNameNew);
+                imgFileNew.renameTo(discardImgFile);//移动到废弃目录
+                throw new BDException("图像识别失败,请上传正确人脸图像");
+            }
+
             idenPerson.setFeatPtr(featPtr);
             // 删除老的文件
             if(StringUtils.isNotEmpty(oldImage)){
                 String fileNameOld = oldImage.substring(oldImage.lastIndexOf("/"));
-                File imgFileOld = new File(idenRoot + "data/final/person/" + fileNameOld);
+                File imgFileOld = new File(idenRoot + "data/final/person/" + idenCommunity.getCode() + "/" + fileNameOld);
                 if(imgFileOld.exists()){
                     imgFileOld.delete();
                 }

+ 5 - 24
src/main/java/com/iden/bms/service/TraceService.java

@@ -41,8 +41,7 @@ public class TraceService {
     @Resource
     private FaceImageService faceImageService;
 
-    @Resource
-    private IdenWarningPersonTraceService idenWarningPersonTraceService;
+
 
 
     @Value("${iden.root:#{null}}")
@@ -160,27 +159,9 @@ public class TraceService {
         return list.toArray(resuit);
     }
 
-    /**
-     *  上传图像查询轨迹列表
-     * 图像识别,使用特征码查询图像库,得到图库表中对应的数据列表
-     * @return
-     */
-    public List<TraceVO> listTrace(String uid, String beginDate, String endDate, UserLoginedConvertVO loginUser) {
-        List<TraceVO> vos = new ArrayList<>();
-        QueryWrapper<IdenWarningPersonTrace> queryWrapper = new QueryWrapper<>();
-        queryWrapper.lambda().eq(IdenWarningPersonTrace::getUid,uid)
-                .ge(StringUtils.isNotEmpty(beginDate),IdenWarningPersonTrace::getDataDate,beginDate)
-                .le(StringUtils.isNotEmpty(endDate),IdenWarningPersonTrace::getDataDate,endDate)
-                .orderByAsc(IdenWarningPersonTrace::getPhotographTime);
-        List<IdenWarningPersonTrace> idenWarningPersonTraceList = this.idenWarningPersonTraceService.list(queryWrapper);
-        if(CollUtil.isNotEmpty(idenWarningPersonTraceList)) {
-            idenWarningPersonTraceList.forEach(item->{
-                TraceVO vo = new TraceVO();
-                IdenWarningPersonTrace idenWarningPersonTrace = new IdenWarningPersonTrace();
-                BeanUtil.copyProperties(idenWarningPersonTrace,vo);
-                vos.add(vo);
-            });
-        }
-        return vos;
+
+    public void cameraVideoPlay(Long cameraId) {
+
     }
+
 }

+ 25 - 1
src/main/java/com/iden/bms/service/WarningPersonService.java

@@ -42,7 +42,8 @@ public class WarningPersonService {
     private IdenPersonCrowdRefService idenPersonCrowdRefService;
     @Resource
     private IdenCrowdService idenCrowdService;
-
+    @Resource
+    private IdenWarningPersonTraceService idenWarningPersonTraceService;
 
     /**
      * 根据小区查询预警人员列表分页
@@ -127,6 +128,29 @@ public class WarningPersonService {
         return results;
     }
 
+    /**
+     *  查询轨迹列表
+     * @return
+     */
+    public List<TraceVO> listTrace(String uid, String beginDate, String endDate, UserLoginedConvertVO loginUser) {
+        List<TraceVO> vos = new ArrayList<>();
+        QueryWrapper<IdenWarningPersonTrace> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(IdenWarningPersonTrace::getUid,uid)
+                .ge(StringUtils.isNotEmpty(beginDate),IdenWarningPersonTrace::getDataDate,beginDate)
+                .le(StringUtils.isNotEmpty(endDate),IdenWarningPersonTrace::getDataDate,endDate)
+                .orderByAsc(IdenWarningPersonTrace::getPhotographTime);
+        List<IdenWarningPersonTrace> idenWarningPersonTraceList = this.idenWarningPersonTraceService.list(queryWrapper);
+        if(CollUtil.isNotEmpty(idenWarningPersonTraceList)) {
+            idenWarningPersonTraceList.forEach(item->{
+                TraceVO vo = new TraceVO();
+                IdenWarningPersonTrace idenWarningPersonTrace = new IdenWarningPersonTrace();
+                BeanUtil.copyProperties(idenWarningPersonTrace,vo);
+                vos.add(vo);
+            });
+        }
+        return vos;
+    }
+
     @Transactional(rollbackFor = Exception.class)
     public boolean handleWarning(WarningPersonVO vo) throws BDException {
 

+ 17 - 5
src/main/java/com/iden/common/entity/IdenCameraVideo.java

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 
+import java.time.LocalDateTime;
+
 import com.baomidou.mybatisplus.annotation.TableField;
 
 import java.io.Serializable;
@@ -20,7 +22,7 @@ import lombok.experimental.Accessors;
  * 摄像机视频表(IdenCameraVideo)实体类
  *
  * @author makejava
- * @since 2021-12-24 16:38:30
+ * @since 2022-01-03 15:36:55
  */
 
 @Data
@@ -29,12 +31,17 @@ import lombok.experimental.Accessors;
 @TableName("iden_camera_video")
 @ApiModel(value = "摄像机视频表", description = "")
 public class IdenCameraVideo implements Serializable {
-    private static final long serialVersionUID = -96192050731661605L;
+    private static final long serialVersionUID = 914965308244813944L;
 
     @TableId(value = "ID", type = IdType.AUTO)
     private Long id;
 
 
+    @ApiModelProperty("视频名称")
+    @TableField("NAME")
+    private String name;
+
+
     @ApiModelProperty("摄像头ID")
     @TableField("CAMERA_ID")
     private Long cameraId;
@@ -45,9 +52,14 @@ public class IdenCameraVideo implements Serializable {
     private Long communityId;
 
 
-    @ApiModelProperty("视频")
-    @TableField("VIDEO")
-    private String video;
+    @ApiModelProperty("视频地址")
+    @TableField("VIDEO_URL")
+    private String videoUrl;
+
+
+    @ApiModelProperty("视频缩略图")
+    @TableField("PIC")
+    private String pic;
 
 
     @ApiModelProperty("拍摄时间")

+ 19 - 0
src/main/java/com/iden/common/util/FileUtil.java

@@ -31,6 +31,25 @@ public class FileUtil {
         return fileList.toArray(filesNew);
     }
 
+    /**
+     * 递归 获取目录下所有文件
+     * @return
+     */
+    public static List<File> getFiles (File dirFile,List<File> resultFiles){
+        File[] files = dirFile.listFiles();
+        if(files == null || files.length == 0){
+            return resultFiles;// 判断目录下是不是空的
+        }
+        for (File f : files) {
+            if(f.isDirectory()){// 判断是否文件夹
+                getFiles(f,resultFiles);// 调用自身,查找子目录
+            } else
+                resultFiles.add(f);
+        }
+        return resultFiles;
+    }
+
+
     public static void main(String[] args) {
         File[] files = new File[]{new File("3"),new File("2"),new File("4")};
         files =  sortByName(files);

+ 209 - 0
src/main/java/com/iden/common/util/VideoUtil.java

@@ -0,0 +1,209 @@
+package com.iden.common.util;
+
+import org.bytedeco.javacpp.opencv_core;
+import org.bytedeco.javacpp.opencv_videoio;
+import org.bytedeco.javacv.FFmpegFrameGrabber;
+import org.bytedeco.javacv.Frame;
+import org.bytedeco.javacv.Java2DFrameConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.util.*;
+import java.util.List;
+
+import static org.bytedeco.javacpp.opencv_imgcodecs.cvSaveImage;
+import static org.bytedeco.javacpp.opencv_videoio.*;
+
+
+/**
+ * 视频工具
+ *
+ * @author
+ */
+public class VideoUtil {
+
+    private static final int SECOND = 50;
+
+    private static final Logger logger = LoggerFactory.getLogger(VideoUtil.class);
+
+    /**
+     * 获取指定视频的帧并保存为图片至指定目录
+     *
+     * @param videoFile 源视频文件
+     * @param saveFile  截取帧的图片存放路径
+     * @throws Exception
+     */
+    public static List<File> fetchPic(File videoFile, String saveFile, int second) throws Exception {
+
+        java.util.List<File> files = new ArrayList<>();
+
+        FFmpegFrameGrabber ff = new FFmpegFrameGrabber(videoFile);
+        ff.start();
+        int lenght = ff.getLengthInAudioFrames();
+        System.out.println(ff.getFrameRate());
+
+        int i = 0;
+        Frame frame = null;
+
+        while (i < lenght) {
+            // 过滤前5帧,避免出现全黑的图片,依自己情况而定
+            frame = ff.grabImage();
+            if (i >= (int) (ff.getFrameRate() * second) && frame.image != null) {
+                System.out.print(i + ",");
+                if (frame != null && frame.image != null) {
+                    System.out.println(i);
+                    files.add(writeToFile(frame, saveFile, i));
+                }
+                second++;
+            }
+            i += second;
+        }
+        ff.stop();
+        return files;
+    }
+
+    private static List<Integer> getList(int count, int length) {
+        if (count > length) {
+            count = length;
+        }
+        System.out.println(length);
+        System.out.println(count);
+        int total = (int) (length / count);
+        List<Integer> list = new ArrayList<>();
+        for (int i = 0; i < count; i++) {
+            list.add(i * total);
+            System.out.println(i * total);
+        }
+        return list;
+    }
+
+    public static List<File> fetchPicByCount(File videoFile, String saveFile, int count) throws Exception {
+
+        java.util.List<File> files = new ArrayList<>();
+
+        FFmpegFrameGrabber ff = new FFmpegFrameGrabber(videoFile);
+        ff.start();
+
+        int frameLength = ff.getLengthInFrames();
+
+
+        System.out.println("length:" + frameLength);
+
+        List<Integer> list = getList(count, frameLength);
+
+        System.out.println("ff.getFrameRate() == " + ff.getFrameRate());
+
+        int i = 0;
+        Frame frame = null;
+
+        while (i < frameLength) {
+            frame = ff.grabImage();
+            if (list.contains(i)) {
+                if (frame != null && frame.image != null) {
+                    System.out.println(i);
+                    files.add(writeToFile(frame, saveFile, i));
+                }
+            }
+            i++;
+        }
+        ff.stop();
+        return files;
+    }
+
+
+    private static File writeToFile(Frame frame, String saveFile, int second) throws Exception {
+        String fileName = String.valueOf(System.currentTimeMillis()) + second;
+        File targetFile = new File(saveFile + File.separator + fileName + ".jpg");
+        String imgSuffix = "jpg";
+
+        Java2DFrameConverter converter = new Java2DFrameConverter();
+        BufferedImage srcBi = converter.getBufferedImage(frame);
+        int owidth = srcBi.getWidth();
+        int oheight = srcBi.getHeight();
+        // 对截取的帧进行等比例缩放
+        int width = 800;
+        int height = (int) (((double) width / owidth) * oheight);
+        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
+        bi.getGraphics().drawImage(srcBi.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null);
+        try {
+            ImageIO.write(bi, imgSuffix, targetFile);
+        } catch (Exception e) {
+            throw new Exception( "截帧失败");
+        }
+        return targetFile;
+    }
+
+
+    /**
+     * 获取视频时长,单位为秒
+     *
+     * @param file
+     * @return 时长(s)
+     */
+    public static Long getVideoTime(File file) {
+        Long times = 0L;
+        try {
+            FFmpegFrameGrabber ff = new FFmpegFrameGrabber(file);
+            ff.start();
+            times = ff.getLengthInTime() / (1000 * 1000);
+            ff.stop();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return times;
+    }
+
+    public static void getBySecond(String filePath, String directory) {
+        opencv_videoio.CvCapture capture = cvCaptureFromFile(filePath);
+        //帧率
+        double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
+        System.out.println("帧率:" + fps);
+        opencv_core.IplImage frame = null;
+        double pos1 = 0;
+
+        double rootCount = 0;
+        while (true) {
+
+            //读取关键帧
+            frame = cvQueryFrame(capture);
+
+            rootCount = fps;
+            while (rootCount > 0) {
+                //这一段的目的是跳过每一秒钟的帧数,也就是说fps是帧率(一秒钟有多少帧),在读取一帧后,跳过fps数量的帧就相当于跳过了1秒钟。
+                frame = cvQueryFrame(capture);
+                rootCount--;
+            }
+
+            //获取当前帧的位置
+            pos1 = cvGetCaptureProperty(capture, CV_CAP_PROP_POS_FRAMES);
+            System.out.println(pos1);
+
+            if (null == frame)
+                break;
+
+            cvSaveImage("E:/223/" + pos1 + ".jpg", frame);
+
+        }
+
+        cvReleaseCapture(capture);
+    }
+
+
+
+    public static void main(String[] args) {
+        try {
+            //getList(10,113);
+
+            File file = new File("E:/4bcd37e90a0d087c349bbd817b5b4798.mp4");
+            List<File> files = VideoUtil.fetchPicByCount(file, "E:/223", 100);
+            System.out.println(files.get(0).getName());
+            System.out.println(VideoUtil.getVideoTime(file));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 1 - 1
src/main/resources/application.properties

@@ -2,7 +2,7 @@
 spring.profiles.active=dev
 
 # 配置服务端口号
-    server.port=8890
+    server.port=13456
 
 ### spring配置
 # 配置服务名称