diff --git a/src/main/java/com/ddf/vodsystem/controllers/EditController.java b/src/main/java/com/ddf/vodsystem/controllers/EditController.java index 76a104f..8b552de 100644 --- a/src/main/java/com/ddf/vodsystem/controllers/EditController.java +++ b/src/main/java/com/ddf/vodsystem/controllers/EditController.java @@ -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 edit(@PathVariable("uuid") String uuid, @ModelAttribute EditDTO editDTO) { - editService.edit(uuid, editDTO); + public ResponseEntity edit(@PathVariable("uuid") String uuid, @ModelAttribute ClipConfig clipConfig) { + editService.edit(uuid, clipConfig); return new ResponseEntity<>(uuid, HttpStatus.OK); } diff --git a/src/main/java/com/ddf/vodsystem/entities/EditDTO.java b/src/main/java/com/ddf/vodsystem/entities/ClipConfig.java similarity index 89% rename from src/main/java/com/ddf/vodsystem/entities/EditDTO.java rename to src/main/java/com/ddf/vodsystem/entities/ClipConfig.java index 7b644e8..522e6f8 100644 --- a/src/main/java/com/ddf/vodsystem/entities/EditDTO.java +++ b/src/main/java/com/ddf/vodsystem/entities/ClipConfig.java @@ -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; diff --git a/src/main/java/com/ddf/vodsystem/services/CompressionService.java b/src/main/java/com/ddf/vodsystem/services/CompressionService.java index d7e8650..ea4a330 100644 --- a/src/main/java/com/ddf/vodsystem/services/CompressionService.java +++ b/src/main/java/com/ddf/vodsystem/services/CompressionService.java @@ -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 filters = new ArrayList<>(); diff --git a/src/main/java/com/ddf/vodsystem/services/EditService.java b/src/main/java/com/ddf/vodsystem/services/EditService.java index 5ec23c5..7d599f6 100644 --- a/src/main/java/com/ddf/vodsystem/services/EditService.java +++ b/src/main/java/com/ddf/vodsystem/services/EditService.java @@ -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) { diff --git a/src/main/java/com/ddf/vodsystem/services/JobService.java b/src/main/java/com/ddf/vodsystem/services/JobService.java index e03e2da..9a775ee 100644 --- a/src/main/java/com/ddf/vodsystem/services/JobService.java +++ b/src/main/java/com/ddf/vodsystem/services/JobService.java @@ -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 jobs = new HashMap<>(); private final LinkedList 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()) { diff --git a/src/main/java/com/ddf/vodsystem/services/UploadService.java b/src/main/java/com/ddf/vodsystem/services/UploadService.java index 860a017..9aa4a69 100644 --- a/src/main/java/com/ddf/vodsystem/services/UploadService.java +++ b/src/main/java/com/ddf/vodsystem/services/UploadService.java @@ -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; diff --git a/src/main/java/com/ddf/vodsystem/entities/Job.java b/src/main/java/com/ddf/vodsystem/tools/Job.java similarity index 71% rename from src/main/java/com/ddf/vodsystem/entities/Job.java rename to src/main/java/com/ddf/vodsystem/tools/Job.java index 8d620f2..e841a4f 100644 --- a/src/main/java/com/ddf/vodsystem/entities/Job.java +++ b/src/main/java/com/ddf/vodsystem/tools/Job.java @@ -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();