# Video to GIF & WebP Preview - Auto Best Clip, Size Target (`kantolabs/video-to-gif`) Actor

Turn video files into short looping GIF and animated WebP previews (+ optional MP4 loop and thumbnail). Auto-picks the most active, sharp, non-black seconds, or your own clip, or one preview per scene. Fits a file-size target (e.g. under 2 MB). $0.014 per preview.

- **URL**: https://apify.com/kantolabs/video-to-gif.md
- **Developed by:** [Kanto Labs](https://apify.com/kantolabs) (community)
- **Categories:** Videos, Automation, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $11.90 / 1,000 previews

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

### Video to GIF & WebP Preview: the best seconds of any video as a looping GIF

**Video to GIF** in one API call: send links to your **video files** (MP4, MOV, WEBM, MKV...) and get back short **looping animated GIF** and **animated WebP previews**, an optional muted **MP4 loop** and a **JPEG thumbnail** for each one. You do not have to find the right moment yourself: in **auto mode** the Actor picks the **most active, sharp, non-black seconds** of the video. You can also cut your own clip (start + length) or get **one preview per scene**. A **file-size target** (for example "under 2 MB" for email or Slack) is met automatically.

Typical uses:

- **Hover previews and thumbnails-in-motion** for video libraries, course platforms, marketplaces and product pages
- **GIFs for email newsletters, Slack, GitHub READMEs, docs and help centers** (where video does not play)
- **Animated WebP** for fast web pages: about 10x smaller than the same GIF
- **Scene previews** of long recordings, trailers and ads for review tools and asset managers
- Bulk previews for **AI agents and automations** (n8n, Make, Zapier) that need a quick look at a video

### How it works

1. **Download** the video file (direct links, S3/R2/GCS pre-signed URLs, Dropbox and Google Drive share links, Apify key-value store records).
2. **Choose the span**:
   - `auto`: the encoded frame sizes of the whole video (read without decoding) show where things move; the most active windows plus a few spread-out ones are decoded and scored on real pixels: motion, sharpness, contrast and exposure. Black frames and hard cuts inside the span are penalised. You get the best span, or the N best (`previewCount`).
   - `clip`: your `startSeconds` (seconds or MM:SS) and `clipSeconds`.
   - `scenes`: our shot detector (the same one as in [Video Scene Detection](https://apify.com/kantolabs/video-scene-detection)) finds cuts, dissolves and fades; the liveliest part of each scene becomes a preview, up to `maxScenes`.
3. **Encode** only those seconds: GIF with a per-clip colour palette (ffmpeg palettegen + paletteuse), animated WebP (libwebp), MP4 (H.264, no audio, fast start). Width (default 480 px) and frame rate (default 12 fps) are yours; the source is never upscaled.
4. **Fit the size target** if you set one: fewer colours or a lower quality first, then a lower frame rate and width, down to 160 px / 5 fps. If even that is too big, you still get the smallest version and `sizeTargetMet: false` with a note.

### Why run it on Apify

- **API, no ffmpeg setup**: call it from any language, or from n8n, Make, Zapier and the Apify MCP server for AI agents.
- **Batch**: hundreds of videos in one run, one dataset row per preview, files in the run's key-value store.
- **Schedules and webhooks**: make previews of every new upload automatically.

### Input example

```json
{
    "videoUrls": ["https://your-bucket.s3.amazonaws.com/demo.mp4"],
    "mode": "auto",
    "clipSeconds": 3,
    "previewCount": 1,
    "formats": ["gif", "webp"],
    "width": 480,
    "fps": 12,
    "loop": true,
    "quality": "balanced",
    "maxFileSizeMb": 2
}
```

### Output example

One dataset row per preview (shortened):

```json
{
    "fileName": "sample-creative-ad.mp4",
    "status": "ok",
    "previewIndex": 1,
    "mode": "auto",
    "thumbnailUrl": "https://api.apify.com/v2/key-value-stores/.../records/...-p1-00015000ms-thumbnail.jpg",
    "gifUrl": "https://api.apify.com/v2/key-value-stores/.../records/...-p1-00015000ms.gif",
    "gifSizeBytes": 1888299,
    "webpUrl": "https://api.apify.com/v2/key-value-stores/.../records/...-p1-00015000ms.webp",
    "webpSizeBytes": 194310,
    "width": 480, "height": 270, "fps": 12, "frames": 36, "durationSeconds": 3.0, "loop": true,
    "sourceStart": 15.0, "sourceEnd": 18.0, "sourceStartTimecode": "00:00:15.000",
    "sizeTargetBytes": 2000000, "sizeTargetMet": true,
    "encoding": {"gif": {"bytes": 1888299, "width": 480, "fps": 12, "colors": 256, "tries": 1}, "webp": {"bytes": 194310, "quality": 72}},
    "selection": {"reason": "Most active, sharp, non-black span of 6 candidate windows.", "score": 0.88, "motion": 4.38, "sharpness": 438.1, "blankShare": 0.0, "cuts": 0, "thumbnailAtSeconds": 16.75},
    "sourceDurationSeconds": 30.21, "sourceWidth": 1280, "sourceHeight": 720, "sourceCodec": "h264",
    "billedPreviews": 1
}
```

The "Previews" table view in the Console shows the thumbnail, the time range, links to every file and why that span was chosen.

### Pricing

Pay per event, **$0.014 per preview** (Silver $0.0126, Gold $0.0119). One preview includes **every format you ask for** (GIF + WebP + MP4) and the thumbnail. Nothing else is billed: no per-minute or platform-usage charge.

Worked example: 200 product videos, one auto preview each = 200 x $0.014 = **$2.80**. A 40-minute webinar in scenes mode with `maxScenes: 10` = 10 previews = **$0.14**.

**Free**: refused links, failed downloads, files that are not videos, damaged or black videos, a start time beyond the end of the video and any other error row. Set **"Max cost per run"** to cap a run: previews that would go over it are not made and are listed as `skipped` (free).

### FAQ

**How do I convert a video to GIF without losing quality?** Keep 2-4 second clips, 480 px and 10-15 fps, and pick `quality: high`. GIF is limited to 256 colours per frame, so busy film footage is always larger than a WebP or MP4 of the same clip; use the WebP when the page supports it.

**How do I make a GIF under 2 MB for email or Slack?** Set `maxFileSizeMb: 2`. Each file is re-encoded until it fits; `encoding` shows the final width, fps and colours.

**Which video formats work?** Anything ffmpeg reads: MP4/M4V (H.264, HEVC), MOV (iPhone, with rotation), WEBM (VP8/VP9), MKV, AVI, OGV, MPEG-TS, and animated GIF input (GIF to WebP).

**Can it read YouTube or TikTok links?** No. Platform pages are refused because their terms forbid downloading. Link your own file.

**Does it keep the sound?** No: GIF and WebP have no audio and the MP4 loop is muted, as autoplay previews are.

**What does "auto" choose on a screen recording?** The span with the most change on screen (scrolling, typing, a new page). On a static slide video, the sharpest and best-exposed part.

**Is there a length limit?** Previews up to 30 s each. Source videos up to 600 minutes and 4 GB (defaults 180 min / 2 GB). The price does not depend on the video's length.

### Known limits

- **Portrait (9:16) videos** at the default 480 px width give 480x854 GIFs, about 3x the bytes of a 16:9 GIF. Use `width: 320` or a size target for chat and email.
- **Busy footage** (film grain, fast pans, confetti) makes large GIFs; the animated WebP of the same clip is usually 5-10x smaller.
- **HDR (10-bit HLG/PQ) phone videos** are converted without tone mapping, so colours can look flat.
- **Auto mode** looks at a few candidate windows chosen from the whole video's activity, not at every second, and it prefers motion over meaning: it cannot know which moment matters to you. Use `previewCount: 3` to get alternatives, or `clip` mode for an exact moment.

### Related Actors from Kanto Labs

- [Video Frame Extractor](https://apify.com/kantolabs/video-frame-extractor): keyframes, scene frames and best thumbnails as images
- [Video Scene Detection](https://apify.com/kantolabs/video-scene-detection): every cut, dissolve and fade with timecodes and clips
- [Video OCR](https://apify.com/kantolabs/video-ocr): on-screen text and burned-in subtitles from video files
- [Video Ad Creative Breakdown](https://apify.com/kantolabs/video-creative-breakdown): hook, shot list, transcript and pacing of ad videos

### Support

Found a video that fails or a preview you would have cut differently? Open an issue in the **Issues** tab with the video link and your input; we reply within a day.

# Actor input Schema

## `videoUrls` (type: `array`):

Direct links to video FILES (MP4, MOV, WEBM, MKV, M4V, AVI...), one per line: your storage, S3/R2/GCS (public or pre-signed URLs), a CDN, an Apify key-value store, Dropbox or Google Drive share links ('anyone with the link'). YouTube, TikTok, Instagram and other platform pages are refused.

## `mode` (type: `string`):

auto = the best seconds (most motion, sharp, no black frames, no hard cut inside). clip = the span you set with 'Start time' + 'Clip length'. scenes = one preview per scene (cut detection), up to 'Max scenes'.

## `clipSeconds` (type: `number`):

Length of each preview. 2-4 s makes small, smooth loops; GIF size grows with every second. Max 30.

## `startSeconds` (type: `string`):

Where the clip starts in 'clip' mode: seconds (12.5) or MM:SS (1:05) or HH:MM:SS. Ignored by auto and scenes.

## `previewCount` (type: `integer`):

Auto mode: the N best non-overlapping spans (best first). Each preview is one charged event.

## `maxScenes` (type: `integer`):

Scenes mode: at most this many previews per video (the longest scenes, in time order). Scenes shorter than 0.8 s and black scenes are skipped.

## `formats` (type: `array`):

Files made for every preview (all included in the one preview price): gif (works everywhere, email, Slack, GitHub), webp (animated WebP, ~10x smaller than GIF, all modern browsers), mp4 (muted H.264 loop for web/social). A JPEG thumbnail is always added.

## `width` (type: `integer`):

Output width; height follows the video's aspect ratio. Never upscaled beyond the source. 480 is the usual GIF size; 320 for small email/chat previews.

## `fps` (type: `number`):

10-15 looks smooth for GIFs; lower = smaller files. Never above the source frame rate.

## `loop` (type: `boolean`):

On: GIF/WebP loop endlessly. Off: they play once and stop on the last frame.

## `quality` (type: `string`):

high = smoothest colours (error-diffusion dither, largest GIF). balanced = ordered dither + light denoise (smaller, clean). small = 128 colours, lower WebP/MP4 quality.

## `maxFileSizeMb` (type: `number`):

Optional size target, e.g. 2 for email/Slack or 8 for Discord. Each file that is too big is re-encoded with fewer colours / lower quality, then lower fps and width, until it fits (down to 160 px / 5 fps). 0 = no target.

## `maxDurationMinutes` (type: `integer`):

Longer videos are skipped (free). Up to 600.

## `maxVideoSizeMb` (type: `integer`):

Larger files are skipped (free).

## `downloadTimeoutSecs` (type: `integer`):

Give up on a video that does not download within this time (free).

## Actor input object example

```json
{
  "videoUrls": [
    "https://api.apify.com/v2/key-value-stores/aXcXwfChlioPWAUJv/records/sample-creative-ad.mp4?signature=1yQpP7ggbJGjS4rGodq21"
  ],
  "mode": "auto",
  "clipSeconds": 3,
  "startSeconds": "0",
  "previewCount": 1,
  "maxScenes": 10,
  "formats": [
    "gif",
    "webp"
  ],
  "width": 480,
  "fps": 12,
  "loop": true,
  "quality": "balanced",
  "maxFileSizeMb": 0,
  "maxDurationMinutes": 180,
  "maxVideoSizeMb": 2000,
  "downloadTimeoutSecs": 600
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `files` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "videoUrls": [
        "https://api.apify.com/v2/key-value-stores/aXcXwfChlioPWAUJv/records/sample-creative-ad.mp4?signature=1yQpP7ggbJGjS4rGodq21"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("kantolabs/video-to-gif").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "videoUrls": ["https://api.apify.com/v2/key-value-stores/aXcXwfChlioPWAUJv/records/sample-creative-ad.mp4?signature=1yQpP7ggbJGjS4rGodq21"] }

# Run the Actor and wait for it to finish
run = client.actor("kantolabs/video-to-gif").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "videoUrls": [
    "https://api.apify.com/v2/key-value-stores/aXcXwfChlioPWAUJv/records/sample-creative-ad.mp4?signature=1yQpP7ggbJGjS4rGodq21"
  ]
}' |
apify call kantolabs/video-to-gif --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,kantolabs/video-to-gif"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/oDoV4gvzcbYR6INkh/builds/sbtDTH2S1FS8BeFqc/openapi.json
