1 Star 0 Fork 0

ws/javm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DefaultFFMPEGLocator.java 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
YCKJ2817 提交于 4年前 . video encode tool
package cn.angs;
import java.io.*;
import static cn.angs.FileUtil.loadRecourseFromJarByFolder;
/**
* ClassName: DefaultFFMPEGLocator.java
* Description: 默认的ffmpeg可执行定位器,运行时在程序临时文件目录生成ffmpeg执行文件,
* 适配windows、linux、mac系统
*
* @author wangshun@cloudwalk.cn
* @version 1.0.0
* @date 2021/07/22 13:47
*/
public class DefaultFFMPEGLocator extends AbstractFFMPEGLocator {
/**
* 追踪版本
*/
private static final int myEXEversion = 1;
/**
* ffmpeg路径.
*/
private String path;
private static final String WIN = "windows";
private static final String MAC = "mac";
/**
* 构建默认的FFMPEGLocator实例,并且导出ffmpeg执行文件到临时目录
*/
public DefaultFFMPEGLocator() {
String os = System.getProperty("os.name").toLowerCase();
// Windows?
boolean isWindows = os.contains(WIN);
//MacOS
boolean isMacOS = os.contains(MAC);
File temp = new File(System.getProperty("java.io.tmpdir"), "jave-"
+ myEXEversion);
if (!temp.exists()) {
temp.mkdirs();
temp.deleteOnExit();
}
String relativePath;
if (isMacOS) {
relativePath = "macos10";
} else if (isWindows) {
relativePath = "window";
} else {
relativePath = "linux";
}
String _temp = temp.getPath() + File.separator;
String ffmpeg = isWindows ? "ffmpeg.exe" : "ffmpeg";
String absolutePath;
if (isWindows) {
absolutePath = temp + File.separator + "system" + File.separator + relativePath + File.separator + "bin" + File.separator + ffmpeg;
} else {
absolutePath = temp + File.separator + "system" + File.separator + relativePath + File.separator + ffmpeg;
}
File ffmpegFile = new File(absolutePath);
if (!ffmpegFile.exists()) {
loadRecourseFromJarByFolder("/system/" + relativePath, _temp, this.getClass());
if (!isWindows) {
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(new String[]{"/bin/chmod", "755",
absolutePath});
} catch (IOException e) {
e.printStackTrace();
}
}
}
this.path = absolutePath;
}
@Override
protected String getFFMPEGExecutablePath() {
return path;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ws410/javm.git
git@gitee.com:ws410/javm.git
ws410
javm
javm
master

搜索帮助