RENAME VideoMetadata to ClipOptions and update related references

This commit is contained in:
2025-08-19 14:56:50 +02:00
parent 85c9d4348c
commit 9ebf69a9e7
11 changed files with 65 additions and 68 deletions

View File

@@ -12,6 +12,6 @@ post {
body:form-urlencoded {
startPoint: 10
endPoint: 40
duration: 40
title: best possible title
}

View File

@@ -1,7 +1,7 @@
package com.ddf.vodsystem.controllers;
import com.ddf.vodsystem.dto.JobStatus;
import com.ddf.vodsystem.dto.VideoMetadata;
import com.ddf.vodsystem.dto.ClipOptions;
import com.ddf.vodsystem.services.EditService;
import com.ddf.vodsystem.dto.APIResponse;
import org.springframework.http.ResponseEntity;
@@ -19,8 +19,8 @@ public class EditController {
}
@PostMapping("edit/{uuid}")
public ResponseEntity<APIResponse<Void>> edit(@PathVariable("uuid") String uuid, @ModelAttribute VideoMetadata videoMetadata) {
editService.edit(uuid, videoMetadata);
public ResponseEntity<APIResponse<Void>> edit(@PathVariable("uuid") String uuid, @ModelAttribute ClipOptions clipOptions) {
editService.edit(uuid, clipOptions);
return ResponseEntity.ok(new APIResponse<>(SUCCESS, "Editing started for UUID: " + uuid, null));
}

View File

@@ -1,6 +1,6 @@
package com.ddf.vodsystem.controllers;
import com.ddf.vodsystem.dto.VideoMetadata;
import com.ddf.vodsystem.dto.ClipOptions;
import com.ddf.vodsystem.dto.APIResponse;
import com.ddf.vodsystem.services.JobService;
import org.springframework.http.HttpStatus;
@@ -20,8 +20,8 @@ public class MetadataController {
}
@GetMapping("/original/{uuid}")
public ResponseEntity<APIResponse<VideoMetadata>> getMetadata(@PathVariable String uuid) {
VideoMetadata originalMetadata = jobService.getJob(uuid).getInputVideoMetadata();
public ResponseEntity<APIResponse<ClipOptions>> getMetadata(@PathVariable String uuid) {
ClipOptions originalMetadata = jobService.getJob(uuid).getInputClipOptions();
if (originalMetadata == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
@@ -33,8 +33,8 @@ public class MetadataController {
}
@GetMapping("/converted/{uuid}")
public ResponseEntity<APIResponse<VideoMetadata>> getConvertedMetadata(@PathVariable String uuid) {
VideoMetadata convertedMetadata = jobService.getJob(uuid).getOutputVideoMetadata();
public ResponseEntity<APIResponse<ClipOptions>> getConvertedMetadata(@PathVariable String uuid) {
ClipOptions convertedMetadata = jobService.getJob(uuid).getOutputClipOptions();
if (convertedMetadata == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)

View File

@@ -3,11 +3,11 @@ package com.ddf.vodsystem.dto;
import lombok.Data;
@Data
public class VideoMetadata {
public class ClipOptions {
private String title;
private String description;
private Float startPoint;
private Float endPoint;
private Float duration;
private Float fps;
private Integer width;
private Integer height;

View File

@@ -10,8 +10,8 @@ public class Job {
private File outputFile;
// configs
private VideoMetadata inputVideoMetadata;
private VideoMetadata outputVideoMetadata = new VideoMetadata();
private ClipOptions inputClipOptions;
private ClipOptions outputClipOptions = new ClipOptions();
// job status
private JobStatus status = new JobStatus();
@@ -19,10 +19,10 @@ public class Job {
public Job(String uuid,
File inputFile,
File outputFile,
VideoMetadata inputVideoMetadata) {
ClipOptions inputClipOptions) {
this.uuid = uuid;
this.inputFile = inputFile;
this.outputFile = outputFile;
this.inputVideoMetadata = inputVideoMetadata;
this.inputClipOptions = inputClipOptions;
}
}

View File

@@ -1,7 +1,7 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.dto.ProgressTracker;
import com.ddf.vodsystem.dto.VideoMetadata;
import com.ddf.vodsystem.dto.ClipOptions;
import com.ddf.vodsystem.entities.*;
import java.io.File;
@@ -60,8 +60,8 @@ public class ClipService {
* @throws IOException if an I/O error occurs during file processing.
* @throws InterruptedException if the thread is interrupted during processing.
*/
public void create(VideoMetadata inputMetadata,
VideoMetadata outputMetadata,
public void create(ClipOptions inputMetadata,
ClipOptions outputMetadata,
File inputFile,
File outputFile,
ProgressTracker progress)
@@ -158,7 +158,7 @@ public class ClipService {
return user.get().getId().equals(clip.getUser().getId());
}
private void persistClip(VideoMetadata videoMetadata,
private void persistClip(ClipOptions clipOptions,
User user,
File tempFile,
String fileName) {
@@ -167,7 +167,7 @@ public class ClipService {
File thumbnailFile = directoryService.getUserThumbnailsFile(user.getId(), fileName + ".png");
directoryService.cutFile(tempFile, clipFile);
VideoMetadata clipMetadata;
ClipOptions clipMetadata;
try {
clipMetadata = metadataService.getVideoMetadata(clipFile).get();
} catch (InterruptedException | ExecutionException e) {
@@ -186,13 +186,13 @@ public class ClipService {
// Save clip to database
Clip clip = new Clip();
clip.setUser(user);
clip.setTitle(videoMetadata.getTitle() != null ? videoMetadata.getTitle() : "Untitled Clip");
clip.setDescription(videoMetadata.getDescription() != null ? videoMetadata.getDescription() : "");
clip.setTitle(clipOptions.getTitle() != null ? clipOptions.getTitle() : "Untitled Clip");
clip.setDescription(clipOptions.getDescription() != null ? clipOptions.getDescription() : "");
clip.setCreatedAt(LocalDateTime.now());
clip.setWidth(clipMetadata.getWidth());
clip.setHeight(clipMetadata.getHeight());
clip.setFps(clipMetadata.getFps());
clip.setDuration(clipMetadata.getEndPoint() - clipMetadata.getStartPoint());
clip.setDuration(clipMetadata.getDuration() - clipMetadata.getStartPoint());
clip.setFileSize(clipMetadata.getFileSize());
clip.setVideoPath(clipFile.getPath());
clip.setThumbnailPath(thumbnailFile.getPath());

View File

@@ -1,7 +1,7 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.dto.JobStatus;
import com.ddf.vodsystem.dto.VideoMetadata;
import com.ddf.vodsystem.dto.ClipOptions;
import com.ddf.vodsystem.dto.Job;
import org.springframework.stereotype.Service;
@@ -14,10 +14,10 @@ public class EditService {
this.jobService = jobService;
}
public void edit(String uuid, VideoMetadata videoMetadata) {
public void edit(String uuid, ClipOptions clipOptions) {
Job job = jobService.getJob(uuid);
validateClipConfig(videoMetadata);
job.setOutputVideoMetadata(videoMetadata);
validateClipConfig(clipOptions);
job.setOutputClipOptions(clipOptions);
}
public void process(String uuid) {
@@ -35,13 +35,13 @@ public class EditService {
return job.getStatus();
}
private void validateClipConfig(VideoMetadata videoMetadata) {
Float start = videoMetadata.getStartPoint();
Float end = videoMetadata.getEndPoint();
Float fileSize = videoMetadata.getFileSize();
Integer width = videoMetadata.getWidth();
Integer height = videoMetadata.getHeight();
Float fps = videoMetadata.getFps();
private void validateClipConfig(ClipOptions clipOptions) {
Float start = clipOptions.getStartPoint();
Float end = clipOptions.getDuration();
Float fileSize = clipOptions.getFileSize();
Integer width = clipOptions.getWidth();
Integer height = clipOptions.getHeight();
Float fps = clipOptions.getFps();
if (start != null && start < 0) {
throw new IllegalArgumentException("Start point cannot be negative");

View File

@@ -72,7 +72,7 @@ public class JobService {
tempFile,
job.getInputFile(),
job.getStatus().getConversion(),
job.getInputVideoMetadata().getEndPoint())
job.getInputClipOptions().getDuration())
.thenRun(() -> {
job.getStatus().getConversion().markComplete();
directoryService.deleteFile(tempFile);
@@ -94,8 +94,8 @@ public class JobService {
try {
clipService.create(
job.getInputVideoMetadata(),
job.getOutputVideoMetadata(),
job.getInputClipOptions(),
job.getOutputClipOptions(),
job.getInputFile(),
job.getOutputFile(),
job.getStatus().getProcess()

View File

@@ -1,7 +1,7 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.dto.Job;
import com.ddf.vodsystem.dto.VideoMetadata;
import com.ddf.vodsystem.dto.ClipOptions;
import com.ddf.vodsystem.exceptions.FFMPEGException;
import com.ddf.vodsystem.services.media.MetadataService;
import org.springframework.stereotype.Service;
@@ -46,8 +46,8 @@ public class UploadService {
// add job
logger.info("Uploaded file and creating job with UUID: {}", uuid);
VideoMetadata videoMetadata = getMetadataWithTimeout(inputFile);
Job job = new Job(uuid, inputFile, outputFile, videoMetadata);
ClipOptions clipOptions = getMetadataWithTimeout(inputFile);
Job job = new Job(uuid, inputFile, outputFile, clipOptions);
jobService.add(job);
return uuid;
@@ -61,7 +61,7 @@ public class UploadService {
return Base64.getUrlEncoder().withoutPadding().encodeToString(bb.array());
}
private VideoMetadata getMetadataWithTimeout(File file) {
private ClipOptions getMetadataWithTimeout(File file) {
try {
return metadataService.getVideoMetadata(file).get(5, TimeUnit.SECONDS);
} catch (ExecutionException | TimeoutException | InterruptedException e) {

View File

@@ -2,7 +2,7 @@ package com.ddf.vodsystem.services.media;
import com.ddf.vodsystem.dto.CommandOutput;
import com.ddf.vodsystem.dto.ProgressTracker;
import com.ddf.vodsystem.dto.VideoMetadata;
import com.ddf.vodsystem.dto.ClipOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
@@ -28,15 +28,13 @@ public class CompressionService {
@Async("ffmpegTaskExecutor")
public CompletableFuture<CommandOutput> compress(File inputFile,
File outputFile,
VideoMetadata videoMetadata,
ClipOptions clipOptions,
ProgressTracker progress
) throws IOException, InterruptedException {
logger.info("Compressing video from {} to {}", inputFile.getAbsolutePath(), outputFile.getAbsolutePath());
float length = videoMetadata.getEndPoint() - videoMetadata.getStartPoint();
List<String> command = buildCommand(inputFile, outputFile, videoMetadata);
CommandOutput result = CommandRunner.run(command, line -> setProgress(line, progress, length));
List<String> command = buildCommand(inputFile, outputFile, clipOptions);
CommandOutput result = CommandRunner.run(command, line -> setProgress(line, progress, clipOptions.getDuration()));
progress.markComplete();
return CompletableFuture.completedFuture(result);
@@ -110,22 +108,21 @@ public class CompressionService {
return command;
}
private List<String> buildCommand(File inputFile, File outputFile, VideoMetadata videoMetadata) {
private List<String> buildCommand(File inputFile, File outputFile, ClipOptions clipOptions) {
List<String> command = new ArrayList<>();
command.add("ffmpeg");
command.add("-progress");
command.add("pipe:1");
command.add("-y");
Float length = videoMetadata.getEndPoint() - videoMetadata.getStartPoint();
command.addAll(buildInputs(inputFile, videoMetadata.getStartPoint(), length));
command.addAll(buildInputs(inputFile, clipOptions.getStartPoint(), clipOptions.getDuration()));
if (videoMetadata.getFps() != null || videoMetadata.getWidth() != null || videoMetadata.getHeight() != null) {
command.addAll(buildFilters(videoMetadata.getFps(), videoMetadata.getWidth(), videoMetadata.getHeight()));
if (clipOptions.getFps() != null || clipOptions.getWidth() != null || clipOptions.getHeight() != null) {
command.addAll(buildFilters(clipOptions.getFps(), clipOptions.getWidth(), clipOptions.getHeight()));
}
if (videoMetadata.getFileSize() != null) {
command.addAll(buildBitrate(length, videoMetadata.getFileSize()));
if (clipOptions.getFileSize() != null) {
command.addAll(buildBitrate(clipOptions.getDuration(), clipOptions.getFileSize()));
}
// Output file

View File

@@ -1,7 +1,7 @@
package com.ddf.vodsystem.services.media;
import com.ddf.vodsystem.dto.CommandOutput;
import com.ddf.vodsystem.dto.VideoMetadata;
import com.ddf.vodsystem.dto.ClipOptions;
import com.ddf.vodsystem.exceptions.FFMPEGException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -21,7 +21,7 @@ public class MetadataService {
private static final Logger logger = LoggerFactory.getLogger(MetadataService.class);
@Async("ffmpegTaskExecutor")
public Future<VideoMetadata> getVideoMetadata(File file) {
public Future<ClipOptions> getVideoMetadata(File file) {
logger.info("Getting metadata for file {}", file.getAbsolutePath());
List<String> command = List.of(
@@ -51,24 +51,24 @@ public class MetadataService {
}
}
public void normalizeVideoMetadata(VideoMetadata inputFileMetadata, VideoMetadata outputFileMetadata) {
public void normalizeVideoMetadata(ClipOptions inputFileMetadata, ClipOptions outputFileMetadata) {
if (outputFileMetadata.getStartPoint() == null) {
outputFileMetadata.setStartPoint(0f);
}
if (outputFileMetadata.getEndPoint() == null) {
outputFileMetadata.setEndPoint(inputFileMetadata.getEndPoint());
if (outputFileMetadata.getDuration() == null) {
outputFileMetadata.setDuration(inputFileMetadata.getDuration());
}
}
private VideoMetadata parseVideoMetadata(JsonNode node) {
VideoMetadata metadata = new VideoMetadata();
private ClipOptions parseVideoMetadata(JsonNode node) {
ClipOptions metadata = new ClipOptions();
metadata.setStartPoint(0f);
JsonNode streamNode = extractStreamNode(node);
metadata.setEndPoint(extractDuration(streamNode));
metadata.setDuration(extractDuration(streamNode));
metadata.setWidth(getWidth(streamNode));
metadata.setHeight(getHeight(streamNode));
metadata.setFps(extractFps(streamNode));
@@ -125,9 +125,9 @@ public class MetadataService {
throw new FFMPEGException("ffprobe file size missing");
}
private void extractEndPointFromFormat(VideoMetadata metadata, JsonNode formatNode) {
if (formatNode != null && formatNode.has("duration") && metadata.getEndPoint() == null) {
metadata.setEndPoint(Float.parseFloat(formatNode.get("duration").asText()));
private void extractEndPointFromFormat(ClipOptions metadata, JsonNode formatNode) {
if (formatNode != null && formatNode.has("duration") && metadata.getDuration() == null) {
metadata.setDuration(Float.parseFloat(formatNode.get("duration").asText()));
}
}