* ADD conversion queue * ADD RemuxService for MP4 conversion * REMOVE unused conversion queue * REORGANISE Job-related classes * ADD Job stages * REVERT to old commit, using Spring Async instead * ADD asynchronous processing for video tasks * PATCH and streamline progress tracking * ADD asynchronous video processing and job restructuring * REFACTOR job service method * ADD job remux functionality * ADD remuxing endpoint * PATCH complete flag not updating in API response * ADD progress type in frontend * ADD reset functionality for job status * PATCH missing progress bar for subsequent exports * REDESIGN settings box * ADD tracking video file conversion in frontend * PATCH extension bug * REMOVE autowired decorator
47 lines
1.6 KiB
Java
47 lines
1.6 KiB
Java
package com.ddf.vodsystem.services.media;
|
|
|
|
import com.ddf.vodsystem.dto.CommandOutput;
|
|
import com.ddf.vodsystem.dto.ProgressTracker;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
@Service
|
|
public class RemuxService {
|
|
private final Pattern timePattern = Pattern.compile("out_time_ms=(\\d+)");
|
|
|
|
@Async("ffmpegTaskExecutor")
|
|
public CompletableFuture<CommandOutput> remux(File inputFile,
|
|
File outputFile,
|
|
ProgressTracker remuxProgress,
|
|
float length
|
|
) throws IOException, InterruptedException {
|
|
List<String> command = List.of(
|
|
"ffmpeg",
|
|
"-progress", "pipe:1",
|
|
"-y",
|
|
"-i", inputFile.getAbsolutePath(),
|
|
"-c:v", "h264",
|
|
"-c:a", "aac",
|
|
"-f", "mp4",
|
|
outputFile.getAbsolutePath()
|
|
);
|
|
|
|
return CompletableFuture.completedFuture(CommandRunner.run(command, line -> setProgress(line, remuxProgress, length)));
|
|
}
|
|
|
|
private void setProgress(String line, ProgressTracker progress, float length) {
|
|
Matcher matcher = timePattern.matcher(line);
|
|
if (matcher.find()) {
|
|
float timeInMs = Float.parseFloat(matcher.group(1)) / 1000000f;
|
|
progress.setProgress(timeInMs / length);
|
|
}
|
|
}
|
|
}
|