How to Extract an Image from a Video using an API?

When working with video files, you sometimes need to capture a single frame of a video, for example, to take a screenshot of a particular moment. This is useful when creating thumbnails and still previews for videos. Here's how to create an image from a video using a single API request:

API Request
curl -s -X POST https://api.creatomate.com/v1/renders \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  --data-binary @- << EOF
{
  "source": {
    "output_format": "jpg",
    "snapshot_time": 1.94,
    "elements": [
      {
        "type": "video",
        "source": "https://cdn.creatomate.com/demo/bird.mp4"
      }
    ]
  }
}
EOF
Output Image

How it works: For this example, we are using the Creatomate video API. This REST API is capable of performing hundreds of different video operations. It works by sending a video task to the API in JSON format, which is then executed in the cloud.

In order to get a frame from a video, we can define a simple composition that contains a single video from a URL. When you create a composition, it scales based on the input video, but you can define the "width" and "height" attributes to generate a different image size. See the related articles below for more examples.

When you want to extract an image from the video, set the "output_format" property to "jpg" (or "png" if you want a PNG image). The "snapshot_time" tells the API to take a screenshot at the given timestamp.

If you also want to add additional elements to the image, such as a watermark logo or a title, you can do that as well. To do this, simply use the video editor to make your own custom composition. You can then use this online tool to export the corresponding JSON for use with your API request.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your application to create any kind of video – completely through code.

Related API Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free