RENAME ClipConfig entity to VideoMetadata

This commit is contained in:
2025-05-20 12:07:25 +02:00
parent e7466800ae
commit b09577fc81
6 changed files with 25 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
package com.ddf.vodsystem.controllers; package com.ddf.vodsystem.controllers;
import com.ddf.vodsystem.entities.ClipConfig; import com.ddf.vodsystem.entities.VideoMetadata;
import com.ddf.vodsystem.services.EditService; import com.ddf.vodsystem.services.EditService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@@ -18,8 +18,8 @@ public class EditController {
} }
@PostMapping("edit/{uuid}") @PostMapping("edit/{uuid}")
public ResponseEntity<String> edit(@PathVariable("uuid") String uuid, @ModelAttribute ClipConfig clipConfig) { public ResponseEntity<String> edit(@PathVariable("uuid") String uuid, @ModelAttribute VideoMetadata videoMetadata) {
editService.edit(uuid, clipConfig); editService.edit(uuid, videoMetadata);
return new ResponseEntity<>(uuid, HttpStatus.OK); return new ResponseEntity<>(uuid, HttpStatus.OK);
} }

View File

@@ -4,14 +4,11 @@ import com.ddf.vodsystem.services.UploadService;
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;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@RestController @RestController
@RequestMapping("api/v1/") @RequestMapping("api/v1/upload")
public class UploadController { public class UploadController {
private final UploadService uploadService; private final UploadService uploadService;
@@ -21,7 +18,7 @@ public class UploadController {
this.uploadService = uploadService; this.uploadService = uploadService;
} }
@PostMapping("/upload") @PostMapping("/")
public ResponseEntity<String> uploadVideo(@RequestParam("file") MultipartFile file) { public ResponseEntity<String> uploadVideo(@RequestParam("file") MultipartFile file) {
String uuid = uploadService.upload(file); String uuid = uploadService.upload(file);

View File

@@ -15,7 +15,7 @@ public class Job {
private File outputFile; private File outputFile;
// configs // configs
private ClipConfig clipConfig; private VideoMetadata videoMetadata;
// job status // job status
private JobStatus status = JobStatus.NOT_READY; private JobStatus status = JobStatus.NOT_READY;

View File

@@ -3,7 +3,7 @@ package com.ddf.vodsystem.entities;
import lombok.Data; import lombok.Data;
@Data @Data
public class ClipConfig { public class VideoMetadata {
private Float startPoint; private Float startPoint;
private Float endPoint; private Float endPoint;
private Float fps; private Float fps;

View File

@@ -1,6 +1,6 @@
package com.ddf.vodsystem.services; package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.ClipConfig; import com.ddf.vodsystem.entities.VideoMetadata;
import com.ddf.vodsystem.entities.JobStatus; import com.ddf.vodsystem.entities.JobStatus;
import com.ddf.vodsystem.entities.Job; import com.ddf.vodsystem.entities.Job;
@@ -84,19 +84,19 @@ public class CompressionService {
} }
} }
private ProcessBuilder buildCommand(File inputFile, File outputFile, ClipConfig clipConfig) { private ProcessBuilder buildCommand(File inputFile, File outputFile, VideoMetadata videoMetadata) {
ArrayList<String> command = new ArrayList<>(); ArrayList<String> command = new ArrayList<>();
command.add("ffmpeg"); command.add("ffmpeg");
command.add("-progress"); command.add("-progress");
command.add("pipe:1"); command.add("pipe:1");
command.add("-y"); command.add("-y");
Float length = clipConfig.getEndPoint() - clipConfig.getStartPoint(); Float length = videoMetadata.getEndPoint() - videoMetadata.getStartPoint();
buildInputs(command, inputFile, clipConfig.getStartPoint(), clipConfig.getEndPoint()); buildInputs(command, inputFile, videoMetadata.getStartPoint(), videoMetadata.getEndPoint());
buildFilters(command, clipConfig.getFps(), clipConfig.getWidth(), clipConfig.getHeight()); buildFilters(command, videoMetadata.getFps(), videoMetadata.getWidth(), videoMetadata.getHeight());
if (clipConfig.getFileSize() != null) { if (videoMetadata.getFileSize() != null) {
buildBitrate(command, length, clipConfig.getFileSize()); buildBitrate(command, length, videoMetadata.getFileSize());
} }
// Output file // Output file
@@ -109,12 +109,12 @@ public class CompressionService {
public void run(Job job) throws IOException, InterruptedException { public void run(Job job) throws IOException, InterruptedException {
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.getVideoMetadata());
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.getVideoMetadata().getEndPoint() - job.getVideoMetadata().getStartPoint();
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {

View File

@@ -1,6 +1,6 @@
package com.ddf.vodsystem.services; package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.ClipConfig; import com.ddf.vodsystem.entities.VideoMetadata;
import com.ddf.vodsystem.entities.Job; import com.ddf.vodsystem.entities.Job;
import com.ddf.vodsystem.entities.JobStatus; import com.ddf.vodsystem.entities.JobStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -13,10 +13,10 @@ public class EditService {
this.jobService = jobService; this.jobService = jobService;
} }
public void edit(String uuid, ClipConfig clipConfig) { public void edit(String uuid, VideoMetadata videoMetadata) {
Job job = jobService.getJob(uuid); Job job = jobService.getJob(uuid);
validateClipConfig(clipConfig); validateClipConfig(videoMetadata);
job.setClipConfig(clipConfig); job.setVideoMetadata(videoMetadata);
} }
public void process(String uuid) { public void process(String uuid) {
@@ -33,10 +33,10 @@ public class EditService {
return job.getProgress(); return job.getProgress();
} }
private void validateClipConfig(ClipConfig clipConfig) { private void validateClipConfig(VideoMetadata videoMetadata) {
Float start = clipConfig.getStartPoint(); Float start = videoMetadata.getStartPoint();
Float end = clipConfig.getEndPoint(); Float end = videoMetadata.getEndPoint();
Float fileSize = clipConfig.getFileSize(); Float fileSize = videoMetadata.getFileSize();
if (start != null && start < 0) { if (start != null && start < 0) {
throw new IllegalArgumentException("Start point cannot be negative"); throw new IllegalArgumentException("Start point cannot be negative");