RENAME ClipConfig entity to VideoMetadata
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.ddf.vodsystem.controllers;
|
||||
|
||||
import com.ddf.vodsystem.entities.ClipConfig;
|
||||
import com.ddf.vodsystem.entities.VideoMetadata;
|
||||
import com.ddf.vodsystem.services.EditService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -18,8 +18,8 @@ public class EditController {
|
||||
}
|
||||
|
||||
@PostMapping("edit/{uuid}")
|
||||
public ResponseEntity<String> edit(@PathVariable("uuid") String uuid, @ModelAttribute ClipConfig clipConfig) {
|
||||
editService.edit(uuid, clipConfig);
|
||||
public ResponseEntity<String> edit(@PathVariable("uuid") String uuid, @ModelAttribute VideoMetadata videoMetadata) {
|
||||
editService.edit(uuid, videoMetadata);
|
||||
return new ResponseEntity<>(uuid, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,11 @@ import com.ddf.vodsystem.services.UploadService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
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.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/v1/")
|
||||
@RequestMapping("api/v1/upload")
|
||||
public class UploadController {
|
||||
|
||||
private final UploadService uploadService;
|
||||
@@ -21,7 +18,7 @@ public class UploadController {
|
||||
this.uploadService = uploadService;
|
||||
}
|
||||
|
||||
@PostMapping("/upload")
|
||||
@PostMapping("/")
|
||||
public ResponseEntity<String> uploadVideo(@RequestParam("file") MultipartFile file) {
|
||||
String uuid = uploadService.upload(file);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Job {
|
||||
private File outputFile;
|
||||
|
||||
// configs
|
||||
private ClipConfig clipConfig;
|
||||
private VideoMetadata videoMetadata;
|
||||
|
||||
// job status
|
||||
private JobStatus status = JobStatus.NOT_READY;
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.ddf.vodsystem.entities;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ClipConfig {
|
||||
public class VideoMetadata {
|
||||
private Float startPoint;
|
||||
private Float endPoint;
|
||||
private Float fps;
|
||||
@@ -1,6 +1,6 @@
|
||||
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.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<>();
|
||||
command.add("ffmpeg");
|
||||
command.add("-progress");
|
||||
command.add("pipe:1");
|
||||
command.add("-y");
|
||||
|
||||
Float length = clipConfig.getEndPoint() - clipConfig.getStartPoint();
|
||||
buildInputs(command, inputFile, clipConfig.getStartPoint(), clipConfig.getEndPoint());
|
||||
buildFilters(command, clipConfig.getFps(), clipConfig.getWidth(), clipConfig.getHeight());
|
||||
Float length = videoMetadata.getEndPoint() - videoMetadata.getStartPoint();
|
||||
buildInputs(command, inputFile, videoMetadata.getStartPoint(), videoMetadata.getEndPoint());
|
||||
buildFilters(command, videoMetadata.getFps(), videoMetadata.getWidth(), videoMetadata.getHeight());
|
||||
|
||||
if (clipConfig.getFileSize() != null) {
|
||||
buildBitrate(command, length, clipConfig.getFileSize());
|
||||
if (videoMetadata.getFileSize() != null) {
|
||||
buildBitrate(command, length, videoMetadata.getFileSize());
|
||||
}
|
||||
|
||||
// Output file
|
||||
@@ -109,12 +109,12 @@ public class CompressionService {
|
||||
public void run(Job job) throws IOException, InterruptedException {
|
||||
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();
|
||||
job.setStatus(JobStatus.RUNNING);
|
||||
|
||||
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;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.JobStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -13,10 +13,10 @@ public class EditService {
|
||||
this.jobService = jobService;
|
||||
}
|
||||
|
||||
public void edit(String uuid, ClipConfig clipConfig) {
|
||||
public void edit(String uuid, VideoMetadata videoMetadata) {
|
||||
Job job = jobService.getJob(uuid);
|
||||
validateClipConfig(clipConfig);
|
||||
job.setClipConfig(clipConfig);
|
||||
validateClipConfig(videoMetadata);
|
||||
job.setVideoMetadata(videoMetadata);
|
||||
}
|
||||
|
||||
public void process(String uuid) {
|
||||
@@ -33,10 +33,10 @@ public class EditService {
|
||||
return job.getProgress();
|
||||
}
|
||||
|
||||
private void validateClipConfig(ClipConfig clipConfig) {
|
||||
Float start = clipConfig.getStartPoint();
|
||||
Float end = clipConfig.getEndPoint();
|
||||
Float fileSize = clipConfig.getFileSize();
|
||||
private void validateClipConfig(VideoMetadata videoMetadata) {
|
||||
Float start = videoMetadata.getStartPoint();
|
||||
Float end = videoMetadata.getEndPoint();
|
||||
Float fileSize = videoMetadata.getFileSize();
|
||||
|
||||
if (start != null && start < 0) {
|
||||
throw new IllegalArgumentException("Start point cannot be negative");
|
||||
|
||||
Reference in New Issue
Block a user