{
  "id": 23130782,
  "title": "Extract frames from a video URL in Python without downloading the file",
  "url": "https://urgent.news/2026/12/02/extract-frames-from-a-video-url-in-python-without-downloading-the-file",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-02T14:40:12.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/picdev/extract-frames-from-a-video-url-in-python-without-downloading-the-file-3cpn"
  },
  "original_language": null,
  "account": "The provided Python code demonstrates how to extract evenly spaced frames from a video file hosted on a URL without downloading the entire file. It uses the PyAV library, which directly binds the FFmpeg libraries, allowing the code to seek near the desired moment and decode only from there. This approach saves bandwidth and CPU resources compared to downloading the entire video.\n\nKey steps in the code include:\n\n1. Defining a function `open_video(url)` that opens the video container from the given URL using PyAV. It retrieves the video stream and sets threading for faster processing.\n\n2. Creating a function `frames_at(url, times)` that yields a tuple of seconds and a PIL (Python Imaging Library) image for each requested time. It seeks to the appropriate time in the video stream, skips frames with None pts, and converts the frame to an image.\n\n3. Implementing a function `evenly_spaced(url, n)` that calculates the step size between evenly spaced frames based on the total duration of the video and the desired number of frames. It returns a list of frame times.\n\n4. Opening the video container using `open_video(url)` and calculating the evenly spaced frame times using `evenly_spaced(url, 5)`.\n\n5. Iterating through the frame times and saving each frame as an image file with the corresponding timestamp.\n\n6. The `scene_cuts(url, threshold=0.075, min_gap=1.0)` function is also defined but not used in the main code snippet. It yields the start time, score, and image for each detected scene cut in the video based on a given threshold and minimum gap between cuts.\n\nThe code efficiently extracts frames from a video without downloading the entire file, utilizing PyAV's capabilities to jump to specific times and decode only the necessary frames. This technique is particularly useful when dealing with large video files, as it minimizes bandwidth usage and computational resources.",
  "summary": "The usual way to get thumbnails from a video is to download it and run ffmpeg -i video.mp4 -vf fps=1/10 out_%03d.jpg . That decodes every frame of the file to keep one in three hundred. For ten thumbnails from an hour-long recording sitting on S3, it is a lot of bandwidth and CPU for nothing. PyAV binds the FFmpeg libraries directly, so you can do what a video player does when you drag the seek…",
  "summary_source": "publisher",
  "key_points": [
    "Function openvideo(url) opens video container from URL using PyAV.",
    "Function framesat(url, times) yields frame images at specified times.",
    "Function evenlyspaced(url, n) calculates evenly spaced frame times for given number."
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}