package com.ruoyi.common.utils.ffmpeg; import java.util.ArrayList; import java.util.List; public class MediaConvertUtils { public static String exchangeToMp4(String ffmpegPath, String upFilePath, String codcFilePath) throws Exception { // 创建List集合来保存转换视频文件为flv格式的命令 List convert = new ArrayList(); convert.add(ffmpegPath); // 添加转换工具路径 convert.add("-y"); // 该参数指定将覆盖已存在的文件 convert.add("-i"); convert.add(upFilePath); convert.add("-c:v"); convert.add("libx264"); convert.add("-c:a"); convert.add("aac"); convert.add("-strict"); convert.add("-2"); convert.add("-pix_fmt"); convert.add("yuv420p"); convert.add("-movflags"); convert.add("faststart"); //convert.add("-vf"); // 添加水印 //convert.add("movie=watermark.gif[wm];[in][wm]overlay=20:20[out]"); convert.add(codcFilePath); try { Process videoProcess = new ProcessBuilder(convert).redirectErrorStream(true).start(); new PrintStream(videoProcess.getInputStream()).start(); //videoProcess.waitFor(); // 加上这句,系统会等待转换完成。不加,就会在服务器后台自行转换。 } catch (Exception e) { System.out.println(e); e.printStackTrace(); } return codcFilePath; } }