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

@@ -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()));
}
}