Java使用ffmpeg
首先完成基本的Java调用ffmpeg代码实现
复制package com.example.ffmpegtest01.service.impl;
import com.example.ffmpegtest01.service.OperationService;
import org.springframework.stereotype.Service;
import java.io.File;
@Service
public class OperationServiceImpl implements OperationService {
@Override
public Boolean ForAvi(String sourcePath, String targetPath) {//sourcePtah是对应的文件的路径
String webroot = "D:\\devsoft\\ffmpeg\\bin";
Runtime run= null;
System.out.println(new File(webroot).getAbsolutePath());
try{
run = Runtime.getRuntime();
long start = System.currentTimeMillis();
//File diretory = new File("");
System.out.println("开始");
Process p = run.exec(new File(webroot).getAbsolutePath()+"/ffmpeg -i "+sourcePath+" -codec copy "+targetPath);
System.out.println("结束");
long end = System.currentTimeMillis();
System.out.println("转化结束"+(end-start));
p.getOutputStream().close();
p.getInputStream().close();
p.getErrorStream().close();
p.waitFor();
return true;
}catch (Exception e){
e.printStackTrace();
return false;
}finally {
run.freeMemory();
}
}
}
Java操作ffmpeg优秀博客
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步