Convert MP4 to FLAC
To convert MP4 to FLAC, send one POST to /v1/audio-convert with the MP4 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.
Agents read this page asGET /v1/audio-convert/schemafree: schema, examples, errors, price
- Endpoint
- POST /v1/audio-convert
- Price
- $0.003 per call
- 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 MP4 to FLAC run of audio-convert.
POST /v1/audio-convert
content-type: application/json
payment-signature: <base64 x402 payload>
{
"url": "https://grist.tools/samples/av/pair-clip.mp4",
"to": "flac"
}200 OK
payment-response: <base64 settlement receipt>
{
"source_url": "https://grist.tools/samples/av/pair-clip.mp4",
"bytes": 11315,
"source_container": "mp4",
"format": "flac",
"bitrate_kbps": null,
"sample_rate": null,
"audio_bytes": 16585,
"audio_base64": "ZkxhQwAAACICQAJAAAAAAASVAfQA8AAAAAAAAAAAAAAAAAAAAAAAAAAABAAADgYA..."
}Source file: av/pair-clip.mp4, 11 KB (11,315 bytes). 4 s MP4 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 mov_text subtitle stream with two cues. The recorded run returned 16.2 KB (16,585 bytes) of FLAC, 1.5 times the source size, with the source read as the mp4 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 ftyp box names major brand isom, minor version 512 and compatible brands isom, iso2 and mp41; the top-level boxes run ftyp, free, mdat and moov, so the moov index comes after the media data; mvhd counts 4,000 ticks at 1,000 per second, 4 s; the 3 tracks are vide with sample entry mp4v, soun with sample entry fLaC and sbtl with sample entry tx3g. 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
MP4 as a source
MP4 belongs to the ISO base-media family, and Grist recognises it by the ftyp box type at bytes four to eight rather than by a file extension. QuickTime MOV and other files carrying the same box are sniffed as this one container, and the response names it mp4. The container can hold video, audio and text subtitle streams side by side, and each service takes one kind. audio-convert maps the first audio stream and drops the picture. video-thumbnail puts the seek before the input, so it happens at the demuxer and stays cheap in a large file, then decodes exactly one frame from the first video stream. subtitle-extract selects a text track by its zero-based position among subtitle streams. Each ffmpeg run strips container metadata and sets bit-exact flags, so outputs do not carry creation timestamps.
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
When each is raised, and what it means for payment: /docs/audio-convert.
Questions
What does it cost to convert MP4 to FLAC?
$0.003 per call, paid in USDC on Base via x402.
How large can the MP4 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.