# Convert MKV to FLAC

> To convert MKV to FLAC, send one POST to /v1/audio-convert with the MKV source and "to": "flac" in the body. Left out, "to" falls back to its default "mp3", so a FLAC 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 100 MB and 60 min (3,600 s) long.

- Endpoint: `POST /v1/audio-convert`
- Price: $0.003 per successful call
- API: [audio-convert](https://grist.tools/docs/audio-convert)
- Selects the target: `"to": "flac"`

## Limits

| Limit | Value |
| --- | --- |
| Largest source file | 100 MB (104,857,600 bytes) |
| Longest input | 60 min (3,600 s) |
| Timeout | 94 s |
| Source formats | AIFF, AVI, FLAC, MKV, MP3, MP4, Ogg, WAV |
| Output formats | AAC, FLAC, MP3, Opus, WAV |

## Example

A real MKV to FLAC run of audio-convert.

Request body:

```json
{
  "url": "https://grist.tools/samples/av/pair-clip.mkv",
  "to": "flac"
}
```

Response:

```json
{
  "source_url": "https://grist.tools/samples/av/pair-clip.mkv",
  "bytes": 10531,
  "source_container": "matroska",
  "format": "flac",
  "bitrate_kbps": null,
  "sample_rate": null,
  "audio_bytes": 16585,
  "audio_base64": "ZkxhQwAAACICQAJAAAAAAASVAfQA8AAAAAAAAAAAAAAAAAAAAAAAAAAABAAADgYA..."
}
```

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 recorded run returned 16.2 KB (16,585 bytes) of FLAC, 1.6 times the source size, with the source read as the matroska container. Decoded, the FLAC in audio_base64 opens with 66 4C 61 43 00 00 00 22 02 40 02 40 (ASCII fLaC). 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 FLAC: its 34-byte STREAMINFO block, in its own field order, declares blocks of 576 samples, a largest frame of 1,173 bytes, 8,000 Hz, 1 channel, 16 bits per sample and a total sample count of 0, which the format reserves for a length the encoder did not write back. Its MD5 signature of the decoded audio is all zeros, the value for a signature that was not computed. The next metadata block is VORBIS_COMMENT, 14 bytes long.

## Format 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.

FLAC as a target: Lossless compression is the point of a FLAC target. A PCM source normally comes out smaller, and at the source rate every sample survives; a lossy source goes the other way and grows, because the encoder keeps each decoded sample, artefacts included, and recovers nothing the earlier compression removed. ffmpeg's flac codec and flac muxer write the result, streamed to a pipe with no temporary file. As with any lossless destination, a bitrate_kbps value is refused rather than silently ignored. A sample_rate from the closed set can be pinned; left unset, ffmpeg usually follows the rate of the input. The duration is checked before encoding starts, video is dropped, metadata and chapters are stripped, and just the first audio stream is mapped, under bit-exact flags that keep the output reproducible with the pinned ffmpeg.

## Errors

- `invalid_input` (400)
- `blocked_target` (403)
- `unreachable_target` (424)
- `upstream_timeout` (424)
- `unsupported_content_type` (415)
- `too_large` (413)
- `unprocessable` (422)
- `internal` (500)

When each is raised, and what it means for payment: https://grist.tools/docs/audio-convert.

## Questions

### What does it cost to convert MKV to FLAC?

$0.003 per call, paid in USDC on Base via x402.

### How large can the MKV file be?

Up to 100 MB (104,857,600 bytes), and at most 60 min (3,600 s) of media. 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.

This page as HTML: https://grist.tools/tools/mkv-to-flac. Every page of grist.tools has a Markdown version at its address plus .md.
