ADD some temporary default values in VideoMetadata
This commit is contained in:
@@ -16,7 +16,7 @@ public class Job {
|
|||||||
|
|
||||||
// configs
|
// configs
|
||||||
private VideoMetadata inputVideoMetadata;
|
private VideoMetadata inputVideoMetadata;
|
||||||
private VideoMetadata outputVideoMetadata;
|
private VideoMetadata outputVideoMetadata = new VideoMetadata();
|
||||||
|
|
||||||
// job status
|
// job status
|
||||||
private JobStatus status = JobStatus.NOT_READY;
|
private JobStatus status = JobStatus.NOT_READY;
|
||||||
|
|||||||
@@ -28,6 +28,16 @@ public class CompressionService {
|
|||||||
|
|
||||||
private final Pattern timePattern = Pattern.compile("out_time_ms=(\\d+)");
|
private final Pattern timePattern = Pattern.compile("out_time_ms=(\\d+)");
|
||||||
|
|
||||||
|
private void validateVideoMetadata(VideoMetadata inputFileMetadata, VideoMetadata outputFileMetadata) {
|
||||||
|
if (outputFileMetadata.getStartPoint() == null) {
|
||||||
|
outputFileMetadata.setStartPoint(0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputFileMetadata.getEndPoint() == null) {
|
||||||
|
outputFileMetadata.setEndPoint(inputFileMetadata.getEndPoint());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void buildFilters(ArrayList<String> command, Float fps, Integer width, Integer height) {
|
private void buildFilters(ArrayList<String> command, Float fps, Integer width, Integer height) {
|
||||||
List<String> filters = new ArrayList<>();
|
List<String> filters = new ArrayList<>();
|
||||||
|
|
||||||
@@ -66,22 +76,15 @@ public class CompressionService {
|
|||||||
command.add(audioBitrate + "k");
|
command.add(audioBitrate + "k");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildInputs(ArrayList<String> command, File inputFile, Float startPoint, Float endPoint) {
|
private void buildInputs(ArrayList<String> command, File inputFile, Float startPoint, Float length) {
|
||||||
if (startPoint == null) {
|
|
||||||
startPoint = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
command.add("-ss");
|
command.add("-ss");
|
||||||
command.add(startPoint.toString());
|
command.add(startPoint.toString());
|
||||||
|
|
||||||
command.add("-i");
|
command.add("-i");
|
||||||
command.add(inputFile.getAbsolutePath());
|
command.add(inputFile.getAbsolutePath());
|
||||||
|
|
||||||
if (endPoint != null) {
|
command.add("-t");
|
||||||
float length = endPoint - startPoint;
|
command.add(Float.toString(length));
|
||||||
command.add("-t");
|
|
||||||
command.add(Float.toString(length));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProcessBuilder buildCommand(File inputFile, File outputFile, VideoMetadata videoMetadata) {
|
private ProcessBuilder buildCommand(File inputFile, File outputFile, VideoMetadata videoMetadata) {
|
||||||
@@ -92,7 +95,7 @@ public class CompressionService {
|
|||||||
command.add("-y");
|
command.add("-y");
|
||||||
|
|
||||||
Float length = videoMetadata.getEndPoint() - videoMetadata.getStartPoint();
|
Float length = videoMetadata.getEndPoint() - videoMetadata.getStartPoint();
|
||||||
buildInputs(command, inputFile, videoMetadata.getStartPoint(), videoMetadata.getEndPoint());
|
buildInputs(command, inputFile, videoMetadata.getStartPoint(), length);
|
||||||
buildFilters(command, videoMetadata.getFps(), videoMetadata.getWidth(), videoMetadata.getHeight());
|
buildFilters(command, videoMetadata.getFps(), videoMetadata.getWidth(), videoMetadata.getHeight());
|
||||||
|
|
||||||
if (videoMetadata.getFileSize() != null) {
|
if (videoMetadata.getFileSize() != null) {
|
||||||
@@ -109,6 +112,8 @@ public class CompressionService {
|
|||||||
public void run(Job job) throws IOException, InterruptedException {
|
public void run(Job job) throws IOException, InterruptedException {
|
||||||
logger.info("FFMPEG starting...");
|
logger.info("FFMPEG starting...");
|
||||||
|
|
||||||
|
validateVideoMetadata(job.getInputVideoMetadata(), job.getOutputVideoMetadata());
|
||||||
|
|
||||||
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getOutputVideoMetadata());
|
ProcessBuilder pb = buildCommand(job.getInputFile(), job.getOutputFile(), job.getOutputVideoMetadata());
|
||||||
Process process = pb.start();
|
Process process = pb.start();
|
||||||
job.setStatus(JobStatus.RUNNING);
|
job.setStatus(JobStatus.RUNNING);
|
||||||
|
|||||||
Reference in New Issue
Block a user