catalogue / tools / Audio & video / AIFF to FLAC

Convert AIFF to FLAC

To convert AIFF to FLAC, send one POST to /v1/audio-convert with the AIFF 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 call

01Limits

LimitValue
Largest source file100 MB (104,857,600 bytes)
Longest input60 min (3,600 s)
Timeout94 s
Source formatsAIFF, AVI, FLAC, MKV, MP3, MP4, Ogg, WAV
Output formatsAAC, FLAC, MP3, Opus, WAV

02Example

A real AIFF to FLAC run of audio-convert.

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

{
  "url": "https://grist.tools/samples/av/pair-tone.aiff",
  "to": "flac"
}
Response
200 OK
payment-response: <base64 settlement receipt>

{
  "source_url": "https://grist.tools/samples/av/pair-tone.aiff",
  "bytes": 48054,
  "source_container": "aiff",
  "format": "flac",
  "bitrate_kbps": null,
  "sample_rate": null,
  "audio_bytes": 15657,
  "audio_base64": "ZkxhQwAAACICQAJAAAAAAASVAfQA8AAAAAAAAAAAAAAAAAAAAAAAAAAABAAADgYA..."
}

Source file: av/pair-tone.aiff, 46.9 KB (48,054 bytes). 3 s mono 8 kHz 16-bit PCM AIFF file written directly by the generator: three 0.5 s 500 Hz triangle beeps at rising level, each followed by 0.5 s of silence. The recorded run returned 15.3 KB (15,657 bytes) of FLAC, 33% of the source size, with the source read as the aiff 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 FORM container is of type AIFF; the COMM chunk declares 1 channel, 24,000 sample frames of 16 bits and a rate of 8,000 Hz stored as an 80-bit extended float, 3 s; the SSND chunk holds 48,008 bytes, big-endian samples behind an 8-byte offset and block size header. 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.

03Format notes

AIFF as a source

AIFF files start with the IFF marker FORM, and Grist also requires the form type at byte eight to read AIFF or AIFC, the variant that allows compressed audio. Classic AIFF stores its PCM samples big-endian, the opposite byte order to WAV. The format is audio only, so video-thumbnail and subtitle-extract turn it away as a container without a picture or caption stream, and audio-convert is its single reader. That service measures the first audio stream's duration, maps only that stream, and strips metadata and chapters before encoding. AIFF is absent from audio-convert's destination enum, so it can be read here but not written. Converting to WAV rewrites the samples as little-endian PCM through the pinned pcm_s16le codec, which changes byte order without altering the sampled values of a sixteen-bit source.

FLAC as a target

FLAC output is produced by ffmpeg's flac codec and flac muxer, streamed to a pipe rather than a temporary file. This destination is lossless, so a bitrate_kbps value is rejected instead of silently ignored. The caller may pin a sample_rate from the closed set; otherwise ffmpeg picks, normally the rate of the input. Before encoding starts the duration is checked, then only the first audio stream is mapped, video is discarded, and metadata and chapters are removed. Bit-exact flags make the output reproducible with the pinned ffmpeg. From a PCM source the result is normally smaller, and at the source rate the samples are preserved. From a lossy source it grows instead, because the lossless encoder stores every decoded sample, artefacts included, and cannot recover what the earlier compression removed.

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/audio-convert.

05Questions

What does it cost to convert AIFF to FLAC?
$0.003 per call, paid in USDC on Base via x402.
How large can the AIFF 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.

06Related