Media¶
5 endpoints for video and audio conversion, thumbnail extraction, and metadata probing.
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/v1/convert/media |
Convert a video or audio file |
GET |
/v1/convert/media |
Stream a converted media file from a URL source |
POST |
/v1/convert/video-thumbnail |
Extract a frame from a video as an image |
POST |
/v1/convert/media-info |
Probe a media file for metadata |
GET |
/v1/convert/supported-media-formats |
List supported conversion pairs |
Python SDK Examples¶
Convert MP4 to WebM¶
Pass a public URL of the source file. Small files complete synchronously; large files return a job ID for async polling.
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
result = cv.media(
url="https://toolkitapi.io/videos/clip.mp4",
source_format="mp4",
target_format="webm",
)
# Small file — result contains the download URL directly
if result.get("status") == "completed":
print(result["file_url"])
# Large file — poll the job
elif "job_id" in result:
final = cv.wait_for_job(result["job_id"])
print(final["file_url"])
Convert with wait_for_job helper¶
wait_for_job polls until the job completes or raises ToolkitAPIError on failure or timeout.
from toolkitapi import Convert, ToolkitAPIError
cv = Convert(api_key="tk_...", timeout=60.0)
response = cv.media(
url="https://toolkitapi.io/videos/webinar.mov",
source_format="mov",
target_format="mp4",
)
if "job_id" in response:
try:
result = cv.wait_for_job(response["job_id"], timeout=300.0)
print(f"Download: {result['file_url']}")
except ToolkitAPIError as e:
print(f"Conversion failed: {e}")
else:
print(f"Download: {response['file_url']}")
Convert audio format¶
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
result = cv.media(
url="https://toolkitapi.io/audio/podcast.wav",
source_format="wav",
target_format="mp3",
)
if "job_id" in result:
result = cv.wait_for_job(result["job_id"])
print(result["file_url"])
Stream converted media to disk¶
Use media_file() to stream the converted file directly to disk. This always completes synchronously.
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
path = cv.media_file(
url="https://toolkitapi.io/videos/short-clip.mp4",
source_format="mp4",
target_format="gif",
output_path="clip.gif",
)
print(f"Saved to {path}")
Extract a video thumbnail¶
Pull a specific frame from a video as a PNG or JPEG image.
from toolkitapi import Convert
import base64
from pathlib import Path
cv = Convert(api_key="tk_...")
result = cv.video_thumbnail(
url="https://toolkitapi.io/videos/presentation.mp4",
timestamp="00:00:05",
format="png",
)
# result["image"] is base64-encoded
Path("thumbnail.png").write_bytes(base64.b64decode(result["image"]))
print(f"Resolution: {result['width']}x{result['height']}")
Probe media metadata¶
Get duration, codec, resolution, bitrate, and stream details before converting.
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
info = cv.media_info(url="https://toolkitapi.io/videos/clip.mp4")
print(f"Duration: {info['duration']:.1f}s")
print(f"Resolution: {info.get('width')}x{info.get('height')}")
print(f"Video codec: {info.get('video_codec')}")
print(f"Audio codec: {info.get('audio_codec')}")
print(f"Bitrate: {info.get('bitrate')} bps")
List supported formats¶
from toolkitapi import Convert
cv = Convert(api_key="tk_...")
formats = cv.supported_media_formats()
print("Video conversions:")
for pair in formats.get("video", []):
print(f" {pair['from']} → {pair['to']}")
print("\nAudio conversions:")
for pair in formats.get("audio", []):
print(f" {pair['from']} → {pair['to']}")
Request Parameters — POST /v1/convert/media¶
| Parameter | Type | Description |
|---|---|---|
url |
string | Public URL of the source media file |
source_format |
string | Source format e.g. mp4, mov, wav, flac |
target_format |
string | Target format e.g. webm, mp3, gif, ogg |
Request Parameters — POST /v1/convert/video-thumbnail¶
| Parameter | Type | Description |
|---|---|---|
url |
string | Public URL of the source video |
timestamp |
string | Frame timestamp: HH:MM:SS or seconds (default 00:00:01) |
format |
string | Output image format: png or jpeg |
Request Parameters — POST /v1/convert/media-info¶
| Parameter | Type | Description |
|---|---|---|
url |
string | Public URL of the media file to probe |
Response Fields — Conversion¶
| Field | Type | Description |
|---|---|---|
status |
string | completed or processing |
file_url |
string | Presigned URL to download the converted file |
job_id |
string | Async job ID (present when status is processing) |
poll_url |
string | URL to poll for job status |
source_format |
string | Source format used |
target_format |
string | Target format used |
Response Fields — Thumbnail¶
| Field | Type | Description |
|---|---|---|
image |
string | Base64-encoded image |
format |
string | Image format (png or jpeg) |
width |
integer | Frame width in pixels |
height |
integer | Frame height in pixels |
timestamp |
string | Timestamp the frame was extracted from |
Tip
Large media files return HTTP 202 with a job_id. Use cv.wait_for_job(job_id) to block until the conversion finishes, or cv.get_job(job_id) to poll manually. Completed jobs return a file_url pointing to a presigned download link.