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; }
servlet:
mvc:
async:
request-timeout: 2000000
modify application-prd.y ml-Datei:
servlet:
multipart:
maximale Dateigröße: 1024 MB
maximale Anforderungsgröße: 1024 MB
Das obige ist der detaillierte Inhalt vonWie Springboot Video-Upload- und Komprimierungsfunktionen implementiert. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!