SDK y ejemplos de código
Ejemplos de código para integrar la API de FFHub en tu aplicación.
FFHub expone una API REST sencilla. A continuación encontrarás ejemplos de código en los lenguajes más populares para empezar rápidamente.
Node.js / JavaScript
const response = await fetch('https://api.ffhub.io/v1/tasks', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
command: 'ffmpeg -i input.mp4 -c:v libx264 -crf 28 output.mp4'
})
});
const { task_id } = await response.json();
// Consulta el estado hasta que la tarea termine (polling)
const checkStatus = async (taskId) => {
const res = await fetch(`https://api.ffhub.io/v1/tasks/${taskId}`, {
headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
});
return res.json();
};
Python
import requests
response = requests.post(
'https://api.ffhub.io/v1/tasks',
headers={'Authorization': 'Bearer YOUR_API_KEY'},
json={'command': 'ffmpeg -i input.mp4 -c:v libx264 -crf 28 output.mp4'}
)
task_id = response.json()['task_id']
# Consulta el estado de la tarea (polling)
def check_status(task_id):
res = requests.get(
f'https://api.ffhub.io/v1/tasks/{task_id}',
headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
return res.json()
cURL
curl -X POST https://api.ffhub.io/v1/tasks \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"command": "ffmpeg -i input.mp4 -c:v libx264 output.mp4"}'
Consulta el estado de la tarea:
curl https://api.ffhub.io/v1/tasks/TASK_ID \
-H "Authorization: Bearer YOUR_API_KEY"
Callback mediante webhook
En lugar de hacer polling, puedes indicar una URL de webhook para recibir una notificación cuando la tarea finalice:
const response = await fetch('https://api.ffhub.io/v1/tasks', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
command: 'ffmpeg -i input.mp4 -c:v libx264 -crf 28 output.mp4',
webhook: 'https://your-server.com/api/ffhub-callback'
})
});
Cuando la tarea finaliza, FFHub envía una solicitud POST a tu URL de webhook con el resultado:
{
"event_id": "task_abc123",
"type": "task.succeeded",
"created_at": "2026-09-17T12:00:00Z",
"data": {
"task_id": "task_abc123",
"status": "succeeded",
"progress": 100,
"outputs": [
{
"filename": "output.mp4",
"url": "https://storage.ffhub.io/outputs/task_abc123/output.mp4",
"size": 10485760
}
],
"error": "",
"created_at": "2026-09-17T11:59:00Z",
"finished_at": "2026-09-17T12:00:00Z"
}
}
Las tareas fallidas envían la misma estructura con "type": "task.failed" y el motivo en data.error.
Flujo de subida de archivos
Si el archivo de origen es local (no una URL pública), súbelo primero a FFHub Storage: firma, PUT y luego pasa la URL pública devuelta a tu comando de FFmpeg. El archivo va directo al almacenamiento y nunca pasa por nuestra API.
Paso 1: Pide una URL firmada
const signRes = await fetch('https://api.ffhub.io/v1/uploads/sign', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: 'input.mp4',
size: file.size,
content_type: 'video/mp4'
})
});
const { upload_url, public_url } = await signRes.json();
Paso 2: Sube el archivo directamente al almacenamiento
const putRes = await fetch(upload_url, {
method: 'PUT',
headers: { 'Content-Type': 'video/mp4' },
body: file
});
if (!putRes.ok) throw new Error(`Upload failed: ${putRes.status}`);
El Content-Type debe coincidir con el content_type que firmaste; si no, el almacenamiento rechaza la firma. La URL firmada caduca a los 15 minutos.
Paso 3: Usa la URL pública en tu comando de FFmpeg
const taskRes = await fetch('https://api.ffhub.io/v1/tasks', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
command: `ffmpeg -i ${public_url} -c:v libx264 -crf 28 output.mp4`
})
});