|
|
@@ -32,6 +32,8 @@ import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
@@ -47,6 +49,8 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
@Autowired
|
|
|
ImageService imageService;
|
|
|
|
|
|
+ private static final String BASE_DIR = System.getProperty("java.io.tmpdir") + "/ffmpeg";
|
|
|
+
|
|
|
public static OkHttpClient client = new OkHttpClient().newBuilder()
|
|
|
.connectTimeout(15, TimeUnit.SECONDS)
|
|
|
.readTimeout(5, TimeUnit.MINUTES)
|
|
|
@@ -54,39 +58,27 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
.retryOnConnectionFailure(true)
|
|
|
.build();
|
|
|
|
|
|
- private void downloadFile(String url, String filePath) throws Exception {
|
|
|
- for (int i = 0; i < 3; i++) {
|
|
|
- try {
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(url)
|
|
|
- .build();
|
|
|
-
|
|
|
- Call call = client.newCall(request);
|
|
|
- Response response = call.execute();
|
|
|
- InputStream is = response.body().byteStream();
|
|
|
-
|
|
|
- Path path = Paths.get(filePath);
|
|
|
- Path parentDir = path.getParent();
|
|
|
- if (!Files.exists(parentDir)) {
|
|
|
- Files.createDirectories(parentDir);
|
|
|
- }
|
|
|
- File file = new File(filePath);
|
|
|
- FileOutputStream outputStream = new FileOutputStream(file);
|
|
|
- byte[] buffer = new byte[4096];
|
|
|
- int bytesRead;
|
|
|
- while ((bytesRead = is.read(buffer)) != -1) {
|
|
|
- outputStream.write(buffer, 0, bytesRead);
|
|
|
- }
|
|
|
- is.close();
|
|
|
- break;
|
|
|
- } catch (Exception e) {
|
|
|
- if (i == 2) {
|
|
|
- throw e;
|
|
|
- } else {
|
|
|
- log.error("downloadFile error,{}", url, e);
|
|
|
- }
|
|
|
+ private void downloadFile(String fileUrl, String filePath) throws Exception {
|
|
|
+ URL url = new URL(fileUrl);
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
+ connection.setConnectTimeout(100000);
|
|
|
+ connection.setReadTimeout(100000);
|
|
|
+
|
|
|
+ // 确保目录存在
|
|
|
+ Files.createDirectories(Paths.get(filePath).getParent());
|
|
|
+
|
|
|
+ try (InputStream in = connection.getInputStream();
|
|
|
+ FileOutputStream out = new FileOutputStream(filePath)) {
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = in.read(buffer)) != -1) {
|
|
|
+ out.write(buffer, 0, bytesRead);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ connection.disconnect();
|
|
|
+ System.out.println("文件已下载到: " + filePath);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -96,13 +88,13 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
if (param.getMainVideo().contains(".mov")) {
|
|
|
mainVideoSuffix = ".mov";
|
|
|
}
|
|
|
- String mainVideoFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + mainVideoSuffix;
|
|
|
- String bgMediaFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String mainVideoFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + mainVideoSuffix;
|
|
|
+ String bgMediaFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
if ("image".equals(param.getType())) {
|
|
|
- bgMediaFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
+ bgMediaFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
}
|
|
|
String adjustBgMediaFilePath = bgMediaFilePath;
|
|
|
- String outputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String outputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
String ossKey = "ffmpeg/mergeBgVideo/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
|
|
|
allLocalFilePathList.add(mainVideoFilePath);
|
|
|
@@ -148,7 +140,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
if (bgImage.getWidth() == width && bgImage.getHeight() == height) {
|
|
|
return bgMediaFilePath;
|
|
|
}
|
|
|
- String resizeImageFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
+ String resizeImageFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
allLocalFilePathList.add(resizeImageFilePath);
|
|
|
BigDecimal widthRate = new BigDecimal(width).divide(new BigDecimal(bgImage.getWidth()), 2,
|
|
|
RoundingMode.UP);
|
|
|
@@ -172,7 +164,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
return resizeImageFilePath;
|
|
|
} else {
|
|
|
FFmpegUtil.MediaInfo bgVideoMediaInfo = FFmpegUtil.getMediaInfo(bgMediaFilePath);
|
|
|
- String resizeBgVideoFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String resizeBgVideoFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
allLocalFilePathList.add(resizeBgVideoFilePath);
|
|
|
if (bgVideoMediaInfo.getWidth() == width && bgVideoMediaInfo.getHeight() == height) {
|
|
|
resizeBgVideoFilePath = bgMediaFilePath;
|
|
|
@@ -203,13 +195,13 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
if (mod > 0) {
|
|
|
loop = loop + 1;
|
|
|
}
|
|
|
- String loopBgVideoFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String loopBgVideoFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
allLocalFilePathList.add(loopBgVideoFilePath);
|
|
|
FFmpegUtil.loopVideo(resizeBgVideoFilePath, loop, loopBgVideoFilePath);
|
|
|
FFmpegUtil.MediaInfo loopMediaInfo = FFmpegUtil.getMediaInfo(loopBgVideoFilePath);
|
|
|
if (loopMediaInfo.getDuration() > duration) {
|
|
|
// 截断
|
|
|
- String cutBgVideoFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String cutBgVideoFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
allLocalFilePathList.add(cutBgVideoFilePath);
|
|
|
String startTime = "00:00:00.000";
|
|
|
String cutTime = covertFFmpegCutTime(duration);
|
|
|
@@ -220,7 +212,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
}
|
|
|
} else if (bgVideoMediaInfo.getDuration() > duration) {
|
|
|
// 截断
|
|
|
- String cutBgVideoFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String cutBgVideoFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
allLocalFilePathList.add(cutBgVideoFilePath);
|
|
|
String startTime = "00:00:00.000";
|
|
|
String cutTime = covertFFmpegCutTime(duration);
|
|
|
@@ -259,13 +251,13 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
|
|
|
@Override
|
|
|
public String removeBg(RemoveBgParam param) {
|
|
|
- String inputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
- String outputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mov";
|
|
|
+ String inputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String outputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mov";
|
|
|
String ossKey = "ffmpeg/removeBg/" + BaseUtils.getUUIDStr() + ".mov";
|
|
|
String contentType = "video/mov";
|
|
|
if ("image".endsWith(param.getMediaType())) {
|
|
|
- inputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
- outputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
+ inputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
+ outputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
ossKey = "ffmpeg/removeBg/" + BaseUtils.getUUIDStr() + ".png";
|
|
|
contentType = "image/png";
|
|
|
}
|
|
|
@@ -318,9 +310,9 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
|
|
|
@Override
|
|
|
public String videoAddAssSubtitle(VideoAddAssSubtitleParam param) {
|
|
|
- String inputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
- String outputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
- String assSubtitleFilePath = "./datalog/videoComposite/subtitle/" + BaseUtils.getUUIDStr() + ".ass";
|
|
|
+ String inputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String outputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String assSubtitleFilePath = BASE_DIR + "/videoComposite/subtitle/" + BaseUtils.getUUIDStr() + ".ass";
|
|
|
String ossKey = "ffmpeg/videoAddAssSubtitle/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
try {
|
|
|
downloadFile(CdnUtil.getOssHttpUrl(param.getVideoUrl()), inputFilePath);
|
|
|
@@ -361,7 +353,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
String outputPath = null;
|
|
|
try {
|
|
|
outputPath = FFmpegUtil.getVideoVoice(videoUrl,
|
|
|
- FFmpegUtil.pathCreate("./datalog/videoExtractAudio/voice/" + BaseUtils.getUUIDStr() + ".mp3"));
|
|
|
+ FFmpegUtil.pathCreate(BASE_DIR + "/videoExtractAudio/voice/" + BaseUtils.getUUIDStr() + ".mp3"));
|
|
|
|
|
|
if (StringUtils.hasText(outputPath)) {
|
|
|
String ossKey = "video/voice/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
@@ -396,12 +388,12 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
String url = param.getAudioUrl();
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
try {
|
|
|
- String inputFilePath = FFmpegUtil.pathCreate("./datalog/audioVolume/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ String inputFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/audioVolume/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
downloadFile(url, inputFilePath);
|
|
|
allLocalFilePathList.add(inputFilePath);
|
|
|
|
|
|
// 音频降噪
|
|
|
- String outputFilePath = FFmpegUtil.pathCreate("./datalog/audioVolume/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ String outputFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/audioVolume/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
allLocalFilePathList.add(outputFilePath);
|
|
|
|
|
|
String afParam = String.format("afftdn=nf=-20,volume=%s", volume);
|
|
|
@@ -434,11 +426,11 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
|
|
|
try {
|
|
|
- String inputFile = FFmpegUtil.pathCreate("./datalog/audioSplit/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ String inputFile = FFmpegUtil.pathCreate(BASE_DIR + "/audioSplit/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
downloadFile(param.getAudioUrl(), inputFile);
|
|
|
allLocalFilePathList.add(inputFile);
|
|
|
|
|
|
- String outputPath = "./datalog/audioSplit/split/" + BaseUtils.getUUIDStr();
|
|
|
+ String outputPath = BASE_DIR + "/audioSplit/split/" + BaseUtils.getUUIDStr();
|
|
|
String outputFilePath = FFmpegUtil.pathCreate(outputPath + "/" + BaseUtils.getUUIDStr() + "_%03d.mp3");
|
|
|
FFmpegUtil.audioSplit(inputFile, param.getSegmentTime(), outputFilePath);
|
|
|
|
|
|
@@ -502,7 +494,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
String imageLocalPath = null;
|
|
|
try {
|
|
|
imageLocalPath = FFmpegUtil.getTimeImage(param.getVideoUrl(), param.getTime(),
|
|
|
- FFmpegUtil.pathCreate("./datalog/videoExtractKeyframe/image/" + BaseUtils.getUUIDStr() + ".jpg"), 0);
|
|
|
+ FFmpegUtil.pathCreate(BASE_DIR + "/videoExtractKeyframe/image/" + BaseUtils.getUUIDStr() + ".jpg"), 0);
|
|
|
if (StringUtils.hasText(imageLocalPath)) {
|
|
|
String ossKey = "video/timeFrame/" + BaseUtils.getUUIDStr() + ".jpg";
|
|
|
AliOssFileTool.saveInPublic(EnumPublicBuckets.PUBBUCKET.getBucketName(), ossKey,
|
|
|
@@ -531,7 +523,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
|
|
|
String outputPath = "";
|
|
|
try {
|
|
|
- outputPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ outputPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
FFmpegUtil.cutVideoTime(param.getVideoUrl(), param.getStartTime(), param.getEndTime(), outputPath);
|
|
|
String ossKey = "video/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
AliOssFileTool.saveInPublic(EnumPublicBuckets.PUBBUCKET.getBucketName(), ossKey,
|
|
|
@@ -560,10 +552,10 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
String outputPath = null;
|
|
|
String inputVideoPath = null;
|
|
|
try {
|
|
|
- inputVideoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ inputVideoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
FileUtils.saveFileContent(inputVideoPath, imageService.imageDownloadV2(param.getVideoUrl()));
|
|
|
outputPath = FFmpegUtil.getVideoVoice(inputVideoPath, param.getStartTime(), param.getEndTime(),
|
|
|
- FFmpegUtil.pathCreate("./datalog/videoExtractAudio/voice/" + BaseUtils.getUUIDStr() + ".mp3"));
|
|
|
+ FFmpegUtil.pathCreate(BASE_DIR + "/videoExtractAudio/voice/" + BaseUtils.getUUIDStr() + ".mp3"));
|
|
|
if (StringUtils.hasText(outputPath)) {
|
|
|
String ossKey = "video/voice/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
AliOssFileTool.saveInPublic(EnumPublicBuckets.PUBBUCKET.getBucketName(), ossKey, Files.newInputStream(Paths.get(outputPath)), "audio/mp3");
|
|
|
@@ -595,11 +587,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
|
|
|
try {
|
|
|
- String inputFile = FFmpegUtil.pathCreate("./datalog/ffmpeg/command/input/" + getFileNameByUrl(param.getInputFile()));
|
|
|
- allLocalFilePathList.add(inputFile);
|
|
|
- downloadFile(CdnUtil.getOssHttpUrl(param.getInputFile()), inputFile);
|
|
|
- ffmpegCommand = ffmpegCommand.replace(param.getInputFile(), inputFile);
|
|
|
- String outputFile = FFmpegUtil.pathCreate("./datalog/ffmpeg/command/result/" + param.getOutputFile());
|
|
|
+ String outputFile = FFmpegUtil.pathCreate(BASE_DIR + "/ffmpeg/command/result/" + param.getOutputFile());
|
|
|
allLocalFilePathList.add(outputFile);
|
|
|
ffmpegCommand = ffmpegCommand.replace(param.getOutputFile(), outputFile);
|
|
|
ffmpegCommand = ffmpegCommand.replace("\n", " ").replace("\\", "").trim();
|
|
|
@@ -708,7 +696,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
long beginTime = System.currentTimeMillis();
|
|
|
try {
|
|
|
- String videoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String videoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
FileUtils.saveFileContent(videoPath, imageService.imageDownloadV2(param.getVideoUrl()));
|
|
|
allLocalFilePathList.add(videoPath);
|
|
|
long time1 = System.currentTimeMillis();
|
|
|
@@ -718,7 +706,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
long time2 = System.currentTimeMillis();
|
|
|
log.info("videoTexture,time2:{},{}", (time2 - time1), param.getVideoUrl());
|
|
|
|
|
|
- String imagePath = FFmpegUtil.pathCreate("./datalog/videoComposite/image/" + BaseUtils.getUUIDStr() + ".png");
|
|
|
+ String imagePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/image/" + BaseUtils.getUUIDStr() + ".png");
|
|
|
FileUtils.saveFileContent(imagePath, imageService.imageDownloadV2(param.getImageUrl()));
|
|
|
allLocalFilePathList.add(imagePath);
|
|
|
long time3 = System.currentTimeMillis();
|
|
|
@@ -747,7 +735,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
log.info("videoTexture,time4:{},{}", (time4 - time3), param.getVideoUrl());
|
|
|
}
|
|
|
|
|
|
- String outputPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String outputPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(outputPath);
|
|
|
|
|
|
// 贴图操作
|
|
|
@@ -792,14 +780,14 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
}
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
|
|
|
- String videoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String videoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
FileUtils.saveFileContent(videoPath, imageService.imageDownloadV2(videoUrl));
|
|
|
allLocalFilePathList.add(videoPath);
|
|
|
- String audioPath = FFmpegUtil.pathCreate("./datalog/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ String audioPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
FileUtils.saveFileContent(audioPath, imageService.imageDownloadV2(audioUrl));
|
|
|
allLocalFilePathList.add(audioPath);
|
|
|
|
|
|
- String outputPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String outputPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(outputPath);
|
|
|
FFmpegUtil.addAudioSelfAdaption(videoPath, audioPath, outputPath);
|
|
|
String ossKey = "videoComposite/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
@@ -816,15 +804,15 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
StringBuilder concatContent = new StringBuilder();
|
|
|
for (String audioUrl : audioUrls) {
|
|
|
- String audioPath = FFmpegUtil.pathCreate("./datalog/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ String audioPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
FileUtils.saveFileContent(audioPath, imageService.imageDownloadV2(audioUrl));
|
|
|
allLocalFilePathList.add(audioPath);
|
|
|
concatContent.append("file '").append(audioPath).append("'").append("\n");
|
|
|
}
|
|
|
- String concatFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/ace/" + BaseUtils.getUUIDStr() + ".txt");
|
|
|
+ String concatFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/ace/" + BaseUtils.getUUIDStr() + ".txt");
|
|
|
FileUtils.saveFileContent(concatFilePath, concatContent.toString().trim().getBytes());
|
|
|
allLocalFilePathList.add(concatFilePath);
|
|
|
- String concatOutputFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/ace/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ String concatOutputFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/ace/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
FFmpegUtil.concatAudios(concatFilePath, concatOutputFilePath);
|
|
|
allLocalFilePathList.add(concatOutputFilePath);
|
|
|
String ossKey = "composeAceAudio/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
@@ -842,15 +830,15 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
// 视频片段拼接
|
|
|
StringBuilder concatContent = new StringBuilder();
|
|
|
for (String videoUrl : videoUrls) {
|
|
|
- String videoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String videoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
FileUtils.saveFileContent(videoPath, imageService.imageDownloadV2(videoUrl));
|
|
|
concatContent.append("file '").append(videoPath).append("'").append("\n");
|
|
|
allLocalFilePathList.add(videoPath);
|
|
|
}
|
|
|
- String concatFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".txt");
|
|
|
+ String concatFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".txt");
|
|
|
FileUtils.saveFileContent(concatFilePath, concatContent.toString().trim().getBytes());
|
|
|
allLocalFilePathList.add(concatFilePath);
|
|
|
- String concatVideoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String concatVideoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
FFmpegUtil.concatVideos(concatFilePath, concatVideoPath);
|
|
|
allLocalFilePathList.add(concatVideoPath);
|
|
|
String ossKey = "videoComposite/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
@@ -868,11 +856,11 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
try {
|
|
|
String concatFileContent = buildConcatFileContentV2(param.getVideoUrls(), allLocalFilePathList, param.getPretreatmentSwitch());
|
|
|
- String concatFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".txt");
|
|
|
+ String concatFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".txt");
|
|
|
FileUtils.saveFileContent(concatFilePath, concatFileContent.getBytes());
|
|
|
allLocalFilePathList.add(concatFilePath);
|
|
|
|
|
|
- String outputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String outputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
allLocalFilePathList.add(outputFilePath);
|
|
|
|
|
|
FFmpegUtil.concatVideos(concatFilePath, outputFilePath);
|
|
|
@@ -907,7 +895,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
int finalHeight = 1280;
|
|
|
for (int i = 0; i < clipVideoUrls.size(); i++) {
|
|
|
String clipVideoUrl = clipVideoUrls.get(i);
|
|
|
- String clipVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String clipVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
downloadFile(clipVideoUrl, clipVideoFilePath);
|
|
|
allLocalFilePathList.add(clipVideoFilePath);
|
|
|
FFmpegUtil.MediaInfo mediaInfo = FFmpegUtil.getMediaInfo(clipVideoFilePath);
|
|
|
@@ -959,7 +947,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
"scale=" + targetWidth + ":" + finalHeight + ",crop=" + finalWidth + ":" + finalHeight + ":" + cropX +
|
|
|
":" + cropY;
|
|
|
}
|
|
|
- String scaleClipVideoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String scaleClipVideoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
// System.out.println("clipVideoUrl:" + clipVideoUrl);
|
|
|
FFmpegUtil.clipVideo(clipVideoFilePath, clipParams, scaleClipVideoPath);
|
|
|
allLocalFilePathList.add(scaleClipVideoPath);
|
|
|
@@ -970,7 +958,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
// 处理视频时间戳,避免拼接后时长不对问题
|
|
|
StringBuilder concatContent = new StringBuilder();
|
|
|
for (String scaleVideoFilePath : scaleVideoFilePathList) {
|
|
|
- String timeScaleVideoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String timeScaleVideoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
FFmpegUtil.fixVideoTime(scaleVideoFilePath, timeScaleVideoPath);
|
|
|
allLocalFilePathList.add(timeScaleVideoPath);
|
|
|
concatContent.append("file '" + timeScaleVideoPath + "'").append("\n");
|
|
|
@@ -987,11 +975,11 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
Integer finalTimeBase = null;
|
|
|
for (int i = 0; i < clipVideoUrls.size(); i++) {
|
|
|
String clipVideoUrl = clipVideoUrls.get(i);
|
|
|
- String clipVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String clipVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
downloadFile(clipVideoUrl, clipVideoFilePath);
|
|
|
allLocalFilePathList.add(clipVideoFilePath);
|
|
|
- FFmpegUtil.MediaInfo mediaInfo = FFmpegUtil.getMediaInfo(clipVideoFilePath);
|
|
|
if (i == 0) {
|
|
|
+ FFmpegUtil.MediaInfo mediaInfo = FFmpegUtil.getMediaInfo(clipVideoUrl);
|
|
|
finalWidth = mediaInfo.getWidth();
|
|
|
finalHeight = mediaInfo.getHeight();
|
|
|
finalAvgFrameRate = mediaInfo.getAvgFrameRate();
|
|
|
@@ -1000,7 +988,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
String clipParams = "scale={finalWidth}:{finalHeight}:force_original_aspect_ratio=decrease,pad={finalWidth}:{finalHeight}:(ow-iw)/2:(oh-ih)/2";
|
|
|
clipParams = clipParams.replace("{finalWidth}", finalWidth + "").replace("{finalHeight}", finalHeight + "");
|
|
|
|
|
|
- String scaleClipVideoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String scaleClipVideoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
|
|
|
// 如果开启预处理,且第一个视频的帧率和时间基都有值,则进行预处理
|
|
|
if (Objects.equals(pretreatmentSwitch, Constant.INTEGER_TRUE)
|
|
|
@@ -1028,7 +1016,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
long beginTime = System.currentTimeMillis();
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
try {
|
|
|
- String originVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String originVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
downloadFile(param.getOriginVideoUrl(), originVideoFilePath);
|
|
|
long time1 = System.currentTimeMillis();
|
|
|
log.info("videoAddTail,bizId:{},time1:{}", param.getBizId(), time1 - beginTime);
|
|
|
@@ -1036,7 +1024,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
String volumeOriginVideoFilePath = originVideoFilePath;
|
|
|
if (Objects.nonNull(param.getOriginVideoVolume())) {
|
|
|
long timea = System.currentTimeMillis();
|
|
|
- String lufsOriginVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String lufsOriginVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(lufsOriginVideoFilePath);
|
|
|
FFmpegUtil.changeVideoVolumeByLoudnorm(originVideoFilePath, "-16", lufsOriginVideoFilePath);
|
|
|
long time2 = System.currentTimeMillis();
|
|
|
@@ -1045,7 +1033,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
String volumeMultiple = new BigDecimal(param.getOriginVideoVolume()).divide(new BigDecimal("50"), 2,
|
|
|
RoundingMode.HALF_UP).toString();
|
|
|
if (new BigDecimal(volumeMultiple).subtract(new BigDecimal("1.00")).abs().compareTo(new BigDecimal("0.1")) > 0) {
|
|
|
- volumeOriginVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ volumeOriginVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(volumeOriginVideoFilePath);
|
|
|
FFmpegUtil.changeVideoVolume(lufsOriginVideoFilePath, volumeMultiple, volumeOriginVideoFilePath);
|
|
|
} else {
|
|
|
@@ -1063,19 +1051,19 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
int finalWidth = originVideoMediaInfo.getWidth();
|
|
|
int finalHeight = originVideoMediaInfo.getHeight();
|
|
|
|
|
|
- String tailVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String tailVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(tailVideoFilePath);
|
|
|
downloadFile(param.getTailVideoUrl(), tailVideoFilePath);
|
|
|
String volumeTailVideoFilePath = tailVideoFilePath;
|
|
|
if (Objects.nonNull(param.getTailVolume())) {
|
|
|
- String lufsTailVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String lufsTailVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(lufsTailVideoFilePath);
|
|
|
FFmpegUtil.changeVideoVolumeByLoudnorm(tailVideoFilePath, "-16", lufsTailVideoFilePath);
|
|
|
|
|
|
String volumeMultiple = new BigDecimal(param.getTailVolume()).divide(new BigDecimal("50"), 2,
|
|
|
RoundingMode.HALF_UP).toString();
|
|
|
if (new BigDecimal(volumeMultiple).subtract(new BigDecimal("1.00")).abs().compareTo(new BigDecimal("0.1")) > 0) {
|
|
|
- volumeTailVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ volumeTailVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(volumeTailVideoFilePath);
|
|
|
FFmpegUtil.changeVideoVolume(lufsTailVideoFilePath, volumeMultiple, volumeTailVideoFilePath);
|
|
|
} else {
|
|
|
@@ -1089,7 +1077,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
} else {
|
|
|
String clipParams = buildScaleClipParams(finalWidth, finalHeight, tailVideoMediaInfo.getWidth(),
|
|
|
tailVideoMediaInfo.getHeight());
|
|
|
- String scaleClipVideoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String scaleClipVideoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(scaleClipVideoPath);
|
|
|
FFmpegUtil.clipVideo(volumeTailVideoFilePath, clipParams, scaleClipVideoPath);
|
|
|
concatFilePathList.add(scaleClipVideoPath);
|
|
|
@@ -1099,7 +1087,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
} else if ("lastFrame".equals(param.getTailType())) {
|
|
|
long timea = System.currentTimeMillis();
|
|
|
// 最后一帧图片
|
|
|
- String lastFrameFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/image/" + BaseUtils.getUUIDStr() + ".png");
|
|
|
+ String lastFrameFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/image/" + BaseUtils.getUUIDStr() + ".png");
|
|
|
allLocalFilePathList.add(lastFrameFilePath);
|
|
|
int lastTime = 1;
|
|
|
int durationSecond = originVideoMediaInfo.getDuration() / 1000;
|
|
|
@@ -1123,7 +1111,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
|
|
|
// 确定片尾视频时长
|
|
|
Integer audioMillisDuration = 0;
|
|
|
- String tailAudioFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ String tailAudioFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
String volumeTailAudioFilePath = tailAudioFilePath;
|
|
|
FFmpegUtil.MediaInfo tailAudioMediaInfo = null;
|
|
|
if (StringUtils.hasText(param.getTailAudioUrl())) {
|
|
|
@@ -1131,14 +1119,14 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
downloadFile(param.getTailAudioUrl(), tailAudioFilePath);
|
|
|
|
|
|
if (Objects.nonNull(param.getTailVolume())) {
|
|
|
- String lufsTailAudioFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ String lufsTailAudioFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
allLocalFilePathList.add(lufsTailAudioFilePath);
|
|
|
FFmpegUtil.changeMediaVolumeByLoudnorm(tailAudioFilePath, "-16", lufsTailAudioFilePath);
|
|
|
|
|
|
String volumeMultiple = new BigDecimal(param.getTailVolume()).divide(new BigDecimal("50"), 2,
|
|
|
RoundingMode.HALF_UP).toString();
|
|
|
if (new BigDecimal(volumeMultiple).subtract(new BigDecimal("1.00")).abs().compareTo(new BigDecimal("0.1")) > 0) {
|
|
|
- volumeTailAudioFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
+ volumeTailAudioFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3");
|
|
|
allLocalFilePathList.add(volumeTailAudioFilePath);
|
|
|
FFmpegUtil.changeMediaVolume(lufsTailAudioFilePath, volumeMultiple, volumeTailAudioFilePath);
|
|
|
} else {
|
|
|
@@ -1163,7 +1151,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
String tailSecondDuration = new BigDecimal(tailMillisDuration).divide(new BigDecimal(1000), 3,
|
|
|
RoundingMode.HALF_UP).toString();
|
|
|
// 生成片尾视频
|
|
|
- String tailVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String tailVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(tailVideoFilePath);
|
|
|
FFmpegUtil.imageToVideo(lastFrameFilePath, originVideoMediaInfo.getWidth(),
|
|
|
originVideoMediaInfo.getHeight(), tailSecondDuration, tailVideoFilePath);
|
|
|
@@ -1173,7 +1161,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
// 片尾视频加音频
|
|
|
String lastTailVideoFilePath = tailVideoFilePath;
|
|
|
if (StringUtils.hasText(param.getTailAudioUrl())) {
|
|
|
- String addAudioFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String addAudioFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(addAudioFilePath);
|
|
|
FFmpegUtil.addAudio(tailVideoFilePath, volumeTailAudioFilePath, addAudioFilePath);
|
|
|
lastTailVideoFilePath = addAudioFilePath;
|
|
|
@@ -1183,11 +1171,11 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
|
|
|
// 片尾视频加字幕
|
|
|
if (StringUtils.hasText(param.getAssSubtitle())) {
|
|
|
- String assSubtitleFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/subtitle/" + BaseUtils.getUUIDStr() + ".ass");
|
|
|
+ String assSubtitleFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/subtitle/" + BaseUtils.getUUIDStr() + ".ass");
|
|
|
FileUtils.saveFileContent(assSubtitleFilePath, param.getAssSubtitle().getBytes());
|
|
|
allLocalFilePathList.add(assSubtitleFilePath);
|
|
|
String inputSubtitleAndStyle = "subtitles=" + assSubtitleFilePath;
|
|
|
- String addSubtitleFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String addSubtitleFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(addSubtitleFilePath);
|
|
|
FFmpegUtil.addSubtitle(lastTailVideoFilePath, inputSubtitleAndStyle, addSubtitleFilePath);
|
|
|
lastTailVideoFilePath = addSubtitleFilePath;
|
|
|
@@ -1201,7 +1189,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
// 处理视频时间戳,避免拼接后时长不对问题
|
|
|
StringBuilder concatContent = new StringBuilder();
|
|
|
for (String concatFilePath : concatFilePathList) {
|
|
|
- String timeFixVideoPath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String timeFixVideoPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(timeFixVideoPath);
|
|
|
FFmpegUtil.encodingEquivalence(concatFilePath, timeFixVideoPath);
|
|
|
concatContent.append("file '" + timeFixVideoPath + "'").append("\n");
|
|
|
@@ -1209,11 +1197,11 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
}
|
|
|
long time10 = System.currentTimeMillis();
|
|
|
log.info("videoAddTail,bizId:{},time10:{}", param.getBizId(), time10 - timea);
|
|
|
- String concatFileListPath = FFmpegUtil.pathCreate("./datalog/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".txt");
|
|
|
+ String concatFileListPath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/filelist/" + BaseUtils.getUUIDStr() + ".txt");
|
|
|
FileUtils.saveFileContent(concatFileListPath, concatContent.toString().trim().getBytes());
|
|
|
allLocalFilePathList.add(concatFileListPath);
|
|
|
|
|
|
- String concatVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String concatVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(concatVideoFilePath);
|
|
|
// 拼接视频
|
|
|
FFmpegUtil.concatVideos(concatFileListPath, concatVideoFilePath);
|
|
|
@@ -1221,7 +1209,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
log.info("videoAddTail,bizId:{},time11:{}", param.getBizId(), time11 - time10);
|
|
|
|
|
|
// 拼接完成后再进行一次编码
|
|
|
-// String outputFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+// String outputFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
// FFmpegUtil.videoTranscoding(concatVideoFilePath, "libx264", outputFilePath);
|
|
|
// allLocalFilePathList.add(outputFilePath);
|
|
|
|
|
|
@@ -1299,11 +1287,11 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
List<String> allLocalFilePathList = new ArrayList<>();
|
|
|
try {
|
|
|
|
|
|
- String originVideoFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String originVideoFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
downloadFile(param.getVideoUrl(), originVideoFilePath);
|
|
|
allLocalFilePathList.add(originVideoFilePath);
|
|
|
|
|
|
- String outputFilePath = FFmpegUtil.pathCreate("./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
+ String outputFilePath = FFmpegUtil.pathCreate(BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4");
|
|
|
allLocalFilePathList.add(outputFilePath);
|
|
|
|
|
|
FFmpegUtil.videoTranscoding(originVideoFilePath, param.getCoding(), param.getBitrate(), outputFilePath);
|
|
|
@@ -1339,19 +1327,19 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
if (videoSize > 500 * 1024 * 1024) {
|
|
|
throw new CommonException(ExceptionEnum.SYSTEM_ERROR.getCode(), "视频文件太大,不能超过500M");
|
|
|
}
|
|
|
- String videoFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String videoFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
downloadFile(param.getVideoUrl(), videoFilePath);
|
|
|
allLocalFilePathList.add(videoFilePath);
|
|
|
String volumeVideoFilePath = videoFilePath;
|
|
|
if (Objects.nonNull(param.getVideoVolume()) && Boolean.TRUE.equals(param.getKeepVideoOriginalSound())) {
|
|
|
- String lufsVideoFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String lufsVideoFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
allLocalFilePathList.add(lufsVideoFilePath);
|
|
|
FFmpegUtil.changeVideoVolumeByLoudnorm(videoFilePath, "-16", lufsVideoFilePath);
|
|
|
|
|
|
String volumeMultiple = new BigDecimal(param.getVideoVolume()).divide(new BigDecimal("50"), 2,
|
|
|
RoundingMode.HALF_UP).toString();
|
|
|
if (new BigDecimal(volumeMultiple).subtract(new BigDecimal("1.00")).abs().compareTo(new BigDecimal("0.1")) > 0) {
|
|
|
- volumeVideoFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ volumeVideoFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
allLocalFilePathList.add(volumeVideoFilePath);
|
|
|
FFmpegUtil.changeVideoVolume(lufsVideoFilePath, volumeMultiple, volumeVideoFilePath);
|
|
|
} else {
|
|
|
@@ -1359,19 +1347,19 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- String audioFilePath = "./datalog/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
+ String audioFilePath = BASE_DIR + "/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
downloadFile(param.getAudioUrl(), audioFilePath);
|
|
|
allLocalFilePathList.add(audioFilePath);
|
|
|
String volumeAudioFilePath = audioFilePath;
|
|
|
if (Objects.nonNull(param.getAudioVolume())) {
|
|
|
- String lufsAudioFilePath = "./datalog/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
+ String lufsAudioFilePath = BASE_DIR + "/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
allLocalFilePathList.add(lufsAudioFilePath);
|
|
|
FFmpegUtil.changeMediaVolumeByLoudnorm(audioFilePath, "-16", lufsAudioFilePath);
|
|
|
|
|
|
String volumeMultiple = new BigDecimal(param.getAudioVolume()).divide(new BigDecimal("50"), 2,
|
|
|
RoundingMode.HALF_UP).toString();
|
|
|
if (new BigDecimal(volumeMultiple).subtract(new BigDecimal("1.00")).abs().compareTo(new BigDecimal("0.1")) > 0) {
|
|
|
- volumeAudioFilePath = "./datalog/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
+ volumeAudioFilePath = BASE_DIR + "/videoComposite/audio/" + BaseUtils.getUUIDStr() + ".mp3";
|
|
|
allLocalFilePathList.add(volumeAudioFilePath);
|
|
|
FFmpegUtil.changeMediaVolume(lufsAudioFilePath, volumeMultiple, volumeAudioFilePath);
|
|
|
} else {
|
|
|
@@ -1379,7 +1367,7 @@ public class FFmpegServiceImpl implements FFmpegService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- String outputFilePath = "./datalog/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
+ String outputFilePath = BASE_DIR + "/videoComposite/video/" + BaseUtils.getUUIDStr() + ".mp4";
|
|
|
|
|
|
if (StringUtils.hasText(param.getMainTimeline()) && "audio".equals(param.getMainTimeline())) {
|
|
|
FFmpegUtil.MediaInfo videoMediaInfo = FFmpegUtil.getMediaInfo(volumeVideoFilePath);
|