ADD error handling
This commit is contained in:
@@ -2,7 +2,6 @@ package com.ddf.vodsystem.controllers;
|
|||||||
|
|
||||||
import com.ddf.vodsystem.entities.ClipConfig;
|
import com.ddf.vodsystem.entities.ClipConfig;
|
||||||
import com.ddf.vodsystem.services.EditService;
|
import com.ddf.vodsystem.services.EditService;
|
||||||
import org.atmosphere.config.service.Get;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -34,4 +33,9 @@ public class EditController {
|
|||||||
return new ResponseEntity<>(editService.getProgress(uuid), HttpStatus.OK);
|
return new ResponseEntity<>(editService.getProgress(uuid), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(IllegalArgumentException.class)
|
||||||
|
public ResponseEntity<String> handleIllegalArgument(IllegalArgumentException ex) {
|
||||||
|
return ResponseEntity.status(404).body(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ public class CompressionService {
|
|||||||
private static final float MAX_AUDIO_BITRATE = 128f;
|
private static final float MAX_AUDIO_BITRATE = 128f;
|
||||||
private static final float BITRATE_MULTIPLIER = 0.9f;
|
private static final float BITRATE_MULTIPLIER = 0.9f;
|
||||||
|
|
||||||
private Pattern timePattern = Pattern.compile("out_time_ms=([\\d:.]+)");
|
private final Pattern timePattern = Pattern.compile("out_time_ms=([\\d:.]+)");
|
||||||
private long out_time_ms;
|
|
||||||
|
|
||||||
private void buildFilters(ArrayList<String> command, Float fps, Integer width, Integer height) {
|
private void buildFilters(ArrayList<String> command, Float fps, Integer width, Integer height) {
|
||||||
List<String> filters = new ArrayList<>();
|
List<String> filters = new ArrayList<>();
|
||||||
@@ -110,17 +109,18 @@ public class CompressionService {
|
|||||||
logger.info("FFMPEG starting...");
|
logger.info("FFMPEG starting...");
|
||||||
|
|
||||||
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getClipConfig());
|
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getClipConfig());
|
||||||
pb.redirectErrorStream(true);
|
//pb.redirectErrorStream(true);
|
||||||
Process process = pb.start();
|
Process process = pb.start();
|
||||||
job.setStatus(JobStatus.RUNNING);
|
job.setStatus(JobStatus.RUNNING);
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
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;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
logger.debug(line);
|
logger.debug(line);
|
||||||
Matcher matcher = timePattern.matcher(line);
|
Matcher matcher = timePattern.matcher(line);
|
||||||
|
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
Float progress = Float.parseFloat(matcher.group(1))/(length*1000000);
|
Float progress = Float.parseFloat(matcher.group(1))/(length*1000000);
|
||||||
job.setProgress(progress);
|
job.setProgress(progress);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.ddf.vodsystem.services;
|
|||||||
|
|
||||||
import com.ddf.vodsystem.entities.ClipConfig;
|
import com.ddf.vodsystem.entities.ClipConfig;
|
||||||
import com.ddf.vodsystem.entities.Job;
|
import com.ddf.vodsystem.entities.Job;
|
||||||
|
import com.ddf.vodsystem.entities.JobStatus;
|
||||||
import com.ddf.vodsystem.exceptions.JobNotFound;
|
import com.ddf.vodsystem.exceptions.JobNotFound;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -36,6 +37,10 @@ public class EditService {
|
|||||||
throw new JobNotFound(uuid);
|
throw new JobNotFound(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (job.getStatus() == JobStatus.FINISHED) {
|
||||||
|
return 1f;
|
||||||
|
}
|
||||||
|
|
||||||
return job.getProgress();
|
return job.getProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user