在获取后缀为kux视频格式时可能会根据需求需要将其转换为mp4等文件格式,那么该如何转换呢?
1.先下载一个对应视频客户端
需要使用客户端中自带的ffmpeg插件
2.通过代码将其进行转换
/**
* 将kux格式视频转换为mp4格式文件
* @param inputPath 需要转换的kux格式视频地址(本地)
* @param outputPath 转换后的mp4保存地址以及文件名称
* @return
*/
public boolean processKuxToMp4(String inputPath,String outputPath) {
List<String> command = new ArrayList<String>();
//这里的ffmpeg地址为对应视频客户端自带的ffmpeg地址(kuxAddress )。
//ffmpeg -y -i inputPath -c:a copy -threads 2 outputPath
command.add(kuxAddress + "ffmpeg");
command.add("-y");
command.add("-i");
command.add(inputPath);
command.add("-c:a");
command.add("copy");
command.add("-threads");
command.add("2");
command.add(outputPath);
try {
// 方案2
Process videoProcess = new ProcessBuilder(command).redirectErrorStream(true).start();
new PrintStream(videoProcess.getErrorStream()).start();
new PrintStream(videoProcess.getInputStream()).start();
videoProcess.waitFor();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
//可以根据需求在转换格式后将原文件进行删除(默认保存)
}
/**
* 转换视频格式时需要的自定义线程
*
*/
public class PrintStream extends Thread{
java.io.InputStream __is = null;
public PrintStream(java.io.InputStream is)
{
__is = is;
}
public void run()
{
try
{
while(this != null)
{
int _ch = __is.read();
if(_ch != -1)
//System.out.print((char)_ch);
System.out.print("");
else break;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
转换完毕后便可在设置的文件路径处看到转换后的视频文件。