FfmpegUtils解码JAVA工具类
package com.core.util;
import com.core.config.Constants;
import com.core.thread.StreamGobblerThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
/**
* ffmpeg通用类
*
* @author manhengwei
* @date 2022/12/28
* @since 1.0
*/
public class FfmpegUtils {
private static final Logger logger = LoggerFactory.getLogger(FfmpegUtils.class);
public static void video2Image(String sourceFileName, String destDir, int fps) {
String cmd = Constants.FFMPEG_HOME + "ffmpeg -i " + sourceFileName + " -r " + fps + "/1 -qscale 0 -s 256x256 -vframes 5000 -sws_flags neighbor " + destDir + "$filename%05d.jpg";
//logger.warn("ffmpeg video2Image cmd:" + cmd);
FfmpegUtils.shell(cmd);
}
public static void video2ImageNoOverwrite(String sourceFileName, String destDir, int fps) {
String cmd = Constants.FFMPEG_HOME + "ffmpeg -i " + sourceFileName + " -r " + fps + "/1 -qscale 0 -s 256x256 -vframes 5000 -sws_flags neighbor " + destDir + "$filename%05d.jpg";
//logger.warn("ffmpeg video2ImageNoOverwrite cmd:" + cmd);
FfmpegUtils.shell(cmd);
}
public static void image2Video(String sourceDir, String outputFile, int fps, int times) {
String cmd = "type " + sourceDir + File.separator + "*.jpg | " + Constants.FFMPEG_HOME + "ffmpeg -r " + fps + " -t " + times + " -i pipe:0 " + " -vcodec libx264 " + " -y " + outputFile;