In this tutorial, we will be looking at how to save a frame from a video using Python. For this tutorial, we will be using the moviepy python library for our video processing and imageio for the image processing. To begin we first need to install moviepy and imageio, if you have python installed on your computer then run the command below to install the above mentioned modules.
pip3 install moviepy
pip3 install imageio
After installing the module create a file called app.py, this is where we will insert our code as shown below.
from moviepy.editor import VideoFileClip
import imageio
video_path = 'argentina.mp4'
final_screenshot = "screenshot.jpg"
# Create a VideoFileClip object
video = VideoFileClip(video_path)
t = 13# Time (in seconds) at which to capture the screenshot
# Get the frame at the specified time
frame = video.get_frame(t)
# Save the frame as an image
imageio.imwrite(final_screenshot,frame) # Replace 'screenshot.jpg' with your desired filename and extension
The above code first takes the path of the video and then we take the time at which to take the screenshot and we then later save the image.
Here is the original video, here.
Here is a screenshot from the processed video.
There you have it, Thanks for reading. Happy Coding.