catalogue / tools / Audio & video / MP3 to Opus

Convert MP3 to Opus

To convert MP3 to Opus, send one POST to /v1/audio-convert with the MP3 source and "to": "opus" in the body. Left out, "to" falls back to its default "mp3", so a Opus 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 MP3 to Opus 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.mp3",
  "to": "opus"
}
Response
200 OK
payment-response: <base64 settlement receipt>

{
  "source_url": "https://grist.tools/samples/av/pair-tone.mp3",
  "bytes": 12980,
  "source_container": "mp3",
  "format": "opus",
  "bitrate_kbps": null,
  "sample_rate": null,
  "audio_bytes": 27133,
  "audio_base64": "T2dnUwACAAAAAAAAAAAAAAAAAAAAAGS5xGoBE09wdXNIZWFkAQE4AUAfAAAAAABP..."
}

Source file: av/pair-tone.mp3, 12.7 KB (12,980 bytes). 3 s mono 8 kHz MP3 at 32 kbit/s, encoded by ffmpeg's libmp3lame with the bit-exact flags: three 0.5 s 500 Hz triangle beeps at rising level, each followed by 0.5 s of silence. The recorded run returned 26.5 KB (27,133 bytes) of Opus, 2.1 times the source size, with the source read as the mp3 container. Decoded, the Opus in audio_base64 opens with 4F 67 67 53 00 02 00 00 00 00 00 00 (ASCII OggS). Recorded with ffmpeg 8.1.2.

In the sample itself: the file opens with an ID3v2.4 tag with 10 bytes of body, then an MPEG 2.5 Layer III frame header at byte 20: 32 kbps, 8,000 Hz, mono. That first frame is an Info header rather than audio, and it counts 44 audio frames and 12,960 bytes. In the returned Opus: the first Ogg page, flagged as the beginning of the stream, has stream serial 0 and one 19-byte packet, the OpusHead: version 1, 1 channel, a pre-skip of 312 samples, an input sample rate of 8,000 Hz and channel mapping family 0.

03Format notes

MP3 as a source

MP3 is lossy audio. Grist accepts it when the file opens with an ID3v2 tag or with a bare MPEG audio frame sync: the byte FF followed by a byte whose top three bits are set. That sync test also matches a raw ADTS AAC stream, and because nothing proves ffmpeg would then pick the right demuxer, AAC is kept out of the sources. Duration needs care with MP3. For a file without a Xing header, the probe estimates length by dividing file size by the bitrate of the first frames, which a crafted variable-bitrate file can falsify, so any probe warning sends the measurement to a scan of real packet timestamps. Once accepted, the first audio stream is decoded by ffmpeg; a lossless destination stores the decoded samples without recovering what MP3 encoding discarded.

Opus as a target

An Opus result is libopus-encoded audio inside an Ogg container: the ogg muxer writes it, and the recorded outputs begin with the OggS capture pattern followed by an OpusHead identification header. For that reason a returned Opus file is recognised as ogg if it is submitted again, and opus never appears as a source slug. bitrate_kbps controls the lossy encode, and an optional sample_rate may be chosen from the closed set; left out, ffmpeg normally follows the source rate. The input's duration is checked first, then the first audio stream alone is encoded, excluding video, metadata and chapters. Pinned ffmpeg and bit-exact flags make repeated calls return the same bytes. With no bitrate given the encoder's default rate applies, and for the recorded low-rate mono examples that default produced larger files than the MP3 default.

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 MP3 to Opus?
$0.003 per call, paid in USDC on Base via x402.
How large can the MP3 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