Table of Contents
- cURL Examples
- Authentication
- Set your API token as an environment variable
- Basic Examples
- Create a Conversion Job
- Basic video conversion using CDN input URL
- Check Job Status
- Get job status
- Get Account Information
- Check account details and credit balance
- URL Types and Warnings
- HTTP URL (will generate security warning but still process)
- Multiple cloud storage providers
- Advanced Examples
- Image Conversion with Options
- Convert image with specific dimensions and quality
- Audio Conversion
- Convert audio file
- Video Conversion with Custom Settings
- High-quality video conversion with custom settings
- Thumbnail Extraction
- Extract a single thumbnail at 50% of video duration
- Extract thumbnails at specific timestamps
- Extract thumbnails using AI scene detection
- Generate a single image with multiple thumbnails in a grid
- Get thumbnail job status and details
- List recent thumbnail jobs
- Cancel a pending or processing thumbnail job
- Error Handling
- Common Error Responses
- Invalid input format
- Robust Error Handling Script
- robust_conversion.sh - Convert with comprehensive error handling
- Usage
- Batch Processing
- Batch Conversion Script
- batch_convert.sh - Process multiple files
- Example manifest.csv:
- input_url,output_url,job_type,input_format,output_format,input_size_bytes
- https://bucket.s3.amazonaws.com/video1.mp4?...,https://bucket.s3.amazonaws.com/video1.webm?...,video,mp4,webm,52428800
- https://bucket.s3.amazonaws.com/image1.jpg?...,https://bucket.s3.amazonaws.com/image1.webp?...,image,jpg,webp,2048000
- API Exploration & Testing
- Get Supported Formats
- Get list of supported input/output formats
- List Recent Jobs
- Get recent conversion jobs
- Usage Statistics
- Get current month usage
- Webhook Testing
- Test Webhook Endpoint
- Test webhook delivery
- Verify Webhook Signature
- verify_webhook.sh
- Test signature verification
- Environment Setup
- Configuration Script
- setup_mediaconvert.sh - Environment setup script
- Performance and Monitoring
- Job Monitoring Script
- monitor_jobs.sh - Monitor multiple jobs
- Usage: monitor_multiple_jobs job1 job2 job3
- Next Steps
- Support
cURL Examples
Direct API usage examples using cURL for quick testing, scripting, and integration without SDKs. Perfect for debugging, shell scripts, and understanding the raw API.
Authentication
All MediaConvert.io API requests require authentication using an API token in the Authorization header:
# Set your API token as an environment variable
export MEDIACONVERT_API_TOKEN="your_api_token_here"
export MEDIACONVERT_BASE_URL="https://mediaconvert.io/api/v1"
Basic Examples
Create a Conversion Job
# Basic video conversion using CDN input URL
curl -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"job_type": "video",
"input_url": "https://cdn.example.com/videos/input.mp4",
"output_url": "https://bucket.s3.amazonaws.com/output.webm?X-Amz-Algorithm=...",
"input_format": "mp4",
"output_format": "webm",
"input_size_bytes": 52428800,
"webhook_url": "https://your-app.com/webhooks/mediaconvert"
}'
Response:
json
{
"id": "job_abc123xyz",
"status": "pending",
"job_type": "video",
"input_format": "mp4",
"output_format": "webm",
"progress_percentage": 0,
"estimated_cost_micros": 157500,
"estimated_cost_cents": 16,
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z"
}
Check Job Status
# Get job status
curl -X GET "$MEDIACONVERT_BASE_URL/conversion_jobs/job_abc123xyz" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN"
Response:
json
{
"id": "job_abc123xyz",
"status": "processing",
"progress_percentage": 45,
"estimated_cost_micros": 157500,
"processing_time_seconds": 23,
"worker_id": "worker_def456",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:32:45Z"
}
Get Account Information
# Check account details and credit balance
curl -X GET "$MEDIACONVERT_BASE_URL/account" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN"
Response:
json
{
"id": "acc_789xyz",
"email": "user@example.com",
"tier": "starter",
"credits_balance_micros": 5000000,
"credits_balance_cents": 500,
"max_concurrent_jobs": 3,
"created_at": "2024-01-01T00:00:00Z"
}
URL Types and Warnings
MediaConvert.io supports various URL protocols. Here are examples showing different types and the warnings you might receive:
# HTTP URL (will generate security warning but still process)
curl -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"job_type": "video",
"input_url": "http://files.example.com/video.mp4",
"output_url": "https://bucket.s3.amazonaws.com/output.mp4?signature=...",
"input_format": "mp4",
"output_format": "mp4"
}'
Response with warnings:
json
{
"success": true,
"data": {
"id": "job_abc123",
"status": "pending",
"metadata": {
"warnings": [
"Input URL uses non-secure protocol 'http'. Consider using HTTPS for better security."
]
}
},
"validation_warnings": [
"URL validation: Input URL uses non-secure protocol"
]
}
# Multiple cloud storage providers
curl -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"job_type": "video",
"input_url": "https://storage.googleapis.com/my-bucket/input.mov",
"output_url": "https://myaccount.blob.core.windows.net/container/output.mp4?sas=token",
"input_format": "mov",
"output_format": "mp4"
}'
Advanced Examples
Image Conversion with Options
# Convert image with specific dimensions and quality
curl -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"job_type": "image",
"input_url": "https://bucket.s3.amazonaws.com/photo.jpg?...",
"output_url": "https://bucket.s3.amazonaws.com/photo.webp?...",
"input_format": "jpg",
"output_format": "webp",
"input_size_bytes": 2048000,
"options": {
"width": 800,
"height": 600,
"quality": 85,
"maintain_aspect_ratio": true
}
}'
Audio Conversion
# Convert audio file
curl -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"job_type": "audio",
"input_url": "https://bucket.s3.amazonaws.com/song.wav?...",
"output_url": "https://bucket.s3.amazonaws.com/song.mp3?...",
"input_format": "wav",
"output_format": "mp3",
"input_size_bytes": 45000000,
"options": {
"bitrate": "320k",
"sample_rate": 44100
}
}'
Video Conversion with Custom Settings
# High-quality video conversion with custom settings
curl -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"job_type": "video",
"input_url": "https://bucket.s3.amazonaws.com/video.mov?...",
"output_url": "https://bucket.s3.amazonaws.com/video.mp4?...",
"input_format": "mov",
"output_format": "mp4",
"input_size_bytes": 524288000,
"urgency": "soon",
"options": {
"video_codec": "h264",
"audio_codec": "aac",
"resolution": "1920x1080",
"frame_rate": 30,
"video_bitrate": "4000k",
"audio_bitrate": "192k"
},
"webhook_url": "https://your-app.com/webhooks/conversion"
}'
Thumbnail Extraction
Simple Single Thumbnail
# Extract a single thumbnail at 50% of video duration
curl -X POST "$MEDIACONVERT_BASE_URL/thumbnails" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"thumbnail_job": {
"input_url": "https://bucket.s3.amazonaws.com/video.mp4?X-Amz-Algorithm=...",
"output_url": "https://bucket.s3.amazonaws.com/thumbnails/single.jpg?X-Amz-Algorithm=...",
"input_format": "mp4",
"output_format": "jpg",
"input_size_bytes": 52428800,
"thumbnail_settings": {
"mode": "single",
"timestamp": "50%",
"quality": "high",
"format": "jpg",
"dimensions": {
"width": 1280,
"height": 720,
"maintain_aspect": true
}
}
}
}'
Response:
json
{
"success": true,
"data": {
"id": "thumb_abc123xyz",
"status": "pending",
"input_url": "https://bucket.s3.amazonaws.com/video.mp4?...",
"output_url": "https://bucket.s3.amazonaws.com/thumbnails/single.jpg?...",
"input_format": "mp4",
"output_format": "jpg",
"file_size": "50.0 MB",
"thumbnail_settings": {
"mode": "single",
"timestamp": "50%",
"quality": "high",
"format": "jpg"
},
"billing": {
"estimated_cost": "€0.005",
"estimated_cost_micros": 5000,
"currency": "EUR"
},
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z"
}
}
Multiple Thumbnails at Specific Times
# Extract thumbnails at specific timestamps
curl -X POST "$MEDIACONVERT_BASE_URL/thumbnails" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"thumbnail_job": {
"input_url": "https://bucket.s3.amazonaws.com/video.mp4?X-Amz-Algorithm=...",
"output_url": "https://bucket.s3.amazonaws.com/thumbnails/multiple_%03d.jpg?X-Amz-Algorithm=...",
"input_format": "mp4",
"output_format": "jpg",
"input_size_bytes": 104857600,
"thumbnail_settings": {
"mode": "multiple",
"timestamps": [10, 30, 60, 120, 300],
"quality": "medium",
"format": "jpg",
"count": 5
}
}
}'
Smart Scene Detection Thumbnails
# Extract thumbnails using AI scene detection
curl -X POST "$MEDIACONVERT_BASE_URL/thumbnails" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"thumbnail_job": {
"input_url": "https://bucket.s3.amazonaws.com/video.mp4?X-Amz-Algorithm=...",
"output_url": "https://bucket.s3.amazonaws.com/thumbnails/smart_%03d.jpg?X-Amz-Algorithm=...",
"input_format": "mp4",
"output_format": "jpg",
"input_size_bytes": 209715200,
"thumbnail_settings": {
"mode": "smart",
"count": 8,
"quality": "high",
"format": "jpg",
"scene_detection": {
"enabled": true,
"threshold": 0.3,
"min_interval": 5
}
}
}
}'
Thumbnail Grid Generation
# Generate a single image with multiple thumbnails in a grid
curl -X POST "$MEDIACONVERT_BASE_URL/thumbnails" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"thumbnail_job": {
"input_url": "https://bucket.s3.amazonaws.com/video.mp4?X-Amz-Algorithm=...",
"output_url": "https://bucket.s3.amazonaws.com/thumbnails/grid.jpg?X-Amz-Algorithm=...",
"input_format": "mp4",
"output_format": "jpg",
"input_size_bytes": 157286400,
"thumbnail_settings": {
"mode": "grid",
"quality": "medium",
"format": "jpg",
"grid_mode": {
"enabled": true,
"columns": 4,
"rows": 3,
"spacing": 10
}
}
}
}'
Check Thumbnail Job Status
# Get thumbnail job status and details
curl -X GET "$MEDIACONVERT_BASE_URL/thumbnails/thumb_abc123xyz" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN"
Response:
json
{
"success": true,
"data": {
"id": "thumb_abc123xyz",
"status": "completed",
"input_url": "https://bucket.s3.amazonaws.com/video.mp4?...",
"output_url": "https://bucket.s3.amazonaws.com/thumbnails/single.jpg?...",
"input_format": "mp4",
"output_format": "jpg",
"file_size": "50.0 MB",
"thumbnail_settings": {
"mode": "single",
"timestamp": "50%",
"quality": "high",
"format": "jpg"
},
"billing": {
"estimated_cost": "€0.005",
"actual_cost": "€0.005",
"estimated_cost_micros": 5000,
"actual_cost_micros": 5000,
"currency": "EUR"
},
"thumbnail_info": {
"estimated_output_count": 1,
"estimated_processing_time": "5s",
"optimization_suggestions": []
},
"processing": {
"duration_seconds": 4.2,
"duration_human": "4s",
"started_at": "2024-01-15T10:30:05Z",
"completed_at": "2024-01-15T10:30:09Z",
"worker_id": "worker_thumb_001"
},
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:09Z"
}
}
List Thumbnail Jobs
# List recent thumbnail jobs
curl -X GET "$MEDIACONVERT_BASE_URL/thumbnails?limit=10&offset=0" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN"
Cancel Thumbnail Job
# Cancel a pending or processing thumbnail job
curl -X DELETE "$MEDIACONVERT_BASE_URL/thumbnails/thumb_abc123xyz" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN"
Error Handling
Common Error Responses
Insufficient Credits (402)
curl -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"job_type": "video",
"input_url": "https://bucket.s3.amazonaws.com/large-video.mp4?...",
"output_url": "https://bucket.s3.amazonaws.com/output.webm?...",
"input_format": "mp4",
"output_format": "webm",
"input_size_bytes": 1073741824
}'
Response:
json
{
"error": "insufficient_credits",
"message": "Insufficient account credits for this conversion",
"required_credits_micros": 3150000,
"available_credits_micros": 500000,
"required_credits_cents": 315,
"available_credits_cents": 50
}
Validation Error (400)
# Invalid input format
curl -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"job_type": "video",
"input_url": "https://bucket.s3.amazonaws.com/file.txt?...",
"output_url": "https://bucket.s3.amazonaws.com/output.webm?...",
"input_format": "txt",
"output_format": "webm"
}'
Response:
json
{
"error": "validation_failed",
"message": "Validation failed",
"errors": [
"input_format 'txt' is not supported for job_type 'video'",
"input_size_bytes is required"
]
}
Rate Limiting (429)
Response:
json
{
"error": "rate_limit_exceeded",
"message": "API rate limit exceeded",
"retry_after": 60,
"limit": 100,
"remaining": 0,
"reset_time": "2024-01-15T11:00:00Z"
}
Robust Error Handling Script
#!/bin/bash
# robust_conversion.sh - Convert with comprehensive error handling
MEDIACONVERT_API_TOKEN="${MEDIACONVERT_API_TOKEN}"
MEDIACONVERT_BASE_URL="${MEDIACONVERT_BASE_URL:-https://mediaconvert.io/api/v1}"
convert_with_retry() {
local input_url="$1"
local output_url="$2"
local job_type="$3"
local input_format="$4"
local output_format="$5"
local input_size_bytes="$6"
local max_retries="${7:-3}"
for attempt in $(seq 1 $max_retries); do
echo "Attempt $attempt/$max_retries..."
# Create conversion job
response=$(curl -s -w "\n%{http_code}" -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"job_type\": \"$job_type\",
\"input_url\": \"$input_url\",
\"output_url\": \"$output_url\",
\"input_format\": \"$input_format\",
\"output_format\": \"$output_format\",
\"input_size_bytes\": $input_size_bytes
}")
# Split response and status code
http_code=$(echo "$response" | tail -n1)
json_response=$(echo "$response" | head -n -1)
case $http_code in
201)
# Success
job_id=$(echo "$json_response" | jq -r '.id')
echo "✅ Job created successfully: $job_id"
# Monitor job progress
monitor_job "$job_id"
return 0
;;
400)
# Validation error - don't retry
error_msg=$(echo "$json_response" | jq -r '.message')
errors=$(echo "$json_response" | jq -r '.errors[]' 2>/dev/null | tr '\n' ', ')
echo "❌ Validation failed: $error_msg"
echo "Errors: $errors"
return 1
;;
401)
# Authentication error - don't retry
echo "❌ Authentication failed - check your API token"
return 1
;;
402)
# Insufficient credits - don't retry
required_micros=$(echo "$json_response" | jq -r '.required_credits_micros')
available_micros=$(echo "$json_response" | jq -r '.available_credits_micros')
required_euros=$(echo "scale=6; $required_micros / 1000000" | bc)
available_euros=$(echo "scale=6; $available_micros / 1000000" | bc)
echo "❌ Insufficient credits: need €$required_euros but only have €$available_euros"
return 1
;;
429)
# Rate limited - retry after delay
retry_after=$(echo "$json_response" | jq -r '.retry_after // 60')
if [ $attempt -lt $max_retries ]; then
echo "⏳ Rate limited. Waiting $retry_after seconds..."
sleep $retry_after
continue
else
echo "❌ Rate limited after $max_retries attempts"
return 1
fi
;;
5*)
# Server error - retry with exponential backoff
if [ $attempt -lt $max_retries ]; then
wait_time=$((2 ** attempt))
echo "🔄 Server error (HTTP $http_code). Retrying in $wait_time seconds..."
sleep $wait_time
continue
else
echo "❌ Server error after $max_retries attempts"
return 1
fi
;;
*)
echo "❌ Unknown error (HTTP $http_code): $json_response"
return 1
;;
esac
done
}
monitor_job() {
local job_id="$1"
local timeout="${2:-3600}" # 1 hour default timeout
local start_time=$(date +%s)
echo "📊 Monitoring job $job_id..."
while true; do
# Check timeout
current_time=$(date +%s)
elapsed=$((current_time - start_time))
if [ $elapsed -gt $timeout ]; then
echo "⏰ Job timeout after ${timeout}s"
return 1
fi
# Get job status
response=$(curl -s -w "\n%{http_code}" -X GET "$MEDIACONVERT_BASE_URL/conversion_jobs/$job_id" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN")
http_code=$(echo "$response" | tail -n1)
json_response=$(echo "$response" | head -n -1)
if [ "$http_code" != "200" ]; then
echo "❌ Error checking job status: HTTP $http_code"
return 1
fi
status=$(echo "$json_response" | jq -r '.status')
progress=$(echo "$json_response" | jq -r '.progress_percentage // 0')
case $status in
"completed")
cost_micros=$(echo "$json_response" | jq -r '.cost_micros // 0')
cost_euros=$(echo "scale=6; $cost_micros / 1000000" | bc)
processing_time=$(echo "$json_response" | jq -r '.processing_time_seconds // 0')
echo "✅ Job completed successfully!"
echo "💰 Cost: €$cost_euros"
echo "⏱️ Processing time: ${processing_time}s"
return 0
;;
"failed")
error_message=$(echo "$json_response" | jq -r '.error_message // "Unknown error"')
echo "❌ Job failed: $error_message"
return 1
;;
"cancelled")
echo "🚫 Job was cancelled"
return 1
;;
"processing"|"pending"|"queued")
echo "⏳ Status: $status, Progress: $progress%"
sleep 5
;;
*)
echo "❓ Unknown status: $status"
sleep 5
;;
esac
done
}
# Usage
convert_with_retry \
"https://bucket.s3.amazonaws.com/input.mp4?X-Amz-Algorithm=..." \
"https://bucket.s3.amazonaws.com/output.webm?X-Amz-Algorithm=..." \
"video" \
"mp4" \
"webm" \
52428800 \
3
Batch Processing
Batch Conversion Script
#!/bin/bash
# batch_convert.sh - Process multiple files
batch_convert() {
local manifest_file="$1"
local max_concurrent="${2:-3}"
echo "🚀 Starting batch conversion (max $max_concurrent concurrent jobs)"
# Read manifest file (CSV format: input_url,output_url,job_type,input_format,output_format,input_size_bytes)
declare -a pids=()
declare -a jobs=()
{
read # Skip header
while IFS=, read -r input_url output_url job_type input_format output_format input_size_bytes; do
# Wait if we've hit the concurrent limit
while [ ${#pids[@]} -ge $max_concurrent ]; do
# Check for completed jobs
for i in "${!pids[@]}"; do
if ! kill -0 "${pids[$i]}" 2>/dev/null; then
wait "${pids[$i]}"
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "✅ Job ${jobs[$i]} completed"
else
echo "❌ Job ${jobs[$i]} failed"
fi
unset "pids[$i]"
unset "jobs[$i]"
fi
done
# Rebuild arrays to remove holes
pids=("${pids[@]}")
jobs=("${jobs[@]}")
sleep 1
done
# Start new job
echo "🎬 Starting conversion: $input_format → $output_format"
convert_single "$input_url" "$output_url" "$job_type" "$input_format" "$output_format" "$input_size_bytes" &
local pid=$!
pids+=($pid)
jobs+=("$job_type conversion")
done
} < "$manifest_file"
# Wait for remaining jobs
echo "⏳ Waiting for remaining jobs to complete..."
for pid in "${pids[@]}"; do
if kill -0 "$pid" 2>/dev/null; then
wait "$pid"
fi
done
echo "🏁 Batch conversion completed"
}
convert_single() {
local input_url="$1"
local output_url="$2"
local job_type="$3"
local input_format="$4"
local output_format="$5"
local input_size_bytes="$6"
# Create job
response=$(curl -s -X POST "$MEDIACONVERT_BASE_URL/conversion_jobs" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"job_type\": \"$job_type\",
\"input_url\": \"$input_url\",
\"output_url\": \"$output_url\",
\"input_format\": \"$input_format\",
\"output_format\": \"$output_format\",
\"input_size_bytes\": $input_size_bytes
}")
job_id=$(echo "$response" | jq -r '.id')
if [ "$job_id" = "null" ]; then
echo "❌ Failed to create job: $response"
return 1
fi
# Wait for completion
monitor_job "$job_id"
}
# Example manifest.csv:
# input_url,output_url,job_type,input_format,output_format,input_size_bytes
# https://bucket.s3.amazonaws.com/video1.mp4?...,https://bucket.s3.amazonaws.com/video1.webm?...,video,mp4,webm,52428800
# https://bucket.s3.amazonaws.com/image1.jpg?...,https://bucket.s3.amazonaws.com/image1.webp?...,image,jpg,webp,2048000
batch_convert "manifest.csv" 3
API Exploration & Testing
Get Supported Formats
# Get list of supported input/output formats
curl -X GET "$MEDIACONVERT_BASE_URL/formats" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN"
Response:
json
{
"video": {
"input_formats": ["mp4", "avi", "mov", "mkv", "webm", "flv"],
"output_formats": ["mp4", "webm", "avi", "mov"]
},
"image": {
"input_formats": ["jpg", "jpeg", "png", "gif", "bmp", "tiff"],
"output_formats": ["jpg", "png", "webp", "gif", "bmp"]
},
"audio": {
"input_formats": ["mp3", "wav", "flac", "aac", "ogg"],
"output_formats": ["mp3", "wav", "aac", "ogg"]
}
}
List Recent Jobs
# Get recent conversion jobs
curl -X GET "$MEDIACONVERT_BASE_URL/conversion_jobs?limit=10&status=completed" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN"
Usage Statistics
# Get current month usage
curl -X GET "$MEDIACONVERT_BASE_URL/usage?period=current_month" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN"
Response:
json
{
"period": {
"start": "2024-01-01T00:00:00Z",
"end": "2024-01-31T23:59:59Z"
},
"summary": {
"jobs_count": 47,
"total_mb_processed": 1250.5,
"total_cost_micros": 3750000,
"total_cost_cents": 375,
"average_cost_per_mb_micros": 3000
},
"by_job_type": {
"video": {"count": 25, "mb_processed": 1100.2, "cost_micros": 3300000},
"image": {"count": 20, "mb_processed": 120.1, "cost_micros": 360000},
"audio": {"count": 2, "mb_processed": 30.2, "cost_micros": 90000}
}
}
Webhook Testing
Test Webhook Endpoint
# Test webhook delivery
curl -X POST "https://your-app.com/webhooks/mediaconvert" \
-H "Content-Type: application/json" \
-H "X-MediaConvert-Signature: sha256=test_signature" \
-d '{
"job_id": "job_test123",
"status": "completed",
"progress_percentage": 100,
"cost_micros": 150000,
"processing_time_seconds": 45,
"output_size_bytes": 8192000,
"created_at": "2024-01-15T10:30:00Z",
"completed_at": "2024-01-15T10:31:15Z"
}'
Verify Webhook Signature
#!/bin/bash
# verify_webhook.sh
verify_signature() {
local payload="$1"
local received_signature="$2"
local secret="$3"
# Calculate expected signature
expected=$(echo -n "$payload" | openssl dgst -sha256 -hmac "$secret" | cut -d' ' -f2)
expected_with_prefix="sha256=$expected"
if [ "$received_signature" = "$expected_with_prefix" ]; then
echo "✅ Webhook signature valid"
return 0
else
echo "❌ Webhook signature invalid"
echo "Expected: $expected_with_prefix"
echo "Received: $received_signature"
return 1
fi
}
# Test signature verification
payload='{"job_id":"job_test123","status":"completed"}'
signature="sha256=abc123def456"
secret="your_webhook_secret"
verify_signature "$payload" "$signature" "$secret"
Environment Setup
Configuration Script
#!/bin/bash
# setup_mediaconvert.sh - Environment setup script
setup_environment() {
echo "🔧 Setting up MediaConvert.io environment..."
# Check required tools
for tool in curl jq bc; do
if ! command -v $tool >/dev/null 2>&1; then
echo "❌ Required tool missing: $tool"
echo "Please install: $tool"
exit 1
fi
done
# Set API token
if [ -z "$MEDIACONVERT_API_TOKEN" ]; then
read -p "Enter your MediaConvert.io API token: " -s api_token
echo
export MEDIACONVERT_API_TOKEN="$api_token"
echo "export MEDIACONVERT_API_TOKEN=\"$api_token\"" >> ~/.bashrc
fi
# Set base URL
export MEDIACONVERT_BASE_URL="https://mediaconvert.io/api/v1"
echo "export MEDIACONVERT_BASE_URL=\"$MEDIACONVERT_BASE_URL\"" >> ~/.bashrc
# Test API connection
echo "🔍 Testing API connection..."
response=$(curl -s -w "\n%{http_code}" -X GET "$MEDIACONVERT_BASE_URL/account" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN")
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
json_response=$(echo "$response" | head -n -1)
email=$(echo "$json_response" | jq -r '.email')
balance_micros=$(echo "$json_response" | jq -r '.credits_balance_micros')
balance_euros=$(echo "scale=6; $balance_micros / 1000000" | bc)
echo "✅ API connection successful!"
echo " Account: $email"
echo " Balance: €$balance_euros"
else
echo "❌ API connection failed (HTTP $http_code)"
exit 1
fi
echo "✅ Environment setup completed!"
echo " Reload your shell or run: source ~/.bashrc"
}
setup_environment
Performance and Monitoring
Job Monitoring Script
#!/bin/bash
# monitor_jobs.sh - Monitor multiple jobs
monitor_multiple_jobs() {
local job_ids=("$@")
echo "📊 Monitoring ${#job_ids[@]} jobs..."
while true; do
local active_jobs=0
local completed_jobs=0
local failed_jobs=0
printf "\033[2J\033[H" # Clear screen
echo "MediaConvert.io Job Monitor - $(date)"
echo "================================================"
for job_id in "${job_ids[@]}"; do
response=$(curl -s -X GET "$MEDIACONVERT_BASE_URL/conversion_jobs/$job_id" \
-H "Authorization: Bearer $MEDIACONVERT_API_TOKEN")
status=$(echo "$response" | jq -r '.status')
progress=$(echo "$response" | jq -r '.progress_percentage // 0')
case $status in
"completed")
cost_micros=$(echo "$response" | jq -r '.cost_micros // 0')
cost_euros=$(echo "scale=6; $cost_micros / 1000000" | bc)
echo "✅ $job_id: COMPLETED (€$cost_euros)"
((completed_jobs++))
;;
"failed")
error_msg=$(echo "$response" | jq -r '.error_message // "Unknown error"')
echo "❌ $job_id: FAILED ($error_msg)"
((failed_jobs++))
;;
"processing"|"pending"|"queued")
echo "⏳ $job_id: $status ($progress%)"
((active_jobs++))
;;
*)
echo "❓ $job_id: $status"
((active_jobs++))
;;
esac
done
echo "================================================"
echo "Active: $active_jobs | Completed: $completed_jobs | Failed: $failed_jobs"
if [ $active_jobs -eq 0 ]; then
echo "🏁 All jobs finished!"
break
fi
sleep 5
done
}
# Usage: monitor_multiple_jobs job1 job2 job3
monitor_multiple_jobs "$@"
Next Steps
- Python SDK Guide - Server-side Python integration
- JavaScript SDK Guide - Node.js and browser integration
- Ruby SDK Guide - Ruby/Rails integration
- API Reference - Complete API documentation
Support
- Documentation: docs.mediaconvert.io
- API Status: status.mediaconvert.io
- Email Support: support@mediaconvert.io
- GitHub Issues: github.com/mediaconvert-io/api