-1

I have a class in my java application that takes a path to a video file, then gets a new video from the source file. The resulting video must have the following characteristics: duration - 60 seconds fps - 25 throughout the video, the only selected frame of the source video is shown (staticFrameNum). the first 10 seconds of video - FADE IN (from 0% to 90%) the last 10 seconds of video - FADE OUT (from 90% to 0%)

the code is below:


int staticFrameNum = 30 //test
String variableFilter = String.format("[0:v]select='eq(n,%s)',setpts=PTS-STARTPTS[selected];[selected]loop=-1:1500,fade=in:0:250,fade=out:1250:250",
                        staticFrameNum);
String[] cmd = {
                    "ffmpeg",
                    "-i", inputFile,
                    "-vf", variableFilter,
                    "-framerate", "25",
                    "-frames:v", amountOfFrames,
                    "-an", // audio off
                    "-c:v", "libx264",
                    "-preset", "slow",
                    "-crf", "18",
                    "-threads", "4",
                    outputFile
            };

            ProcessBuilder processBuilder = new ProcessBuilder(cmd);
            processBuilder.redirectErrorStream(false);
            processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
            processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
            Process process = null;
            try {
                process = processBuilder.start();

This code works fine and returns correct video, but I'm concerned about performance.I suspect that the logic in **variableFilter ** can be changed to make this operation faster. Now it's taking too long. I will be glad to your ideas.

I tried to use another library to solve this problem - javaCV, but in this case the performance was even lower

0 Answers0