I have an MP4 file which contains animation repeating in a loop. Let's just say, for example, a video of rain. However, when loop is turned on, the video cuts off at the wrong place and does not make a nice smooth animation. The part where it loops is obvious. It's just that the video contains more than one cycle of the loop, but not an exact integer of the full cycle.
My goal is to turn this video into a gif with a seamless loop. In other words, I want the last frame of the video to match the first frame.
My approach: I found a "Seamless loop creator" website on Google, tried it out, and it worked REALLY well. I thought all my problems have been solved. But little did I know, I've been only looking at the few seconds at the beginning and at the end of the video, not paying attention to what's in the middle. The sneaky pesky little website cuts off the video right in the middle, stitch the "seamless transition" at the beginning and end of the video, and put an ugly cross-fade in the middle where the frames don't line up. That is stupid. This of course, isn't noticable on rain videos, but on videos like a character jumping, the crossfade is very visible.
My second approach: I'd use FFMPEG to get the first frame of the video, then starting from the last frame of the video and backwards, it'd try to find a frame that matches exactly with the first frame.
Steps:
- Get the first frame and save it as a PNG or something I don't know
- Reverse the original video
- Match the image to each frame of the video in step 2. It is now easier because it's not doing it backwards frame by frame.
- When a frame match is found, cut off all the frames before this matched frame.
- Reverse back the video
Can I achieve something like this in ffmpeg, preferably a one-liner in windows cmd?
Follow-up question: Would it be better to leave the last frame the same as first frame or should I remove it? For example, when it's looping, it would repeat that exact frame two times, is that good? Or which one provides better results? And if it's better to not include the last frame (the one that matches), how would I do it in my process above?
I tried ChatGPT, expecting a ready-made code. Put it in the command prompt and lost my original video file. Had to use a recovery tool because the file was overwritten.