catalogue / tools / Audio & video / MP4 to MP3

Convert MP4 to MP3

To convert MP4 to MP3, send one POST to /v1/audio-convert with the MP4 source and "to": "mp3" in the body. "mp3" is the schema default of "to", so the field may also be left out. 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 MP4 to MP3 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-clip.mp4",
  "to": "mp3"
}
Response
200 OK
payment-response: <base64 settlement receipt>

{
  "source_url": "https://grist.tools/samples/av/pair-clip.mp4",
  "bytes": 11315,
  "source_container": "mp4",
  "format": "mp3",
  "bitrate_kbps": null,
  "sample_rate": null,
  "audio_bytes": 4196,
  "audio_base64": "SUQzBAAAAAAACgAAAAAAAAAAAAD/4xjEAAxoAub5QBAAh1QgCdy3AiAECgDB/D8Q..."
}

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 4.1 KB (4,196 bytes) of MP3, 37% of the source size, with the source read as the mp4 container. Decoded, the MP3 in audio_base64 opens with 49 44 33 04 00 00 00 00 00 0A 00 00. 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 MP3: it opens with an ID3v2.4 tag with 10 bytes of body, then an MPEG 2.5 Layer III frame header at byte 20: 8 kbps, 8,000 Hz, mono.

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

MP3 as a target

MP3 is the default value of audio-convert's to field, encoded with the pinned libmp3lame codec. The mp3 muxer needs no seeking, so output streams straight to a pipe instead of a temporary file. bitrate_kbps applies to this lossy destination; when it is omitted, no audio bitrate argument is passed, the encoder's own default applies, and the response reports the bitrate as null. An optional sample_rate selects from the closed set, otherwise ffmpeg normally follows the source. Only the first audio stream is encoded, and video, chapters and metadata are left out, with bit-exact flags keeping the bytes reproducible for the pinned ffmpeg. Even with source metadata removed, each recorded MP3 output still begins with an ID3v2 tag written by the muxer. Inputs whose duration exceeds the service limit are refused before encoding.

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 MP4 to MP3?
$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.

06Related