|
|
@@ -2,10 +2,12 @@ package com.izouma.wenlvju.web;
|
|
|
|
|
|
import com.izouma.wenlvju.exception.BusinessException;
|
|
|
import com.izouma.wenlvju.service.storage.StorageService;
|
|
|
+import com.izouma.wenlvju.utils.VideoUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.util.TempFile;
|
|
|
import org.bytedeco.javacv.FFmpegFrameGrabber;
|
|
|
import org.bytedeco.javacv.Frame;
|
|
|
import org.bytedeco.javacv.Java2DFrameConverter;
|
|
|
@@ -18,10 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.net.URLConnection;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Base64;
|
|
|
@@ -48,8 +47,8 @@ public class FileUploadController {
|
|
|
} catch (Exception ignored) {
|
|
|
}
|
|
|
path = basePath + "/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
- + RandomStringUtils.randomAlphabetic(8)
|
|
|
- + "." + FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
+ + RandomStringUtils.randomAlphabetic(8)
|
|
|
+ + "." + FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
}
|
|
|
InputStream is;
|
|
|
try {
|
|
|
@@ -75,7 +74,7 @@ public class FileUploadController {
|
|
|
} catch (Exception ignored) {
|
|
|
}
|
|
|
path = "image/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
- + RandomStringUtils.randomAlphabetic(8) + ext;
|
|
|
+ + RandomStringUtils.randomAlphabetic(8) + ext;
|
|
|
}
|
|
|
InputStream is;
|
|
|
try {
|
|
|
@@ -105,6 +104,11 @@ public class FileUploadController {
|
|
|
throw new BusinessException(file.getContentType() + " 非视频文件");
|
|
|
}
|
|
|
|
|
|
+ File destDir = TempFile.createTempDirectory("import." + FilenameUtils.getExtension(file.getOriginalFilename()));
|
|
|
+ file.transferTo(destDir);
|
|
|
+ Long videoTime = VideoUtils.getVideoTime(destDir);
|
|
|
+ log.info("视频长度:" + videoTime);
|
|
|
+
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
@@ -115,6 +119,7 @@ public class FileUploadController {
|
|
|
baos.flush();
|
|
|
|
|
|
InputStream is1 = new ByteArrayInputStream(baos.toByteArray());
|
|
|
+
|
|
|
String videoUrl = storageService.uploadFromInputStream(is1, videoPath);
|
|
|
|
|
|
InputStream is2 = new ByteArrayInputStream(baos.toByteArray());
|