添加定时删除功能

This commit is contained in:
孙小云 2025-08-04 15:24:12 +08:00
parent 240b87ab35
commit 71919393ef
1 changed files with 16 additions and 21 deletions

View File

@ -152,21 +152,20 @@ public class ProcessService {
public StreamProcess takePic(String streamUrl) throws IOException { public StreamProcess takePic(String streamUrl) throws IOException {
String outFileName = targetPath + "/" +UUID.randomUUID().toString() +".jpg"; String outFileName = targetPath + "/" +UUID.randomUUID().toString() +".jpg";
String command = String.format(
ffmpeg+ " -i %s -vf fps=1 -frames:v 1 -q:v 2 %s",
streamUrl, outFileName);
// -rw_timeout 5
List<String> listCommand = new ArrayList<>(); List<String> listCommand = new ArrayList<>();
listCommand.add(ffmpeg); // ffmpeg 路径 listCommand.add(ffmpeg); // ffmpeg 路径
// listCommand.add("-timeout");
// 添加重连和超时参数 // listCommand.add("3000000");
listCommand.add("-reconnect"); // listCommand.add("-rw_timeout");
listCommand.add("1"); // listCommand.add("5000000");
listCommand.add("-reconnect_streamed");
listCommand.add("1");
listCommand.add("-reconnect_delay_max");
listCommand.add("5");
listCommand.add("-rw_timeout");
listCommand.add("10000000"); // 10秒读取超时
listCommand.add("-i"); listCommand.add("-i");
// listCommand.add(" -timeout 3000000 -rw_timeout 5000000 -i ");
listCommand.add(streamUrl); // 流地址 listCommand.add(streamUrl); // 流地址
listCommand.add("-vf"); listCommand.add("-vf");
listCommand.add("fps=1"); listCommand.add("fps=1");
@ -174,23 +173,19 @@ public class ProcessService {
listCommand.add("1"); listCommand.add("1");
listCommand.add("-q:v"); listCommand.add("-q:v");
listCommand.add("2"); listCommand.add("2");
listCommand.add("-y"); // 覆盖输出文件
listCommand.add(outFileName); // 输出文件名 listCommand.add(outFileName); // 输出文件名
logger.info("takePic {}", listCommand); logger.info("takePic {}", listCommand);
ProcessBuilder pb = new ProcessBuilder(listCommand); ProcessBuilder pb = new ProcessBuilder(listCommand);
pb.redirectErrorStream(true); pb.redirectErrorStream(true);
Process process = pb.start(); Process process = pb.start();
// 增加超时时间到60秒
try { try {
if (!process.waitFor(60, TimeUnit.SECONDS)) { if (!process.waitFor(30, TimeUnit.SECONDS)) {
process.destroyForcibly(); process.destroyForcibly();
logger.warn("takePic {} 超时60秒", listCommand); // 处理超时逻辑
logger.info("takePic {} 超时", listCommand);
} }
}catch (Exception e) { }catch (Exception ignore) {
logger.error("takePic 等待进程异常", e);
} }
loggingService.execute(new Runnable() { loggingService.execute(new Runnable() {
@ -200,7 +195,7 @@ public class ProcessService {
new InputStreamReader(process.getInputStream()))) { new InputStreamReader(process.getInputStream()))) {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
logger.info("takePic-------- {}",line); logger.info("recordStream-------- {}",line);
} }
} catch (IOException e) { } catch (IOException e) {
logger.info("takePic-------- Over"); logger.info("takePic-------- Over");