

An Algorithm to Extract Looping GIFs from Videos - StylifyYourBlog
http://zulko.github.io/blog/2015/02/01/extracting-perfectly-looping-gifs-from-videos-with-python-and-moviepy/

======
leni536
_We will say that a video segment loops well when its first and last video
frames are very similar._

It's a reasonable approximation. However really perfect loops have not only
matching positions of the objects but perfect speeds too. I would calculate
optical flows and compare them at the first and the last frames too and
somehow put it into the distance function.

One example: this algorithm would find the half period of a pendulum perfectly
loop. Taking optical flows into account would fix this.

~~~
kazinator
Yes. For instance, suppose a point-like object is moving on a flat plane, in a
repeating figure eight path. The ideal repetition unit is one cycle of the
entire figure eight. But by the frame similarity heuristic, we will find that
the cross in the figure eight creates two identical positions which give rise
to a half-cycle of the figure eight also being considered viable. In this half
cycle, the point abruptly changes direction at the cusp of a tear-drop path.

------
mxfh
some prior research on this:

\---

 _Loop Findr_ by Collin Burger

[http://loopfindr.tumblr.com/](http://loopfindr.tumblr.com/)

[http://golancourses.net/2014/collin/05/12/loop-
findr/](http://golancourses.net/2014/collin/05/12/loop-findr/)

[https://github.com/cyburgee/loopFindr](https://github.com/cyburgee/loopFindr)

\---

Microsoft Research: _Automated video looping with progressive dynamism_ (2013)

[http://research.microsoft.com/en-
us/um/people/hoppe/proj/vid...](http://research.microsoft.com/en-
us/um/people/hoppe/proj/videoloops/)

[http://research.microsoft.com/pubs/196137/videoloops.pdf](http://research.microsoft.com/pubs/196137/videoloops.pdf)

[http://research.microsoft.com/en-
us/downloads/d02f3198-7896-...](http://research.microsoft.com/en-
us/downloads/d02f3198-7896-45eb-89e8-5a75859b67c8/)

~~~
FraKtus
The automated video looping paper is a fascinating one… much better … however
it's patented. Anybody knows what is the position of Microsoft about the
patents they own and describe in their research paper ?

~~~
NicoJuicy
You could try contacting them through Twitter about that

~~~
FraKtus
I have done that, their email is on their papers … no reply

------
comboy
Very cool concept and article.

You may also notice that many of these looping gifs are done in much simpler
way by just playing part of a video and then playing it in reverse.

~~~
rnhmjoj
So you could just check if the frame _i_ is similar to the frame _n-i_?

~~~
jessaustin
The idea is that frame 0 is similar to frame 0, and also that frame _n_ is
similar to frame _n_. (The resulting gif is _2n - 2_ frames long.)

~~~
loco5niner
I'm missing something. I don't really understand the first part of what you
said...

~~~
tokenizerrr
You just play it normally once, then in reverse. Then it loops around.

------
ZoFreX
I assume something has broken, but this article makes no sense to me. It's
full of sentences like:

"If is very similar to , and is different from , then we do not need to
compute to know that and are also very different."

~~~
rnhmjoj
It uses MathJax to render LaTeX. Probably you have blocked the script or it's
not loaded.

------
Animats
With a better, faster algorithm, probably with some help from a GPU, this
could become a new app. There's already
"[http://loopc.am/"](http://loopc.am/"), but it's not as good. Then cash out
by selling out to Instagram. Also use to jazz up real estate ads.

------
xxxyy
Isn't this just k-NN? I mean: one can reduce this problem to k-NN by first
loading the database with all video frames, and then performing queries using
frame 0, frame 1, etc.

There are good tree algorithms[0] and implementations[1][2] for executing k-NN
queries. These implementations also exploit the properties of the triangle
inequality.

[0]
[http://en.wikipedia.org/wiki/Ball_tree](http://en.wikipedia.org/wiki/Ball_tree)

[1]
[http://mlpack.org/doxygen.php?doc=nstutorial.html](http://mlpack.org/doxygen.php?doc=nstutorial.html)

[2] [http://scikit-
learn.org/stable/modules/neighbors.html#neighb...](http://scikit-
learn.org/stable/modules/neighbors.html#neighbors)

------
baxter001
Slightly misleading to say the summed colour value difference between the
frames a distance that's analogous to a geometric distance, geometric distance
measures on data with high numbers of dimensions becomes useless, as the
dimensionality increases the difference between 'near' and 'far' tends towards
zero.

