apyhub
Cover illustration for How to Convert a Video to a GIF online Using an API
Engineering

How to Convert a Video to a GIF online Using an API

How to Convert Video to GIF with an API (2026 Guide)

Updated September 17, 2026. This guide has been rewritten with working code examples, current parameters for the ApyHub Video to GIF API, GIF vs MP4 file size data, an FFmpeg method, and what the Tenor API shutdown means for apps that show GIFs.

01Introduction

To convert a video to a GIF programmatically, send the video (or its URL) to a video to GIF API with the start time, length, and size you want, and the API returns an animated GIF. If you'd rather run the conversion yourself, FFmpeg can do the same job from the command line.

GIFs are still everywhere in 2026: in chat apps, emails, product docs, GitHub READMEs, and support articles. But the format is old, and it comes with real trade-offs in file size. This guide covers when a GIF is the right choice, how to create one with FFmpeg or the ApyHub Video to GIF API, and how to keep the files small.

02What changed for GIFs in 2026

The biggest change this year happened on the GIF search side. Google shut down the Tenor API on June 30, 2026, breaking the GIF pickers of services that still relied on it and forcing platforms such as X to move to other providers. Discord, WhatsApp, and Bluesky were also affected. Tenor itself is still available on its website and inside Google products, but third-party apps can no longer search its library through the API.

For developers, that shutdown is a reminder of how much depends on a single external GIF library. Search APIs like GIPHY and KLIPY are still options for finding existing GIFs. For product demos, onboarding clips, user uploads, and branded content, though, many teams generate their own GIFs from their own videos, which also means they control the content, the size, and the licensing.

03GIF vs MP4: which should you use?

Before converting anything, it's worth knowing what a GIF costs. The GIF format stores every frame as a separate image with a limited color palette, so it compresses motion poorly. Modern video formats do much better.

In Google's web.dev guide to replacing animated GIFs with video, a 3.7 MB GIF converted to a 551 KB MP4 and a 341 KB WebM file. That's roughly 85% and 91% smaller. The exact savings depend on the clip, but the direction is consistent, which is why Lighthouse and PageSpeed Insights flag large animated GIFs and recommend video formats instead.

GIFMP4 (H.264)WebM (VP9)
File sizeLargestMuch smallerSmallest
Colors256 per frameFull colorFull color
SoundNoYesYes
Plays automatically everywhereYes, as an imageNeeds a <video> tag with autoplay, muted, loopNeeds a <video> tag; check browser support
Works in emailYes, in most clientsRarelyRarely
Works in chat apps, docs, READMEsYesVariesVaries

Use a GIF when the destination only accepts images: email campaigns, chat messages, Markdown files, many help centers and documentation tools, and places where you can't add a video tag.

Use MP4 or WebM when you control the web page. A short looping video with autoplay muted loop playsinline behaves like a GIF at a fraction of the size.

04Three ways to convert video to GIF

1. Online tools

Desktop and browser tools such as EZGIF, Kapwing, and Photoshop are the fastest option for a one-off GIF. They don't help when GIFs need to be created automatically, for example for every product video or every user upload.

2. FFmpeg

FFmpeg is the standard open-source tool for converting video. For good-looking GIFs, generate a custom color palette from the clip first, then apply it. This one command does both:

bash

· bash
ffmpeg -ss 5 -t 4 -i input.mp4 \
  -vf "fps=12,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
  -loop 0 output.gif

Here's what each part does:

  • -ss 5 -t 4: start 5 seconds in and use 4 seconds of video
  • fps=12: keep 12 frames per second, which is smooth enough for most GIFs and keeps the file smaller
  • scale=480:-1: make the GIF 480 pixels wide and keep the proportions
  • palettegen and paletteuse: build a 256-color palette from this clip, which looks much better than the default palette
  • -loop 0: loop forever

FFmpeg gives you full control. The trade-off is that you install, update, secure, and scale it yourself, including the servers and queues that run it when conversions happen inside your product.

3. A video to GIF API

A video to GIF API does the conversion on its own servers. You send the video and your settings over HTTPS and get a GIF back, so there's nothing to install or scale. This is the practical choice when GIF creation is one feature in a larger app, when conversions arrive at unpredictable times, or when an AI agent needs to create GIFs on its own.

05How to convert video to GIF with the ApyHub API

The ApyHub Video to GIF API accepts a video upload (MP4, MKV, AVI, MOV, FLV, 3GP, or WebM, up to 100 MB) or a public video URL, and returns the GIF as a file or as a signed download link.

Parameters

ParameterWhat it doesDefault
video or video_urlThe source video, as an upload or a public URLRequired
start_timeWhere the clip starts, in seconds0
durationClip length in seconds, from 1 to 202
sizeOutput dimensions as width x height, such as 480x270Original size
speedPlayback speed from -10 to 10; positive is faster, negative is slower0 (normal)

The default length is 2 seconds, so set duration whenever you want a longer clip.

Convert an uploaded video

bash

· bash
curl -X POST "https://api.eu.apyhub.com/apyhub/generate-gif/multi-part/download" \
  -H "apy-token: $APY_TOKEN" \
  -F "video=@/path/to/demo.mp4" \
  -F "start_time=5" \
  -F "duration=4" \
  -F "size=480x270" \
  -o demo.gif

The response is the GIF file itself, saved as demo.gif.

Convert a video from a URL and get a link

bash

· bash
curl -X POST "https://api.eu.apyhub.com/apyhub/generate-gif/url/link" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "video_url": "https://assets.apyhub.com/samples/sample.mp4",
    "start_time": 0,
    "duration": 3,
    "size": "320x240"
  }'

The response contains a time-limited link to the GIF:

json

· json
{
  "data": "https://storage.example.com/gif/output.gif?sig=abc"
}

The same call in Python

python

· python
import os
import requests

response = requests.post(
    "https://api.eu.apyhub.com/apyhub/generate-gif/multi-part/download",
    headers={"apy-token": os.environ["APY_TOKEN"]},
    files={"video": open("demo.mp4", "rb")},
    data={"start_time": 5, "duration": 4, "size": "480x270"},
)
response.raise_for_status()

with open("demo.gif", "wb") as f:
    f.write(response.content)

For larger pipelines

When GIF creation runs in the background, for example after every video upload, the Video to GIF Job API processes conversions as jobs you submit and check later, so your app doesn't wait for each GIF.

Try the Video to GIF API free →

06How to keep GIFs small

GIF files grow quickly with length, size, and motion. These settings make the biggest difference:

  1. Keep it short. Two to five seconds covers most reactions, feature demos, and loops. Use start_time to pick the most important moment.
  2. Reduce the dimensions. A 480-pixel-wide GIF is usually enough for chat, email, and docs. Halving the width cuts the pixel count by about three quarters.
  3. Pick a calm clip. Fast motion and full-screen changes produce much bigger files than a cursor moving across a mostly static screen.
  4. Speed up slow footage. A higher speed value fits more of the action into a shorter GIF.
  5. Use video on your own pages. If you control the HTML, an MP4 or WebM loop is almost always the smaller option.

07Common use cases

  • Product demos and changelogs: turn screen recordings into short loops for release notes, docs, and help articles.
  • Email campaigns: add motion to emails, where video usually isn't supported.
  • User-generated content: let users turn their own clips into shareable GIFs inside your app.
  • Social media and chat: create previews and reactions from longer videos.
  • Education: show one step of a process as a looping clip in course material.

Pair GIF creation with other video tools on the same ApyHub account, such as the Video Thumbnail API for still previews and the Video Watermark API for branding clips before converting them.

08Creating GIFs with AI agents

The Video to GIF API is available through ApyHub MCP, so an AI agent can create a GIF when a task calls for one, for example "turn this product video into a 3-second GIF for the release notes", without a custom integration. New to the protocol? Read what is MCP.

09Conclusion

GIFs remain the most compatible way to show motion in email, chat, and documentation, even though MP4 and WebM are far smaller for web pages you control. With the Tenor API gone, more teams are creating their own GIFs from their own videos instead of relying on a shared library.

For one-off GIFs, an online tool is enough. For conversions inside your product, choose between running FFmpeg yourself and calling the Video to GIF API, which handles the conversion with a single request and gives you control over start time, length, size, and speed.

Get started with ApyHub for free →

The free Starter plan includes 5 API calls per day and 3,000 atoms per month, with no card required.

10FAQ

How do I convert a video to a GIF with an API? Send the video file or its URL to a video to GIF API with your settings. ApyHub's Video to GIF API returns the GIF file or a link to it.

Which video formats can I convert? The ApyHub Video to GIF API accepts MP4, MKV, AVI, MOV, FLV, 3GP, and WebM files, plus publicly accessible video URLs.

How long can the GIF be? Up to 20 seconds. The default is 2 seconds, so set duration for longer clips.

Can I choose which part of the video becomes the GIF? Yes. Set start_time to where the clip should begin and duration to its length.

Can I convert a YouTube video to a GIF? The API needs a direct link to a video file, not a YouTube page. Only convert videos you own or have permission to use.

How do I make a GIF with FFmpeg? Use ffmpeg -ss 5 -t 4 -i input.mp4 -vf "fps=12,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif. The palette steps give much better colors than the default.

Is a GIF or an MP4 better for my website? For pages you control, an MP4 or WebM loop is usually much smaller. In Google's web.dev example, a 3.7 MB GIF became a 551 KB MP4. Use a GIF where video isn't supported, such as email and many chat and documentation tools.

What happened to the Tenor GIF API? Google shut it down on June 30, 2026. Apps that used it for GIF search moved to other providers, and many teams now create their own GIFs from their own videos.

Is the Video to GIF API free? You can try it on ApyHub's free Starter plan, which includes 5 API calls per day and 3,000 atoms per month, with no card required. See pricing for higher usage.

Can AI agents create GIFs? Yes. The Video to GIF API is available to AI agents through ApyHub MCP.

11About ApyHub

ApyHub is a curated API catalog and trusted operational layer for developers and AI agents, with over 1,500 endpoints or capabilities and growing. Teams use the whole catalog through a single subscription priced in atoms, a unit that reflects the actual work each call performs. Every endpoint ships with machine-readable certification aligned with GDPR, SOC 2, and ISO 27001, and is MCP-ready by default, so AI agents can discover and call it through ApyHub MCP without custom wrappers. ApyHub is headquartered in Amsterdam, with offices in the Netherlands, Greece, and India, and serves 65,000+ developer workspaces every month. The free Starter plan includes 5 API calls per day and 3,000 atoms per month, with no card required. Building an API of your own? Become a provider →