RENAME CompressionService to ClipService and update references

This commit is contained in:
2025-06-25 19:31:37 +02:00
parent f37c4fc75d
commit 6cf454c484
3 changed files with 40 additions and 40 deletions

View File

@@ -8,10 +8,10 @@ import org.springframework.security.oauth2.core.user.OAuth2User;
import java.util.Collection;
import java.util.Map;
@Getter
public class CustomOAuth2User implements OAuth2User {
private final OAuth2User oauth2User;
@Getter
private final User user;
public CustomOAuth2User(OAuth2User oauth2User, User user) {

View File

@@ -19,8 +19,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@Service
public class CompressionService {
private static final Logger logger = LoggerFactory.getLogger(CompressionService.class);
public class ClipService {
private static final Logger logger = LoggerFactory.getLogger(ClipService.class);
private static final float AUDIO_RATIO = 0.15f;
private static final float MAX_AUDIO_BITRATE = 128f;
@@ -28,6 +28,38 @@ public class CompressionService {
private final Pattern timePattern = Pattern.compile("out_time_ms=(\\d+)");
public void run(Job job) throws IOException, InterruptedException {
logger.info("FFMPEG starting...");
validateVideoMetadata(job.getInputVideoMetadata(), job.getOutputVideoMetadata());
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getOutputVideoMetadata());
Process process = pb.start();
job.setStatus(JobStatus.RUNNING);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
float length = job.getOutputVideoMetadata().getEndPoint() - job.getOutputVideoMetadata().getStartPoint();
String line;
while ((line = reader.readLine()) != null) {
logger.debug(line);
Matcher matcher = timePattern.matcher(line);
if (matcher.find()) {
Float progress = Long.parseLong(matcher.group(1))/(length*1000000);
job.setProgress(progress);
}
}
if (process.waitFor() != 0) {
job.setStatus(JobStatus.FAILED);
throw new FFMPEGException("FFMPEG process failed");
}
job.setStatus(JobStatus.FINISHED);
logger.info("FFMPEG finished");
}
private void validateVideoMetadata(VideoMetadata inputFileMetadata, VideoMetadata outputFileMetadata) {
if (outputFileMetadata.getStartPoint() == null) {
outputFileMetadata.setStartPoint(0f);
@@ -109,36 +141,4 @@ public class CompressionService {
return new ProcessBuilder(command);
}
public void run(Job job) throws IOException, InterruptedException {
logger.info("FFMPEG starting...");
validateVideoMetadata(job.getInputVideoMetadata(), job.getOutputVideoMetadata());
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getOutputVideoMetadata());
Process process = pb.start();
job.setStatus(JobStatus.RUNNING);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
float length = job.getOutputVideoMetadata().getEndPoint() - job.getOutputVideoMetadata().getStartPoint();
String line;
while ((line = reader.readLine()) != null) {
logger.debug(line);
Matcher matcher = timePattern.matcher(line);
if (matcher.find()) {
Float progress = Long.parseLong(matcher.group(1))/(length*1000000);
job.setProgress(progress);
}
}
if (process.waitFor() != 0) {
job.setStatus(JobStatus.FAILED);
throw new FFMPEGException("FFMPEG process failed");
}
job.setStatus(JobStatus.FINISHED);
logger.info("FFMPEG finished");
}
}

View File

@@ -24,14 +24,14 @@ public class JobService {
private static final Logger logger = LoggerFactory.getLogger(JobService.class);
private final ConcurrentHashMap<String, Job> jobs = new ConcurrentHashMap<>();
private final BlockingQueue<Job> jobQueue = new LinkedBlockingQueue<>();
private final CompressionService compressionService;
private final ClipService clipService;
/**
* Constructs a JobService with the given CompressionService.
* @param compressionService the compression service to use for processing jobs
* @param clipService the compression service to use for processing jobs
*/
public JobService(CompressionService compressionService) {
this.compressionService = compressionService;
public JobService(ClipService clipService) {
this.clipService = clipService;
}
/**
@@ -78,7 +78,7 @@ public class JobService {
*/
private void processJob(Job job) {
try {
compressionService.run(job);
clipService.run(job);
} catch (IOException | InterruptedException e) {
Thread.currentThread().interrupt();
logger.error("Error while running job {}", job.getUuid(), e);