RENAME VideoMetadata to ClipOptions and update related references
This commit is contained in:
@@ -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,16 +158,16 @@ public class ClipService {
|
||||
return user.get().getId().equals(clip.getUser().getId());
|
||||
}
|
||||
|
||||
private void persistClip(VideoMetadata videoMetadata,
|
||||
User user,
|
||||
File tempFile,
|
||||
String fileName) {
|
||||
private void persistClip(ClipOptions clipOptions,
|
||||
User user,
|
||||
File tempFile,
|
||||
String fileName) {
|
||||
// Move clip from temp to output directory
|
||||
File clipFile = directoryService.getUserClipsFile(user.getId(), fileName);
|
||||
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());
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user