On this page
DocsGuides
GIF previews
Turn a few seconds of video into an animated GIF with a palette made for its frames.
POST /v1/gif turns part of a video into an animated GIF with a palette made for its own frames,
so the colours hold up.
The request#
curl "$VIDEXO_API_URL/v1/gif" \
-H "Authorization: Bearer $VIDEXO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "https://example.com/talk.mp4",
"filename": "preview.gif",
"trim": {
"start": 5,
"duration": 4
},
"fps": 12,
"resize": {
"width": 480
}
}'Copy failed. The text is selected; copy it with your keyboard.
const response = await fetch(`${process.env.VIDEXO_API_URL}/v1/gif`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VIDEXO_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"input": "https://example.com/talk.mp4",
"filename": "preview.gif",
"trim": {
"start": 5,
"duration": 4
},
"fps": 12,
"resize": {
"width": 480
}
}),
});
const job = await response.json();Copy failed. The text is selected; copy it with your keyboard.
ffmpeg \
-ss 5 -t 4 -i https://example.com/talk.mp4 \
-filter_complex "[0:v:0]scale=480:7680:force_original_aspect_ratio=decrease:force_divisible_by=2:flags=lanczos,fps=12[o0s0];[o0s0]split[o0g0][o0g1];[o0g0]palettegen=max_colors=256[o0p];[o0g1][o0p]paletteuse[o0v]" \
-map "[o0v]" \
preview.gifCopy failed. The text is selected; copy it with your keyboard.
preview.gif: 4 seconds from 0:05, 480 pixels wide at 12 frames a second, in colours picked from those frames.
The gif-preview preset#
The first 5 seconds at 12 frames a second, at most 480 pixels wide; trim moves it.
curl "$VIDEXO_API_URL/v1/gif" \
-H "Authorization: Bearer $VIDEXO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "https://example.com/talk.mp4",
"preset": "gif-preview",
"trim": {
"start": 30
}
}'Copy failed. The text is selected; copy it with your keyboard.
const response = await fetch(`${process.env.VIDEXO_API_URL}/v1/gif`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VIDEXO_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"input": "https://example.com/talk.mp4",
"preset": "gif-preview",
"trim": {
"start": 30
}
}),
});
const job = await response.json();Copy failed. The text is selected; copy it with your keyboard.
ffmpeg \
-ss 30 -t 5 -i https://example.com/talk.mp4 \
-filter_complex "[0:v:0]scale='min(iw,480)':'min(ih,7680)':force_original_aspect_ratio=decrease:force_divisible_by=2:flags=lanczos,fps=12[o0s0];[o0s0]split[o0g0][o0g1];[o0g0]palettegen=max_colors=256[o0p];[o0g1][o0p]paletteuse[o0v]" \
-map "[o0v]" \
gif.gifCopy failed. The text is selected; copy it with your keyboard.
Without trim.duration or trim.end a GIF stops at 60 seconds. colors (2 to 256) makes the file
smaller with fewer colours, and fps is at most 30.