flv格式转换为mp4(ffmpeg)
·
使用java将flv文件格式视频转换为mp4文件格式,使用的工具为ffmpeg。
/**
* 转换视频格式时需要的自定义线程
*/
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();
}
}
}
public class ConvertVideoUtils(){
/**
* flv转换为mp4
* @param ffmpegPath ffmpeg安装路径
* @param inputPath 需要转换为文件(flv)
* @param outputPath 转换后得文件(mp4)
* @return
*/
private boolean processMp4(String ffmpegPath,String inputPath,String outputPath) {
List<String> command = new ArrayList<String>();
command.add(ffmpegPath + "ffmpeg");
command.add("-i");
command.add(inputPath);
command.add("-c:v");
command.add("libx264");
command.add("-mbd");
command.add("0");
command.add("-c:a");
command.add("aac");
command.add("-strict");
command.add("-2");
command.add("-pix_fmt");
command.add("yuv420p");
command.add("-movflags");
command.add("faststart");
command.add(outputPath);
try {
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;
}
}
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)