With a very simple trick you can extract the motion of a video. Uses python3 and OpenCV to compare current frame of the video to a previous frame to see where changes have been made in the frames (and any changes indicate motion).
Inspired by this video by Posy
NOTE: Recommend to only test on shorter videos (ie: not greater than 5 minutes) -- current program converts in REAL TIME
- IE: 5 hour video = at least 5 hours to convert
-
- Make sure you have python 3 download, installed and on path
-
- Use the activateVirEnv.txt to create a virtual environment
-
- Make sure you
pip install -r requirements.txt
to install all the needed packages
- Make sure you
-
- Move your target MP4 video into the same directory as the
motion_Extraction.py
file
- Move your target MP4 video into the same directory as the
-
- Run the program with the command
python motion_Extraction.py yourVideo.mp4
- you NEED to provide the video title as an argument
- Run the program with the command
-
- If you want to see the extraction overlay, type
yes
. If you do not, typeno
- If you want to see the extraction overlay, type
-
- If you just want the frame compared to the previous one, then type
PREVIOUS
. If you want a larger delay, typeCUSTOM
(you will the be prompted to enter your custom frame delay)
- If you just want the frame compared to the previous one, then type
-
- Your output will be created in a subfolder within the
OUTPUTS
folder, enjoy!
- Your output will be created in a subfolder within the
- [DONE] maybe combine the two while loops?
- [DONE] invert then immediatly overlay?
- [DONE] check pervious frame in one video then x frames back in another video (shows slower movement)
- cut videos larger than like 3 minutes into chunks of 1 minutes, store in folder [check multiprocessing attempt folder]
- then use threading to individually loop through and invert videos
- then you can paste it together at the end
- Motion Extraction tutorial (attempt...): https://youtu.be/woj4vfMLpao
- Python OpenCV – cv2.flip() method: https://www.geeksforgeeks.org/python-opencv-cv2-flip-method/
- Adding (blending) two images using OpenCV : https://docs.opencv.org/3.4/d5/dc4/tutorial_adding_images.html
- How to split a video in parts using Python?: https://stackoverflow.com/questions/65570944/how-to-split-a-video-in-parts-using-python
- multiprocessing — Process-based parallelism: https://docs.python.org/3/library/multiprocessing.html