catalogue / tools / Audio & video / MKV to JPEG

Convert MKV to JPEG (single frame)

To convert MKV to JPEG (single frame), send one POST to /v1/video-thumbnail with the MKV source and "format": "jpeg" in the body. Left out, "format" falls back to its default "png", so a JPEG request has to send it. Each call costs $0.003 in USDC on Base via x402, with no account and no API key. The source file can be up to 200 MB.

Endpoint
POST /v1/video-thumbnail
Price
$0.003 per call

01Limits

LimitValue
Largest source file200 MB (209,715,200 bytes)
Timeout60 s
Source formatsAVI, MKV, MP4, Ogg
Output formatsJPEG, PNG
Option time_secondsdefault 0

02Example

A real MKV to JPEG run of video-thumbnail.

Request
POST /v1/video-thumbnail
content-type: application/json
payment-signature: <base64 x402 payload>

{
  "url": "https://grist.tools/samples/av/pair-clip.mkv",
  "time_seconds": 1,
  "format": "jpeg"
}
Response
200 OK
payment-response: <base64 settlement receipt>

{
  "source_url": "https://grist.tools/samples/av/pair-clip.mkv",
  "bytes": 10531,
  "container": "matroska",
  "time_seconds": 1,
  "format": "jpeg",
  "width": 64,
  "height": 36,
  "image_bytes": 389,
  "image_base64": "/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgEBAQEBAUFBQUFBQYGBgYGBgYGBgYG..."
}

Source file: av/pair-clip.mkv, 10.3 KB (10,531 bytes). 4 s Matroska file made by ffmpeg: a 64x36 PNG video stream at 1 fps (a slate field with a small amber square moving right), a mono 8 kHz FLAC audio track of two 500 Hz triangle beeps, and an English SubRip subtitle stream with two cues. The request sets time_seconds to 1. The recorded run returned 389 bytes of JPEG, 4% of the source size, with the source read as the matroska container, an image of 64x36 pixels and the frame taken at 1 s. Decoded, the JPEG in image_base64 opens with FF D8 FF E0 00 10 4A 46 49 46 00 01 (ASCII JFIF). Recorded with ffmpeg 8.1.2.

In the sample itself, the EBML header names DocType matroska, version 4, readable by a version 2 parser; Segment Info sets a timestamp scale of 1,000,000 ns and a duration of 4,000 ticks, 4 s, with Lavf as the muxing application; the Tracks element lists codec IDs V_MS/VFW/FOURCC (video, language und), A_FLAC (audio, language und) and S_TEXT/UTF8 (subtitle, language eng). In the returned JPEG: after the start-of-image marker comes a 16-byte JFIF APP0 segment, version 1.02, density 1 by 1 with no unit. The segment after it has marker FF DB.

03Format notes

MKV as a source

Matroska files begin with the EBML magic 1A 45 DF A3, and WebM uses the same signature, so the sniffer treats both as a single container and reports it as matroska in the container field of each response. Matroska is built from tracks that ffmpeg can address independently. When audio is the target, the first audio track is decoded and any picture is ignored. For a still frame, the requested timestamp is sought at the demuxer level before one picture is decoded, with sound excluded. A subtitle track is chosen by its index counted among subtitle tracks only, starting from zero, and an index that matches nothing is refused rather than answered with an empty file. SubRip or WebVTT text written by ffmpeg comes back together with a cue count taken from the timing arrows in that text.

JPEG as a target

image-convert writes JPEG through sharp with options pinned around the caller's quality value. mozjpeg is off, scans are baseline rather than progressive, chroma subsampling is fixed, coding is optimised, and trellis quantisation and overshoot deringing are both disabled. Fixing these settings means the same image, format and quality produce the same bytes on a given build, instead of drifting with a libvips default. The pixel grid is not resized; only codec and container change, and the response reports the width and height of the result. Because withMetadata is never called, EXIF and similar blocks are dropped. An animated input is opened with animation off, so its first frame is the one encoded. Video frames take another road: video-thumbnail decodes one picture and hands it to ffmpeg's mjpeg encoder, which streams it out through image2pipe.

Note: The answer is one frame of the video, taken at the timestamp you choose, not the whole video.

04Errors

CodeHTTP
invalid_input400
blocked_target403
unreachable_target424
upstream_timeout424
unsupported_content_type415
too_large413
unprocessable422
internal500

When each is raised, and what it means for payment: /docs/video-thumbnail.

05Questions

What does it cost to convert MKV to JPEG?
$0.003 per call, paid in USDC on Base via x402.
How large can the MKV file be?
Up to 200 MB (209,715,200 bytes). Past a limit the call answers too_large (413).
What happens if the conversion fails?
The tool answers with a typed JSON error from the errors table. Payment is settled only after the tool has produced its result; a call that fails inside the tool is never settled.

06Related