|
@@ -24,19 +24,16 @@
|
|
|
|
|
|
package com.tzld.crawler.etl.util;
|
|
|
|
|
|
+import com.tzld.crawler.etl.common.enums.ExceptionEnum;
|
|
|
+import com.tzld.crawler.etl.common.exception.CommonException;
|
|
|
import com.tzld.crawler.etl.model.dto.VideoInfoDto;
|
|
|
-import net.bramp.ffmpeg.FFmpeg;
|
|
|
-import net.bramp.ffmpeg.FFmpegExecutor;
|
|
|
import net.bramp.ffmpeg.FFprobe;
|
|
|
-import net.bramp.ffmpeg.builder.FFmpegBuilder;
|
|
|
import net.bramp.ffmpeg.probe.FFmpegFormat;
|
|
|
import net.bramp.ffmpeg.probe.FFmpegProbeResult;
|
|
|
import net.bramp.ffmpeg.probe.FFmpegStream;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
/**
|
|
|
* @author ehlxr
|
|
|
* @since 2023-06-26 18:01.
|
|
@@ -63,29 +60,31 @@ public class VideoUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void videoCompose(String videoPath, String audioPath, String outPath) {
|
|
|
+ public static void videoCompose(String ffmpegPath, String videoPath, String audioPath, String outPath) {
|
|
|
try {
|
|
|
- FFmpeg fFmpeg = new FFmpeg("ffmpeg");
|
|
|
- FFprobe fFprobe = new FFprobe("ffprobe");
|
|
|
-
|
|
|
- FFmpegBuilder builder = new FFmpegBuilder()
|
|
|
- .setInput(videoPath) // 主输入为视频文件
|
|
|
- .addExtraArgs("-i", audioPath) // 然后添加音频文件作为参数
|
|
|
- .addOutput(outPath) // 输出文件
|
|
|
- .addExtraArgs("-c:v", "copy") // 使用原视频的编码
|
|
|
- .addExtraArgs("-c:a", "aac") // 音频用aac编码
|
|
|
- .addExtraArgs("-strict", "experimental")
|
|
|
- .addExtraArgs("-map", "0:v:0") // 映射视频流
|
|
|
- .addExtraArgs("-map", "1:a:0") // 映射音频流
|
|
|
- .done();
|
|
|
- FFmpegExecutor executor = new FFmpegExecutor(fFmpeg, fFprobe);
|
|
|
- executor.createJob(builder).run(); // 执行 ffmpeg 命令
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
+ // FFmpeg fFmpeg = new FFmpeg("ffmpeg");
|
|
|
+ // FFprobe fFprobe = new FFprobe("ffprobe");
|
|
|
+ //
|
|
|
+ // FFmpegBuilder builder = new FFmpegBuilder()
|
|
|
+ // .addInput(videoPath)
|
|
|
+ // // .addExtraArgs("-i", videoPath) // 然后添加音频文件作为参数
|
|
|
+ // .addExtraArgs("-i", audioPath) // 然后添加音频文件作为参数
|
|
|
+ // .addOutput(outPath) // 输出文件
|
|
|
+ // .addExtraArgs("-c:v", "copy") // 使用原视频的编码
|
|
|
+ // .addExtraArgs("-c:a", "aac") // 音频用aac编码
|
|
|
+ // .addExtraArgs("-strict", "experimental")
|
|
|
+ // .addExtraArgs("-map", "0:v:0") // 映射视频流
|
|
|
+ // .addExtraArgs("-map", "1:a:0") // 映射音频流
|
|
|
+ // .done();
|
|
|
+ // FFmpegExecutor executor = new FFmpegExecutor(fFmpeg, fFprobe);
|
|
|
+ // executor.createJob(builder).run(); // 执行 ffmpeg 命令
|
|
|
+ ProcessBuilder processBuilder = new ProcessBuilder(ffmpegPath, "-i", videoPath, "-i", audioPath,
|
|
|
+ "-c:v", "copy", "-c:a", "aac", "-strict", "experimental", "-map", "0:v:0", "-map", "1:a:0", outPath);
|
|
|
+ Process process = processBuilder.start();
|
|
|
+ process.waitFor();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("video {} audio {} compose error.", videoPath, audioPath, e);
|
|
|
+ throw new CommonException(ExceptionEnum.DATA_ERROR, "video compose error");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- videoCompose("", "", "");
|
|
|
- }
|
|
|
}
|