public AjaxResult videoUploadFile(MultipartFile file){ try { if(null == file || file.isEmpty()){ return AjaxResult.error("文件为空"); } String ossFilePrefix = StringUtils.genUUID(); String fileName = ossFilePrefix +"-"+ file.getOriginalFilename(); String fileurl = AliOssUtils.videoUploadFile(file,fileName); AjaxResult ajax = AjaxResult.success(); ajax.put("fileName", "after_"+fileName); ajax.put("url", fileurl); return ajax; } catch (Exception e) { return AjaxResult.error(e.getMessage()); } }
public static final String uploadVideo(String baseDir, MultipartFile file, String fileName) throws FileSizeLimitExceededException, IOException { File desc = getAbsoluteFile(baseDir, fileName); file.transferTo(desc); String pathFileName = getPathFileName(baseDir, fileName); return pathFileName; }
public static boolean toCompressFile(String convertFile,String targetFile){ try{ /**将视频压缩为 每秒15帧 平均码率600k 画面的宽与高 为1280*720*/ String cutCmd="ffmpeg -i " + convertFile + " -r 15 -b:v 600k -s 1280x720 "+ targetFile; log.info("cutCmd: " + cutCmd); runCmd(cutCmd); log.info("文件:"+convertFile+" 视屏压缩完成"); }catch(Exception e){ e.printStackTrace(); log.info("压缩文件出现异常:"+e.getMessage()); return false; } return true; }
private static String getFileUrl(String path) throws IOException { File file = new File(path); FileInputStream fileInputStream = new FileInputStream(file); MultipartFile multipartFile1 = new MockMultipartFile(file.getName(), file.getName(), ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream); uploadFile(multipartFile1, file.getName()); String url = getUrl(file.getName()); return url; }
修改application.yml檔案:
spring :
servlet:
mvc:
async:
# servlet:
max-file-size: 1024MB
max-request-size max-request-size 1024:##
以上是Springboot如何實現影片上傳及壓縮功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!