import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
- 视频截图截图处理器
- @Author lixiaowen
- @date 2018/6/29
*/
@Log4j2
@Deprecated
public class VideoCaptureHandler {
private String destDir = "D:/";
/**
* 返回截图所在目录
*
* @param video
* @param start
* @param frequency
* @return
*/
//视频截图
public String capture(String video, String start, int frequency) {
//截图命令
StringBuilder sb = new StringBuilder("D:\\Program Files\\ffmpeg-4.0-win64-static\\bin\\ffmpeg -ss ");
String dir = destDir + System.currentTimeMillis() + "";
sb.append(start);
sb.append(" -i ");
sb.append(video);
sb.append(" -t 180");
sb.append(" -f image2 -vf fps=fps=1/");
sb.append(frequency);
//hashCode会重复
sb.append(" " + dir);
sb.append("/out%d.png");
if (!new File(dir).exists()) {
new File(dir).mkdirs();
}
try {
log.info("运行截图命令:" + sb.toString());
Process exec = Runtime.getRuntime().exec(sb.toString());
exec.waitFor(30, TimeUnit.SECONDS);//等待截图完成
} catch (IOException | InterruptedException e) {
log.error("截图失败,命令{}", sb.toString(), e.getMessage());
//e.printStackTrace();
return null;
}
return dir;
}
}
网友评论