I got an video, which is 14059 frames long. If I use it inside my java application and put a cut into frame 369 (at least the FFmpegFrameGrabber method getFrameNumber() says so), and then I put this cut into a .file and open this one in Shotcut, the frame is 3 frames off from where the cut should be. I found out, when I this:
grabber.setFrameNumber(0);
Frame frame;
while ((frame = grabber.grabImage()) != null){
if (frame.image == null) continue;
BufferedImage wholeFrame = converter.convert(frame);
if (wholeFrame == null) continue;
System.out.print(grabber.getFrameNumber() + ", ");
}
it prints: 2, 2, 3, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, …, 2866, 2867, 2869, 2870, …, 6880, 6881, 6883, 6884, …, 10897, 10899, …
So you see, there are frames missing and some frames are duplicated. If I put the exact same video into Shotcut, and export it without any changes and do the same, it prints:
0, 1, 2, 3, 4, 5, …
So what you would normally expect. The problem is, that it’s not just different numbers, but the first frame in the original video is the same as in the expected one. Even if the frameNumber in the first frame is different, it shows the same content. But a the third frame already is one frame off from the third frame in the exported video. This changes again later. What is the problem, is there a way to check in the java code, how many frames the shotcut video would be off from the original? The same problem is already if I just set a cut inside Shotcut in the original video without exporting it: the .mlt file says the cut is on frame 366 but my code says 369 for the same content of the frame. I hope you get what I mean.
I could fix these offsets by always exporting the video without cuts in Shotcut, then applying my cuts through my code and create a new .mlt with these cuts on the exported one and then the cuts are on the correct position. But I don’t always want to wait minutes or hours to export a video before I can apply cuts through my automated code to see where my code set the cuts.