#is there a tool or program to pick a frame and find another one most similar in the same video?

59 messages · Page 1 of 1 (latest)

warm marten
#

I need this to create a looping video. No, finding the previous or next frame does not work because its a video of fire.

polar raptor
#

% being modulo not precentage

warm marten
#

programs like this?

polar raptor
#

what format is your video? have you found out how to import it into python?

warm marten
#

@polar raptor what do you think?

polar raptor
# warm marten dude literally have no idea how to put stuff through code, im only experienced i...

No worries!
if you have gotten to the point where you can atleast enter text into vs code or something, it would look like this.

import numpy as np
import cv2
frames=[]
cap=cv2.VideoCapture(“file name.mp4”)
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
frames.append(frame)
start=frames[0]
diffs=[]
for f in range(len(frames)):
diffs.append(start%frames[f])
end=np.argmin(diffs)

loop=frames[:end]
fourcc = cv2.VideoWriter_fourcc(*'XVID')
cv2.VideoWriter('fireloop.mp4', fourcc, fps, (width, height))

#

download pydroid or something lol

#

obviously you gotta replace width, height, and filename with your video dimensions and filename

warm marten
warm marten
#

anything for pc?

polar raptor
#

very easy to get set up, it's a well worn path.

warm marten
polar raptor
#

yeah it gives you autocomplete suggestions. very helpful

#

if you got anaconda you have python and the libraries I put at the top "import ___" at the top of python programs is you importing programs that help you program. Think, digging a hole with a shovel instead of your hands

warm marten
polar raptor
# warm marten so do i just create a python file?

when you attempt to run your code in vs code(little play button looking thing at the top right) it will make you see if somewhere before you can run it.

make sure your fire video is in the same folder the .py file is in

#

(I'm doing this alongside you btw)

warm marten
polar raptor
#

import matplotlib.pyplot as plt
import numpy as np
import cv2
frames=[]
fire=cv2.VideoCapture("fire.mp4")
while(fire.isOpened()):
ret, frame = fire.read()
if ret == True:
frames.append(frame)
start=frames[0]
diffs=[]
for f in range(len(frames)):
diff=start%frames[f]
plt.imshow(frame,cmap="inferno")
plt.title=(diff)
plt.pause(0.01)
plt.cla()
diffs.append(diff)
end=np.argmin(diffs)

loop=frames[:end]
fourcc = cv2.VideoWriter_fourcc(*'XVID')
cv2.VideoWriter('fireloop.mp4', fourcc, 30, (640,360))

#

this works and shows you the fire and modulo(think of as difference-between) of the first frame and the current frame

polar raptor
#

yeah essentially it's saving the first frame of the video, and every frame deciding it by the frame it is on.

#

%(modulo) is the remainder of that division

#

the higher the %, the less similar they are

warm marten
polar raptor
#

the end of the code takes all the frames from the start to the most similar frame to the start, and saves that as your loop.

logically speaking I see an emediate problem with this

#

the most similar frame to frame 1 would be frame 2

#

sooo

#

1sec

warm marten
polar raptor
#

import matplotlib.pyplot as plt
import numpy as np
import cv2
frames=[]
fire=cv2.VideoCapture("fire.mp4")
while(fire.isOpened()):
ret, frame = fire.read()
if ret == True:
frames.append(frame)
start=frames[0]
diffs=[]
for f in range(60,len(frames)):
diff=start%frames[f]
plt.imshow(frame,cmap="inferno")
plt.title=(diff)
plt.pause(0.01)
plt.cla()
diffs.append(diff)
end=np.argmin(diffs)

loop=frames[:end]
fourcc = cv2.VideoWriter_fourcc(*'XVID')
cv2.VideoWriter('fireloop.mp4', fourcc, 30, (640,360))

okay what I just did was, see where it says "for f in range(len(frames)):"

that does what it sounds like it does, " the amount of frames that are in the the entire length of the video".

I put a 60 infront of len(frames), so the counter starts at frame 60, to avoid the problem of our most-similar frame being the second one in the video

warm marten
#

does this work for any type of fps?

polar raptor
#

yeah, I just arbitrarily picked 60 frames assuming it's probably a 60 or 30fps video you're working with.

#

so 1 or 2 seconds

warm marten
#

?

#

or can i do however long

polar raptor
#

that's the beauty of libraries, I sure have no idea what wizardry goes into making python understand a video file, but whoever developed the opencv2 library did.

that's what

fire=cv2.videocapture("fire.mp4")
did. you can put whatever video file format you want in there and let the people smarter than you do the hard work

polar raptor
warm marten
#

i think about 30-40 seconds

warm marten
polar raptor
#

that will make this a bit choppy but the program is super simple so it should be fine.

polar raptor
#

and again, make sure it goes in the same folder you are putting your python file in

#

(the video)

#

import matplotlib.pyplot as plt

plt.imshow(frame,cmap="inferno")
plt.title=(diff)
plt.pause(0.01)
plt.cla()

this part is unnecessary for functionality but let's you see the frames of the video go by

#

if you wanted to be a giganerd you could do this:
plt.imshow((frame/start),cmap="inferno")
plt.title=(diff)
plt.pause(0.01)
plt.cla()

warm marten
#

hey is it okay if we bring this into the dms?

#

because i gotta go eat

polar raptor
#

with a 4k video that will probably make your computer explode but it would show you the difference between your starting frame and the current frame as the video goes along

#

yeh