Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Authored by Souvik Mandal, Ph.D.

Project Leader & Instructor, Computational Behavioral Sciences, LS100, FAS, Harvard University | Linkedin ID: souvik-mandal-phd


Last updated: 2026-07-03

Open in Colab Open in GitHub Codespaces

This notebook processes all video files in a given directory and creates new videos where every other frame is skipped, while preserving the original video duration.

Packages Used

1. os

  • Lets us interact with the file system

  • We use it to:

    • Loop through files in a directory

    • Build input/output file paths

    • Check file extensions

2. cv2 (OpenCV)

  • A computer vision library for reading, writing, and manipulating videos and images

  • We use it to:

    • Open each video file

    • Read frames one by one

    • Resize frames

    • Write output videos with modified frames

3. tqdm (optional but recommended)

  • Creates progress bars

  • Makes it easier to see the processing progress for each video

Output Format

For an input file like: walking.mp4 The output file will be: walking_FrameReduced.mp4 in the same directory, and the video will keep its original duration even though half the frames are removed.


How We Keep the Original Duration

If we skip every other frame, we effectively output half the frames.
To keep the video length the same, we also halve the FPS when writing the output video.

Example:

  • Input video: 120 FPS, 600 frames → 20 seconds

  • Output video: 60 FPS, 300 frames → still 20 seconds

This preserves video timing.


Make the Python Function

RUN THE FUNCTION BELOW