SDK & Codebeispiele

Codebeispiele zur Integration der FFHub API in Ihre Anwendung.

FFHub provides a simple REST API. Here are code examples in popular languages to help you get started.

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();

// 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 input.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 input.mp4 -c:v libx264 output.mp4"}'

Check task status:

curl https://api.ffhub.io/v1/tasks/TASK_ID \
  -H "Authorization: Bearer YOUR_API_KEY"

Webhook Callback

Instead of polling, you can provide a webhook URL to receive a notification when the task completes:

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'
  })
});

When the task completes, FFHub sends a POST request to your webhook URL with the task result:

{
  "task_id": "task_abc123",
  "status": "completed",
  "outputs": [
    {
      "filename": "output.mp4",
      "url": "https://storage.ffhub.io/outputs/task_abc123/output.mp4",
      "size": 10485760
    }
  ]
}

File Upload Flow

If your source file is local (not a public URL), upload it first, then use the returned URL in your FFmpeg command:

Step 1: Upload the file

const formData = new FormData();
formData.append('file', fileBlob, 'input.mp4');

const uploadRes = await fetch('https://api.ffhub.io/v1/files', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
  body: formData
});
const { url } = await uploadRes.json();

Step 2: Use the URL in your FFmpeg command

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 ${url} -c:v libx264 -crf 28 output.mp4`
  })
});