import cv2

# Open the video file
cap = cv2.VideoCapture('sample_video.mp4')

# Check if the video opened successfully
if not cap.isOpened():
    print("Error: Could not open video file.")
    exit()

# Loop through the video frames
while True:
    # Read a frame
    ret, frame = cap.read()

    # Break the loop if the video has ended
    if not ret:
        break

    # Process the frame (convert to grayscale)
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the processed frame
    cv2.imshow('Grayscale Frame', gray_frame)

    # Exit if the 'q' key is pressed
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release the video capture object and close windows
cap.release()
cv2.destroyAllWindows()
