OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can I use ffmpeg to create a seamless looping gif?

  • Thread starter Thread starter DavidNyan10
  • Start date Start date
D

DavidNyan10

Guest
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:

  1. Get the first frame and save it as a PNG or something I don't know
  2. Reverse the original video
  3. 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.
  4. When a frame match is found, cut off all the frames before this matched frame.
  5. 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.
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>Steps:</p>
<ol>
<li>Get the first frame and save it as a PNG or something I don't know</li>
<li>Reverse the original video</li>
<li>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.</li>
<li>When a frame match is found, cut off all the frames before this matched frame.</li>
<li>Reverse back the video</li>
</ol>
<p>Can I achieve something like this in ffmpeg, preferably a one-liner in windows cmd?</p>
<p>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?</p>
<p>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.</p>
Continue reading...
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Ads by Eonads
Top