不用我们安装FFmpeg,项目自动依赖ffmpeg,已经有开源实现:https://github.com/a-schild/jave2
下面的代码基于:3.1.1 version
maven坐标:
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-all-deps</artifactId>
<version>3.1.1</version>
</dependency>
java代码:
DefaultFFMPEGLocator defaultFFMPEGLocator = new DefaultFFMPEGLocator();
ProcessWrapper processWrapper = defaultFFMPEGLocator.createExecutor();
//你需要的自定义的FFmpeg原生命令(比如mp4 转 mp3:ffmpeg -i foo.mp4 foobar.mp3)......
processWrapper.addArgument("ffmpeg -i foo.mp4 foobar.mp3");
//destroyOnRuntimeShutdown表示是否立即关闭Runtime
//如果ffmpeg命令需要长时间执行,destroyOnRuntimeShutdown = false
//openIOStreams表示是不是需要打开输入输出流:
// inputStream = processWrapper.getInputStream();
// outputStream = processWrapper.getOutputStream();
// errorStream = processWrapper.getErrorStream();
//processWrapper.execute() 默认: processWrapper.execute(true,true)
processWrapper.execute(boolean destroyOnRuntimeShutdown, boolean openIOStreams);
//是否执行完毕
int exitCode = processWrapper.getProcessExitCode()
//执行完毕,关闭
processWrapper.destroy();
我的小站:
http://www.binarydance.top//aticle_view.html?aticle_id=587710507340017664&t=1620287576763