REPLACE AtomicProgress with simple ProgressTracker
This commit is contained in:
19
src/main/java/com/ddf/vodsystem/dto/ProgressTracker.java
Normal file
19
src/main/java/com/ddf/vodsystem/dto/ProgressTracker.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.ddf.vodsystem.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class ProgressTracker {
|
||||||
|
private float progress;
|
||||||
|
|
||||||
|
public ProgressTracker(float initialProgress) {
|
||||||
|
this.progress = initialProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProgress(float newProgress) {
|
||||||
|
if (newProgress < 0 || newProgress > 1) {
|
||||||
|
throw new IllegalArgumentException("Progress must be between 0 and 1");
|
||||||
|
}
|
||||||
|
this.progress = newProgress;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.ddf.vodsystem.entities;
|
package com.ddf.vodsystem.entities;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
|
import com.ddf.vodsystem.dto.ProgressTracker;
|
||||||
import com.ddf.vodsystem.dto.VideoMetadata;
|
import com.ddf.vodsystem.dto.VideoMetadata;
|
||||||
import org.springframework.security.core.context.SecurityContext;
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ public class Job {
|
|||||||
|
|
||||||
// job status
|
// job status
|
||||||
private JobStatus status = JobStatus.NOT_READY;
|
private JobStatus status = JobStatus.NOT_READY;
|
||||||
private AtomicReference<Float> progress = new AtomicReference<>(0f);
|
private ProgressTracker progress = new ProgressTracker(0.0f);
|
||||||
|
|
||||||
public Job(String uuid, File inputFile, File outputFile, VideoMetadata inputVideoMetadata) {
|
public Job(String uuid, File inputFile, File outputFile, VideoMetadata inputVideoMetadata) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class EditService {
|
|||||||
return 1f;
|
return 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return job.getProgress().get();
|
return job.getProgress().getProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateClipConfig(VideoMetadata videoMetadata) {
|
private void validateClipConfig(VideoMetadata videoMetadata) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.ddf.vodsystem.services;
|
package com.ddf.vodsystem.services;
|
||||||
|
|
||||||
|
import com.ddf.vodsystem.dto.ProgressTracker;
|
||||||
import com.ddf.vodsystem.dto.VideoMetadata;
|
import com.ddf.vodsystem.dto.VideoMetadata;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -11,7 +12,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ public class FfmpegService {
|
|||||||
private static final float BITRATE_MULTIPLIER = 0.9f;
|
private static final float BITRATE_MULTIPLIER = 0.9f;
|
||||||
private final Pattern timePattern = Pattern.compile("out_time_ms=(\\d+)");
|
private final Pattern timePattern = Pattern.compile("out_time_ms=(\\d+)");
|
||||||
|
|
||||||
public void runWithProgress(File inputFile, File outputFile, VideoMetadata videoMetadata, AtomicReference<Float> progress) throws IOException, InterruptedException {
|
public void runWithProgress(File inputFile, File outputFile, VideoMetadata videoMetadata, ProgressTracker progress) throws IOException, InterruptedException {
|
||||||
logger.info("Starting FFMPEG process");
|
logger.info("Starting FFMPEG process");
|
||||||
|
|
||||||
List<String> command = buildCommand(inputFile, outputFile, videoMetadata);
|
List<String> command = buildCommand(inputFile, outputFile, videoMetadata);
|
||||||
@@ -45,7 +45,7 @@ public class FfmpegService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run(File inputFile, File outputFile, VideoMetadata videoMetadata) throws IOException, InterruptedException {
|
public void run(File inputFile, File outputFile, VideoMetadata videoMetadata) throws IOException, InterruptedException {
|
||||||
runWithProgress(inputFile, outputFile, videoMetadata, new AtomicReference<>(0f));
|
runWithProgress(inputFile, outputFile, videoMetadata, new ProgressTracker(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateThumbnail(File inputFile, File outputFile, Float timeInVideo) throws IOException, InterruptedException {
|
public void generateThumbnail(File inputFile, File outputFile, Float timeInVideo) throws IOException, InterruptedException {
|
||||||
@@ -77,7 +77,7 @@ public class FfmpegService {
|
|||||||
logger.info("Thumbnail generated successfully at {}", outputFile.getAbsolutePath());
|
logger.info("Thumbnail generated successfully at {}", outputFile.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateJobProgress(Process process, AtomicReference<Float> progress, Float length) throws IOException {
|
private void updateJobProgress(Process process, ProgressTracker progress, Float length) throws IOException {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
@@ -87,7 +87,7 @@ public class FfmpegService {
|
|||||||
|
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
Float timeInMs = Float.parseFloat(matcher.group(1)) / 1000000f;
|
Float timeInMs = Float.parseFloat(matcher.group(1)) / 1000000f;
|
||||||
progress.set(timeInMs/length);
|
progress.setProgress(timeInMs/length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user