ffmpeg的使用方式有以下几种:
直接在ffmpeg官网上下载安装该软件,加入到环境变量中就可以使用了
优点:简单,灵活,代码中也不用添加其他第三方的包
缺点:需要手动安装ffmpeg,这点比较麻烦
在windows环境下,有时就算加入到了环境变量,在程序中依然有可能会报错找不到ffmpeg.exe文件,此时可以直接在配置文件中指定脚本路径,CmdHandleConfig
@ConfigurationProperties(prefix = "cmd-handle")
@Component
@Data
public class CmdHandleConfig {
/**
* ffmpeg的路径
*/
private String ffmpegPath;
}
public static String getFfmpegPath() {
CmdHandleConfig cmdHandleConfig = SpringUtil.getBean(CmdHandleConfig.class);
if (StringUtils.hasText(cmdHandleConfig.getFfmpegPath())) {
return cmdHandleConfig.getFfmpegPath();
}
OsInfo osInfo = SystemUtil.getOsInfo();
String suffix = osInfo.isWindows() ? ".exe" : (osInfo.isMac() ? "-osx" : "");
return "ffmpeg" + suffix;
}
说明:方法中使用的都是hutool的工具包;windows中的执行脚本是ffmpeg.exe,linux上是ffmpeg
在linux上手动获取脚本路径,可使用以下命令:
which ffmpeg
在linux上部署分为两种情况,直接使用宿主机环境安装和使用docker安装
添加源并安装,这种装好的ffmpeg命令是已经自动加到了环境变量,不需要自己再手动添加
echo > /etc/apt/sources.list
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free" >/etc/apt/sources.list
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free" >>/etc/apt/sources.list
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free" >>/etc/apt/sources.list
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free" >>/etc/apt/sources.list
apt-get -y update && apt-get install -y ffmpeg