Selaa lähdekoodia

发送消息修改标题提示

8 vuotta sitten
vanhempi
commit
d617327c02

+ 0 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/consult/ConsultTeamDao.java

@ -85,7 +85,6 @@ public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam,
	/**
	 * 解约时结束家庭咨询
	 *
	 * @param patient
	 * @return
	 */

+ 61 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/CommonUtil.java

@ -276,6 +276,67 @@ public class CommonUtil {
        }
    }
    public static String getVideoTimeAndImg(String sourcePath,String targetPath) throws  Exception{
        File source = new File(sourcePath);
        Encoder encoder = new Encoder();
        MultimediaInfo m = encoder.getInfo(source);
        File target = new File(targetPath);//转图片
        VideoAttributes video = new VideoAttributes();
        video.setCodec("png");//转图片
        video.setSize(new VideoSize(600, 500));
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("image2");//转图片
        attrs.setOffset(3f);//设置偏移位置,即开始转码位置(3秒)
        attrs.setDuration(0.01f);//设置转码持续时间(1秒)
        attrs.setVideoAttributes(video);
        encoder.encode(source, target, attrs);
        return m.getDuration()+"";
    }
    public static void changeToMp4(String sourcePath, String targetPath) {
        File source = new File(sourcePath);
        File target = new File(targetPath);
        AudioAttributes audio = new AudioAttributes();
        //audio.setCodec("aac");
        audio.setCodec("libvorbis");
       // audio.setBitRate(new Integer(64000));
        //audio.setChannels(new Integer(1));
       // audio.setSamplingRate(new Integer(22050));
        VideoAttributes video = new VideoAttributes();
        //video.setCodec("libxvid");// 转MP4
        video.setCodec("libtheora");//
       // video.setBitRate(new Integer(240000));// 180kb/s比特率
       // video.setFrameRate(new Integer(28));// 1f/s帧频,1是目前测试比较清楚的,越大越模糊
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("ogg");// 转MP4
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);
        Encoder encoder = new Encoder();
        long beginTime = System.currentTimeMillis();
        try {
            // 获取时长
            MultimediaInfo m = encoder.getInfo(source);
            System.out.println(m.getDuration());
            System.out.println("获取时长花费时间是:" + (System.currentTimeMillis() - beginTime));
            beginTime = System.currentTimeMillis();
            encoder.encode(source, target, attrs);
            System.out.println("视频转码花费时间是:" + (System.currentTimeMillis() - beginTime));
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InputFormatException e) {
            e.printStackTrace();
        } catch (EncoderException e) {
            e.printStackTrace();
        }
    }
    public static void main(String args[]){
        changeToMp4("E://mp4/5.mov","e://mp4/7.ogg");
    }
    public static String  saveVoiceToDisk(InputStream inputStream,String newFileName) throws Exception {
        // 文件保存的临时路径

+ 63 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/common/FileUploadController.java

@ -192,7 +192,27 @@ public class FileUploadController extends BaseController {
                    if(mp3File!=null){
                        mp3File.delete();
                    }
                }else{
                }else if("4".equals(type)){
                    String tempPath  =  CommonUtil.saveVoiceToDisk(mf.getInputStream(),fileName);
                    String pngPath = tempPath.substring(0,tempPath.lastIndexOf("."))+".png";
                    File tempFile = new File(tempPath);
                    File pngFile = new File(pngPath);
                    String times = CommonUtil.getVideoTimeAndImg(tempPath,pngPath);
                    ObjectNode imgNode = fastDFSUtil.upload(new FileInputStream(pngPath),"png","");
                    String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
                    ObjectNode videoNode = fastDFSUtil.upload(new FileInputStream(tempPath),fileExt,"");
                    tempPaths.add(fastUrl + imgNode.get("groupName").toString().replaceAll("\"","")
                            + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"",""));
                    tempPaths.add(fastUrl + videoNode.get("groupName").toString().replaceAll("\"","")
                            + "/" + videoNode.get("remoteFileName").toString().replaceAll("\"",""));
                    tempPaths.add(times);
                    if(tempFile!=null){
                        tempFile.delete();
                    }
                    if(pngFile!=null){
                        pngFile.delete();
                    }
                } else{
                    String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
                    ObjectNode objectNode = fastDFSUtil.upload(mf.getInputStream() ,fileExt,"");
                    tempPaths.add(fastUrl + objectNode.get("groupName").toString().replaceAll("\"","")
@ -202,6 +222,7 @@ public class FileUploadController extends BaseController {
            String urls = String.join(",", tempPaths);
            JSONObject json = new JSONObject();
            json.put("status", 200);
            json.put("success",true);
            json.put("msg", "上传成功");
            // 图片标识对象的HTTP链接
            json.put("urls", urls);
@ -282,4 +303,45 @@ public class FileUploadController extends BaseController {
            return error(-1, "上传失败");
        }
    }
    /**
     * 语音上传
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "test", method = RequestMethod.POST)
    @ResponseBody
    public String test(HttpServletRequest request, HttpServletResponse response) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        List<String> tempPaths = new ArrayList<String>();
        String fastUrl = SystemConf.getInstance().getSystemProperties().getProperty("fastdfs_file_url");
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            MultipartFile mf = entity.getValue();
            String fileName = mf.getOriginalFilename();
            String tempPath  =  CommonUtil.saveVoiceToDisk(mf.getInputStream(),fileName);
            String pngPath = tempPath.substring(0,tempPath.lastIndexOf("."))+".png";
            File tempFile = new File(tempPath);
            File pngFile = new File(pngPath);
            String times = CommonUtil.getVideoTimeAndImg(tempPath,pngPath);
            ObjectNode imgNode = fastDFSUtil.upload(new FileInputStream(pngPath),"png","");
            String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
            ObjectNode videoNode = fastDFSUtil.upload(new FileInputStream(tempPath),fileExt,"");
            tempPaths.add(fastUrl + imgNode.get("groupName").toString().replaceAll("\"","")
                    + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"",""));
            tempPaths.add(fastUrl + videoNode.get("groupName").toString().replaceAll("\"","")
                    + "/" + videoNode.get("remoteFileName").toString().replaceAll("\"",""));
            tempPaths.add(times);
            if(tempFile!=null){
                tempFile.delete();
            }
            if(pngFile!=null){
                pngFile.delete();
            }
        }
        String urls = String.join(",", tempPaths);
        return urls;
    }
}