ADD error handling

This commit is contained in:
2025-05-12 21:57:31 +02:00
parent 489372ea61
commit 25dd60dd82
3 changed files with 14 additions and 5 deletions

View File

@@ -2,7 +2,6 @@ package com.ddf.vodsystem.controllers;
import com.ddf.vodsystem.entities.ClipConfig;
import com.ddf.vodsystem.services.EditService;
import org.atmosphere.config.service.Get;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -34,4 +33,9 @@ public class EditController {
return new ResponseEntity<>(editService.getProgress(uuid), HttpStatus.OK);
}
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<String> handleIllegalArgument(IllegalArgumentException ex) {
return ResponseEntity.status(404).body(ex.getMessage());
}
}

View File

@@ -25,8 +25,7 @@ public class CompressionService {
private static final float MAX_AUDIO_BITRATE = 128f;
private static final float BITRATE_MULTIPLIER = 0.9f;
private Pattern timePattern = Pattern.compile("out_time_ms=([\\d:.]+)");
private long out_time_ms;
private final Pattern timePattern = Pattern.compile("out_time_ms=([\\d:.]+)");
private void buildFilters(ArrayList<String> command, Float fps, Integer width, Integer height) {
List<String> filters = new ArrayList<>();
@@ -110,17 +109,18 @@ public class CompressionService {
logger.info("FFMPEG starting...");
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getClipConfig());
pb.redirectErrorStream(true);
//pb.redirectErrorStream(true);
Process process = pb.start();
job.setStatus(JobStatus.RUNNING);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
Float length = job.getClipConfig().getEndPoint() - job.getClipConfig().getStartPoint();
float length = job.getClipConfig().getEndPoint() - job.getClipConfig().getStartPoint();
String line;
while ((line = reader.readLine()) != null) {
logger.debug(line);
Matcher matcher = timePattern.matcher(line);
if (matcher.find()) {
Float progress = Float.parseFloat(matcher.group(1))/(length*1000000);
job.setProgress(progress);

View File

@@ -2,6 +2,7 @@ package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.ClipConfig;
import com.ddf.vodsystem.entities.Job;
import com.ddf.vodsystem.entities.JobStatus;
import com.ddf.vodsystem.exceptions.JobNotFound;
import org.springframework.stereotype.Service;
@@ -36,6 +37,10 @@ public class EditService {
throw new JobNotFound(uuid);
}
if (job.getStatus() == JobStatus.FINISHED) {
return 1f;
}
return job.getProgress();
}
}