1、FileManagementHelper 视频转码类
package com.openailab.oascloud.file.common.helper;
import com.openailab.oascloud.file.common.config.BootstrapConfig;
import com.openailab.oascloud.file.common.consts.BootstrapConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
/**
-
@description: 视频转码
-
@author: zhangzhixiang
-
@createDate: 2019/12/11
-
@version: 1.0
*/
@Component
public class FileManagementHelper {
private static final Logger LOG = LoggerFactory.getLogger(FileManagementHelper.class);
@Autowired
private BootstrapConfig bootstrapConfig;
/**
-
文件转码
-
@param filePath
-
@return com.openailab.oascloud.common.model.ResponseResult
-
@author zxzhang
-
@date 2019/12/10
*/
public int transcode(String filePath) {
//1、获取文件名和后缀
String ext = getExt(filePath);
String fileDir = getFileDir(filePath);
String fileName = getFileName(filePath);
//2、删除同名文件
File originFile = new File(fileDir + fileName + BootstrapConst.SPOT + ext);
if (originFile.exists()){
originFile.delete();
}
//3、视频转码
LinkedList ffmpegCmds = new LinkedList<>();
ffmpegCmds.add(“ffmpeg”);
ffmpegCmds.add("-i");
ffmpegCmds.add(bootstrapConfig.getFileRoot() + filePath);
ffmpegCmds.add("-c:v");
ffmpegCmds.add(“libx264”);
ffmpegCmds.add("-strict");
ffmpegCmds.add("-2");
ffmpegCmds.add(bootstrapConfig.getFileRoot() + fileDir + BootstrapConst.PATH_SEPARATOR + fileName + “.mp4”);
ProcessBuilder builder = new ProcessBuilder();
builder.command(ffmpegCm