添加定时删除功能

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