#!/usr/bin/python3 import argparse import os import cv2 def capture_and_resize_frame(video_path, capture_time=180): # Extract the base filename from the video path base_filename = os.path.splitext(os.path.basename(video_path))[0] output_image_path = f"{base_filename}_screencapture.jpg" # Open the video file video = cv2.VideoCapture(video_path) # Get the frames per second (fps) of the video fps = video.get(cv2.CAP_PROP_FPS) # Calculate the frame number for the specified capture time (180 seconds by default) frame_number = int(fps * capture_time) # Set the frame position to the capture time in the video video.set(cv2.CAP_PROP_POS_FRAMES, frame_number) # Read the frame success, frame = video.read() # Check if the frame was successfully read if success: # Save the frame as an image temporarily temp_image_path = 'temp_screencapture.jpg' cv2.imwrite(temp_image_path, frame) #print(f"Frame at {capture_time} seconds saved as {temp_image_path}") # Load the captured image for resizing image = cv2.imread(temp_image_path) # Set new dimensions new_width, new_height = 960, 540 # Resize the image resized_image = cv2.resize(image, (new_width, new_height)) # Save the resized image with the new output path cv2.imwrite(output_image_path, resized_image) print(f"Screen capture resized and saved as {output_image_path}") else: print("Failed to capture the frame, video shorter than 3 mins.") # Release the video video.release() # Remove the temporary file os.remove(temp_image_path) def main(): # Set up argument parser parser = argparse.ArgumentParser(description="Extract and resize a frame from a video.") parser.add_argument("video_path", type=str, help="Path to the video file") # Parse arguments args = parser.parse_args() # Call the capture and resize function capture_and_resize_frame(args.video_path) if __name__ == "__main__": main()