A Python-based Video Editing Automation with Motion Detection using OpenCV and FFMPEG (MoviePy)
Ref: PyImageSearch awesome blog post on Motion Detection
- Working on different approach to automate Video Editing check here
- combo_creator: Creates a single video by combining multiple videos from a single folder
- vea: main directory that performs video editing based on motion activity.
- Install ffmpeg, required for video trimming
- Install all the requirements
$ pip3 install -r requirements.txt
- You are ready to roll.
The project starts by taking an input video file, reads it frame by frame and then resizes the frame to 500px width to reduce the processing, then making the image grayscale to add up more ease.
Then using OpenCV's diff to calculate the difference between the frames and thresholding the frame with required value, 25 suggested. Then calculating whether the threshold value changes and then detecting motion. Once, motion is detected calculating the time at it occurred. timeOccurred = frameNumber / fps # this will give us the time.
Store the startTime and endTime of the motion and then make cuts to the video starting from the startTime to the endTime using the FFMPEG tool. Storing the video to the file directory specified. Since only the processing of video is carried out, it is much faster.
The video reading is done in the thread in the VideoGet file which improves reading by *2 the normal way.
If any problem occurs, regarding the code or libraries, you may raise an issue on GitHub. Thank You!