#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)
save the frame as grayscale and list the % of that frame and every other frame in the footage, return lowest % frame, start loop there.
% being modulo not precentage
very smart idea actually but how would i do this?
programs like this?
what format is your video? have you found out how to import it into python?
dude literally have no idea how to put stuff through code, im only experienced in video editing and know some ai
@polar raptor what do you think?
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
https://theailearner.com/2021/05/29/creating-gif-from-video-using-opencv-and-imageio/
here's how you would save it as a gif if you want it to loop automatically, but what I typed should Give you the most similar frames
okay ill let you know how it goes
look up visual studio code and anaconda.
very easy to get set up, it's a well worn path.
should i download the python extension?
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
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)
thank you
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
oh so is this comparing them?
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
oh so the lower the better, can i change that?
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
kk!
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
whoa
does this work for any type of fps?
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
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
yup, probably assuming you have the memory to pump some 13 gigabye 4k video file though python
lol, it is 4k but not that long
i think about 30-40 seconds
is this the only code i have to put in?
that will make this a bit choppy but the program is super simple so it should be fine.
yeah, make the name of the file and the width and hieght correct
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()