FFmpeg low trim accuracy

2019-08-17 17:43发布

问题:

So, I'm trying to cut a 1 minute 29 seconds video into clips of 30 seconds each. The expected output is 30sec,30sec,29sec. The result is 35sec,29sec,23sec.

This is my code -

 ArrayList<String> commandList = new ArrayList<>();
            commandList.add("-ss");
            commandList.add("00:00:00");
            commandList.add("-i");
            commandList.add(videoPath);
            commandList.add("-c");
            commandList.add("copy");
            commandList.add("-f");
            commandList.add("segment");
            commandList.add("-segment_time");
            commandList.add("00:00:30");
            commandList.add(TEST.getAbsolutePath());
            String[] command  = commandList.toArray(new String[commandList.size()]);
            execFFmpegBinary(command);

Any idea what I'm doing wrong? I read somewhere that if at a particular position a keyframe doesn't exists it seeks to position of the nearest keyframe.

Any solution or guidance will help me. Thank you in advance.

回答1:

FFmpeg will start segments on keyframes. When using -codec copy there is no transcode, so It must use the existing keyframes. There is no keyframe at 30s, so it cuts at the next one.