How to Take a Screenshot From a Video Using Python

How to Take a Screenshot From a Video Using Python
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 a screenshot from the processed video.

There you have it, Thanks for reading. Happy Coding.

Leave a Comment

Your email address will not be published. Required fields are marked *