|
@@ -169,17 +169,21 @@ public class VideoGenerateJob {
|
|
|
if (CollectionUtil.isNotEmpty(imageList)) {
|
|
if (CollectionUtil.isNotEmpty(imageList)) {
|
|
|
for (SpiderContentMedia image : imageList) {
|
|
for (SpiderContentMedia image : imageList) {
|
|
|
// 现仅一种效果,后更改为多种效果随机
|
|
// 现仅一种效果,后更改为多种效果随机
|
|
|
- String command = "ffmpeg -loop 1 -i input.jpg -t 3 -r 25 -filter_complex \"[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,gblur=sigma=5[bg];[0:v]scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:color=black@0[fg];[fg]zoompan=z='min(1.00+0.000266*on,1.02)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':s=1080x1920[fg_anim];[bg][fg_anim]overlay=0:0:format=auto\" -c:v libx264 -pix_fmt yuv420p -movflags +faststart \"output.mp4\"";
|
|
|
|
|
- command = command.replace("input.jpg", CdnUtil.getOssHttpUrl(image.getOssKey()));
|
|
|
|
|
String outputVideoName = String.format("%s_%d.mp4", produceVideo.getContentId(), System.currentTimeMillis());
|
|
String outputVideoName = String.format("%s_%d.mp4", produceVideo.getContentId(), System.currentTimeMillis());
|
|
|
- command = command.replace("output.mp4", outputVideoName);
|
|
|
|
|
|
|
+ String command = String.format("ffmpeg -loop 1 -i %s -t 3 -r 25 -filter_complex " +
|
|
|
|
|
+ "\"[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,gblur=sigma=5[bg];" +
|
|
|
|
|
+ "[0:v]scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2:color=black@0[fg];" +
|
|
|
|
|
+ "[fg]zoompan=z='min(1.00+0.000266*on,1.02)':d=1:x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':s=1080x1920[fg_anim];" +
|
|
|
|
|
+ "[bg][fg_anim]overlay=0:0:format=auto\" " +
|
|
|
|
|
+ "-c:v libx264 -pix_fmt yuv420p -movflags +faststart \"%s\"",
|
|
|
|
|
+ CdnUtil.getOssHttpUrl(image.getOssKey()), outputVideoName);
|
|
|
CommandParam commandParam = CommandParam.builder()
|
|
CommandParam commandParam = CommandParam.builder()
|
|
|
.ffmpegCommand(command)
|
|
.ffmpegCommand(command)
|
|
|
.outputFile(outputVideoName)
|
|
.outputFile(outputVideoName)
|
|
|
.outputType("video")
|
|
.outputType("video")
|
|
|
.build();
|
|
.build();
|
|
|
String commandResponseData = ffmpegApiService.command(commandParam);
|
|
String commandResponseData = ffmpegApiService.command(commandParam);
|
|
|
- String fileName = String.format("material/video/%s", outputVideoName);
|
|
|
|
|
|
|
+ String fileName = String.format("supply/material/video/%s", outputVideoName);
|
|
|
String imageToVideoOssUrl = AliOssFileTool.downloadAndSaveInOSS(fileName, commandResponseData, "video/mp4");
|
|
String imageToVideoOssUrl = AliOssFileTool.downloadAndSaveInOSS(fileName, commandResponseData, "video/mp4");
|
|
|
|
|
|
|
|
// 获取视频信息
|
|
// 获取视频信息
|
|
@@ -231,7 +235,7 @@ public class VideoGenerateJob {
|
|
|
.build();
|
|
.build();
|
|
|
lastEndTime = endTime;
|
|
lastEndTime = endTime;
|
|
|
String videoCutUrl = ffmpegApiService.timeCutVideo(timeCutParam);
|
|
String videoCutUrl = ffmpegApiService.timeCutVideo(timeCutParam);
|
|
|
- String fileName = String.format("material/video/%s_%d.mp4", produceVideo.getContentId(), System.currentTimeMillis());
|
|
|
|
|
|
|
+ String fileName = String.format("supply/material/video/%s_%d.mp4", produceVideo.getContentId(), System.currentTimeMillis());
|
|
|
String videoCutOssUrl = AliOssFileTool.downloadAndSaveInOSS(fileName, videoCutUrl, "video/mp4");
|
|
String videoCutOssUrl = AliOssFileTool.downloadAndSaveInOSS(fileName, videoCutUrl, "video/mp4");
|
|
|
// 获取视频信息
|
|
// 获取视频信息
|
|
|
MediaInfo mediaInfo = getMediaInfo(videoCutOssUrl);
|
|
MediaInfo mediaInfo = getMediaInfo(videoCutOssUrl);
|
|
@@ -300,6 +304,10 @@ public class VideoGenerateJob {
|
|
|
if (materialList.size() < 10) {
|
|
if (materialList.size() < 10) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ ProduceVideoAudio audio = getProduceAudio(produceVideo);
|
|
|
|
|
+ if (audio == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
// short video to long video
|
|
// short video to long video
|
|
|
// 视频素材拼接长视频
|
|
// 视频素材拼接长视频
|
|
|
VideoUrlsParam concatParam = VideoUrlsParam.builder()
|
|
VideoUrlsParam concatParam = VideoUrlsParam.builder()
|
|
@@ -309,17 +317,15 @@ public class VideoGenerateJob {
|
|
|
String concatVideoUrl = ffmpegApiService.videoConcat(concatParam);
|
|
String concatVideoUrl = ffmpegApiService.videoConcat(concatParam);
|
|
|
// add audio
|
|
// add audio
|
|
|
String videoName = String.format("%s_%d.mp4", produceVideo.getId(), System.currentTimeMillis());
|
|
String videoName = String.format("%s_%d.mp4", produceVideo.getId(), System.currentTimeMillis());
|
|
|
- String command = "ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -map 0:v:0 -map 1:a:0 -shortest -y output.mp4";
|
|
|
|
|
- command = command.replace("video.mp4", concatVideoUrl);
|
|
|
|
|
- command = command.replace("audio.mp3", materialList.get(0).getUrl());
|
|
|
|
|
- command = command.replace("output.mp4", videoName);
|
|
|
|
|
|
|
+ String command = String.format("ffmpeg -i %s -i %s -c:v copy -map 0:v:0 -map 1:a:0 -shortest -y %s",
|
|
|
|
|
+ concatVideoUrl, audio.getUrl(), videoName);
|
|
|
CommandParam commandParam = CommandParam.builder()
|
|
CommandParam commandParam = CommandParam.builder()
|
|
|
.ffmpegCommand(command)
|
|
.ffmpegCommand(command)
|
|
|
.outputFile(videoName)
|
|
.outputFile(videoName)
|
|
|
.outputType("video")
|
|
.outputType("video")
|
|
|
.build();
|
|
.build();
|
|
|
String commandResponseData = ffmpegApiService.command(commandParam);
|
|
String commandResponseData = ffmpegApiService.command(commandParam);
|
|
|
- String fileName = String.format("video/%s", videoName);
|
|
|
|
|
|
|
+ String fileName = String.format("supply/video/%s", videoName);
|
|
|
String finalVideoUrl = AliOssFileTool.downloadAndSaveInOSS(fileName, commandResponseData, "video/mp4");
|
|
String finalVideoUrl = AliOssFileTool.downloadAndSaveInOSS(fileName, commandResponseData, "video/mp4");
|
|
|
// 更新视频地址
|
|
// 更新视频地址
|
|
|
produceVideo.setUrl(finalVideoUrl);
|
|
produceVideo.setUrl(finalVideoUrl);
|
|
@@ -329,9 +335,19 @@ public class VideoGenerateJob {
|
|
|
return ReturnT.SUCCESS;
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private ProduceVideoAudio getProduceAudio(ProduceVideo produceVideo) {
|
|
|
|
|
+ ProduceVideoAudioExample example = new ProduceVideoAudioExample();
|
|
|
|
|
+ example.createCriteria().andProduceVideoIdEqualTo(produceVideo.getId()).andStatusEqualTo(1);
|
|
|
|
|
+ List<ProduceVideoAudio> audioList = produceVideoAudioMapper.selectByExample(example);
|
|
|
|
|
+ if (CollectionUtil.isEmpty(audioList)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return audioList.get(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private List<ProduceVideoMaterial> getVideoMaterialList(ProduceVideo produceVideo) {
|
|
private List<ProduceVideoMaterial> getVideoMaterialList(ProduceVideo produceVideo) {
|
|
|
ProduceVideoMaterialExample example = new ProduceVideoMaterialExample();
|
|
ProduceVideoMaterialExample example = new ProduceVideoMaterialExample();
|
|
|
- example.createCriteria().andProduceVideoIdEqualTo(produceVideo.getId());
|
|
|
|
|
|
|
+ example.createCriteria().andProduceVideoIdEqualTo(produceVideo.getId()).andStatusEqualTo(1);
|
|
|
return produceVideoMaterialMapper.selectByExample(example);
|
|
return produceVideoMaterialMapper.selectByExample(example);
|
|
|
}
|
|
}
|
|
|
|
|
|