REFACTOR to be more modular
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.ddf.vodsystem.controllers;
|
||||
|
||||
import com.ddf.vodsystem.entities.EditDTO;
|
||||
import com.ddf.vodsystem.entities.ClipConfig;
|
||||
import com.ddf.vodsystem.services.EditService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -17,8 +17,8 @@ public class EditController {
|
||||
}
|
||||
|
||||
@PostMapping("edit/{uuid}")
|
||||
public ResponseEntity<String> edit(@PathVariable("uuid") String uuid, @ModelAttribute EditDTO editDTO) {
|
||||
editService.edit(uuid, editDTO);
|
||||
public ResponseEntity<String> edit(@PathVariable("uuid") String uuid, @ModelAttribute ClipConfig clipConfig) {
|
||||
editService.edit(uuid, clipConfig);
|
||||
return new ResponseEntity<>(uuid, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.ddf.vodsystem.entities;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EditDTO {
|
||||
public class ClipConfig {
|
||||
private Float startPoint;
|
||||
private Float endPoint;
|
||||
private Float fps;
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ddf.vodsystem.services;
|
||||
|
||||
import com.ddf.vodsystem.entities.ClipConfig;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -27,17 +28,14 @@ public class CompressionService {
|
||||
@Getter @Setter
|
||||
private File outputFile;
|
||||
@Getter @Setter
|
||||
private Float startPoint;
|
||||
@Getter @Setter
|
||||
private Float endPoint;
|
||||
@Getter @Setter
|
||||
private Integer width;
|
||||
@Getter @Setter
|
||||
private Integer height;
|
||||
@Getter @Setter
|
||||
private Float fps;
|
||||
@Getter @Setter
|
||||
private Float fileSize;
|
||||
private ClipConfig clipConfig;
|
||||
|
||||
private final Float startPoint;
|
||||
private final Float endPoint;
|
||||
private final Integer width;
|
||||
private final Integer height;
|
||||
private final Float fps;
|
||||
private final Float fileSize;
|
||||
|
||||
private static final float AUDIO_RATIO = 0.15f;
|
||||
private static final float MAX_AUDIO_BITRATE = 128f;
|
||||
@@ -46,7 +44,7 @@ public class CompressionService {
|
||||
private Pattern timePattern = Pattern.compile("time=([\\d:.]+)");
|
||||
private long out_time_ms;
|
||||
|
||||
public CompressionService(File file, File output) {
|
||||
public CompressionService(File file, File output, ClipConfig clipConfig) {
|
||||
command = new ArrayList<>();
|
||||
command.add("ffmpeg");
|
||||
command.add("-progress");
|
||||
@@ -55,15 +53,16 @@ public class CompressionService {
|
||||
|
||||
this.inputFile = file;
|
||||
this.outputFile = output;
|
||||
this.clipConfig = clipConfig;
|
||||
this.startPoint = clipConfig.getStartPoint();
|
||||
this.endPoint = clipConfig.getEndPoint();
|
||||
this.fps = clipConfig.getFps();
|
||||
this.fileSize = clipConfig.getFileSize();
|
||||
this.width = clipConfig.getWidth();
|
||||
this.height = clipConfig.getHeight();
|
||||
|
||||
}
|
||||
|
||||
public void setResolution(Integer width, Integer height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
private void buildFilters() {
|
||||
List<String> filters = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.ddf.vodsystem.services;
|
||||
|
||||
import com.ddf.vodsystem.entities.EditDTO;
|
||||
import com.ddf.vodsystem.entities.Job;
|
||||
import com.ddf.vodsystem.entities.ClipConfig;
|
||||
import com.ddf.vodsystem.tools.Job;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@@ -12,40 +12,18 @@ public class EditService {
|
||||
this.jobService = jobService;
|
||||
}
|
||||
|
||||
public void edit(String uuid, EditDTO editDTO) {
|
||||
public void edit(String uuid, ClipConfig clipConfig) {
|
||||
Job job = jobService.get(uuid);
|
||||
|
||||
if (editDTO.getStartPoint() != null) {
|
||||
if (editDTO.getStartPoint() < 0) {
|
||||
if (clipConfig.getStartPoint() != null) {
|
||||
if (clipConfig.getStartPoint() < 0) {
|
||||
throw new IllegalArgumentException("Start point cannot be negative");
|
||||
}
|
||||
|
||||
job.setStartPoint(editDTO.getStartPoint());
|
||||
}
|
||||
|
||||
if (editDTO.getEndPoint() != null) {
|
||||
job.setEndPoint(editDTO.getEndPoint());
|
||||
}
|
||||
job.setClipConfig(clipConfig);
|
||||
|
||||
if (editDTO.getFps() != null) {
|
||||
job.setFps(editDTO.getFps());
|
||||
}
|
||||
|
||||
if (editDTO.getWidth() != null) {
|
||||
job.setWidth(editDTO.getWidth());
|
||||
}
|
||||
|
||||
if (editDTO.getHeight() != null) {
|
||||
job.setHeight(editDTO.getHeight());
|
||||
}
|
||||
|
||||
if (editDTO.getFileSize() != null) {
|
||||
if (editDTO.getFileSize() < 0) {
|
||||
throw new IllegalArgumentException("File size cannot be negative");
|
||||
}
|
||||
|
||||
job.setFileSize(editDTO.getFileSize());
|
||||
}
|
||||
}
|
||||
|
||||
public void jobReady(String uuid) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.ddf.vodsystem.services;
|
||||
|
||||
import com.ddf.vodsystem.entities.Job;
|
||||
import com.ddf.vodsystem.tools.Job;
|
||||
import com.ddf.vodsystem.entities.JobStatus;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -12,7 +12,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
@Service
|
||||
class JobService {
|
||||
public class JobService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(JobService.class);
|
||||
private final HashMap<String, Job> jobs = new HashMap<>();
|
||||
private final LinkedList<Job> jobQueue = new LinkedList<>();
|
||||
@@ -39,7 +39,7 @@ class JobService {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void startProcessingLoop() {
|
||||
private void startProcessingLoop() {
|
||||
Thread thread = new Thread(() -> {
|
||||
while (true) {
|
||||
if (!jobQueue.isEmpty()) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.ddf.vodsystem.services;
|
||||
|
||||
import com.ddf.vodsystem.entities.Job;
|
||||
import com.ddf.vodsystem.tools.Job;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.ddf.vodsystem.entities;
|
||||
package com.ddf.vodsystem.tools;
|
||||
|
||||
import com.ddf.vodsystem.entities.ClipConfig;
|
||||
import com.ddf.vodsystem.entities.JobStatus;
|
||||
import com.ddf.vodsystem.services.CompressionService;
|
||||
import lombok.Data;
|
||||
import java.io.File;
|
||||
@@ -16,12 +18,7 @@ public class Job implements Runnable {
|
||||
private File file;
|
||||
|
||||
// configs
|
||||
private Float startPoint;
|
||||
private Float endPoint;
|
||||
private Float fps;
|
||||
private Integer width;
|
||||
private Integer height;
|
||||
private Float fileSize;
|
||||
private ClipConfig clipConfig;
|
||||
|
||||
// job status
|
||||
private JobStatus status = JobStatus.PENDING;
|
||||
@@ -37,13 +34,7 @@ public class Job implements Runnable {
|
||||
logger.info("Job {} started", uuid);
|
||||
this.status = JobStatus.RUNNING;
|
||||
|
||||
CompressionService f = new CompressionService(file, new File("output.mp4"));
|
||||
f.setStartPoint(startPoint);
|
||||
f.setEndPoint(endPoint);
|
||||
f.setFps(fps);
|
||||
f.setWidth(width);
|
||||
f.setHeight(height);
|
||||
f.setFileSize(fileSize);
|
||||
CompressionService f = new CompressionService(file, new File("output.mp4"), clipConfig);
|
||||
|
||||
try {
|
||||
f.run();
|
||||
Reference in New Issue
Block a user