SDK & Code-Beispiele
Code-Beispiele zur Integration der FFHub API in deine Anwendung.
FFHub stellt eine REST API bereit. Hier sind Beispiele in gängigen Sprachen für den Einstieg.
Jede -i-Eingabe muss eine öffentliche http/https-URL sein — die API kann keine Dateien auf deinem Rechner lesen. Liegt die Quelldatei lokal, lade sie zuerst über den Abschnitt Datei-Upload am Ende dieser Seite hoch.
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 https://storage.ffhub.io/sample.mp4 -c:v libx264 -crf 28 output.mp4'
})
});
const { task_id } = await response.json();
// Poll for completion
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 https://storage.ffhub.io/sample.mp4 -c:v libx264 -crf 28 output.mp4'}
)
task_id = response.json()['task_id']
# Poll for completion
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 https://storage.ffhub.io/sample.mp4 -c:v libx264 output.mp4"}'
Status prüfen:
curl https://api.ffhub.io/v1/tasks/TASK_ID \
-H "Authorization: Bearer YOUR_API_KEY"
Webhook Callback
Statt zu pollen, kannst du eine webhook-URL angeben, an die FFHub bei Abschluss eine Benachrichtigung sendet:
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 https://storage.ffhub.io/sample.mp4 -c:v libx264 -crf 28 output.mp4',
webhook: 'https://your-server.com/api/ffhub-callback'
})
});
Bei Abschluss sendet FFHub einen POST-Request an deine Webhook-URL mit dem Ergebnis:
{
"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"
}
}
Bei fehlgeschlagenen Tasks ist die Struktur identisch, mit "type": "task.failed" und dem Grund in data.error.
Datei-Upload
Liegt die Quelldatei lokal (keine öffentliche URL), lade sie zuerst in FFHub Storage: signieren, PUT, dann die zurückgegebene öffentliche URL im FFmpeg-Befehl verwenden. Die Datei geht direkt in den Storage und läuft nie über unsere API.
Schritt 1: Signierte URL anfordern
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();
Schritt 2: Datei direkt in den Storage PUTten
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}`);
Der Content-Type muss exakt dem content_type aus Schritt 1 entsprechen, sonst lehnt der Storage die Signatur ab. Die signierte URL ist 15 Minuten gültig.
Schritt 3: Öffentliche URL im FFmpeg-Befehl verwenden
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`
})
});