DEV Community

Adam King
Adam King

Posted on Originally published at pennycompute.com

Burn SRT subtitles into video with one API call

A burned-in caption is drawn onto the picture. It plays in any player, and it survives a later transcode that would drop a sidecar SRT or a subtitle track. Soft subtitles are not what this job writes.

This walkthrough uses PennyCompute's ffmpeg.caption_burn.v1 job. You point the API at a public MP4 and a public SRT or ASS file, submit the job, wait until it succeeds, and download the finished MP4. The same flow is documented on the burn captions guide. Field names and paths below are taken from the public OpenAPI document at https://api.pennycompute.com/openapi.json (buyer API 1.10.2).

What you need

  • A public https link to the source video, up to 1 GB, or an input_url from POST /v1/assets. The renderer fetches it with a plain GET, so keep the link readable until the job has ended.
  • A public https link to the subtitle file, under the same rules. Upload SRT or ASS as text/plain if you host the file through the assets endpoint.
  • A PennyCompute account and a server API key from https://app.pennycompute.com. Send the key as Authorization: Bearer $PENNY_API_KEY on every API call. Uploads to a returned upload_url do not use the key.

A new account starts with $5 in its prepaid balance. Failed, cancelled and expired jobs are not charged.

What a caption-burn job costs

Caption burn is billed as FFmpeg output. Live rates are on https://pennycompute.com/ffmpeg-api-pricing and https://pennycompute.com/pricing: $0.0075 per minute of HD output, $0.00375 for SD and $0.015 for 4K, billed by the second, with a ten-second minimum per output. The rate follows the output's shorter side. Queue time is not charged.

POST /v1/jobs/estimate takes the same service_id and input as a job. It creates no job and reserves nothing. For FFmpeg, price_is_final is false. The completed job is billed for the length of its actual output.

1. Estimate the job

The Idempotency-Key header is required only on POST /v1/jobs. The estimate call does not use it.

export PENNY_API_KEY="$PENNY_API_KEY"
export API=https://api.pennycompute.com

curl -sS -X POST "$API/v1/jobs/estimate" \
  -H "Authorization: Bearer $PENNY_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "service_id": "ffmpeg.caption_burn.v1",
    "input": {
      "input_url": "https://example.com/source.mp4",
      "captions_url": "https://example.com/captions.srt",
      "captions_format": "srt"
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Replace the two example URLs with your own public links, or with input_url values returned by POST /v1/assets.

captions_format is srt or ass. The OpenAPI default is ass, so set srt explicitly when the file is SubRip. SRT is a plain-text cue list (start, end, and the words). ASS can carry styling such as fonts, colours and positioning.

2. Submit the job

POST /v1/jobs requires an Idempotency-Key header of 8 to 128 characters. Repeating the same key with the same body returns the original job and does not create or charge a second one. A different body with the same key is rejected as idempotency_conflict.

curl -sS -X POST "$API/v1/jobs" \
  -H "Authorization: Bearer $PENNY_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: burn-srt-demo-001" \
  -d '{
    "service_id": "ffmpeg.caption_burn.v1",
    "input": {
      "input_url": "https://example.com/source.mp4",
      "captions_url": "https://example.com/captions.srt",
      "captions_format": "srt"
    }
  }'
Enter fullscreen mode Exit fullscreen mode

A new job is created as queued and the response includes its id. Save that id. Optional fields on the same body, if you need them, are max_wait_seconds (default 900, maximum 86400), client_reference, priority and webhook_endpoint_id, as listed on the Specification schema.

3. Poll until the status is final

JOB_ID=your-job-id

curl -sS "$API/v1/jobs/$JOB_ID" \
  -H "Authorization: Bearer $PENNY_API_KEY" \
  -H "Accept: application/json"
Enter fullscreen mode Exit fullscreen mode

status is one of queued, active, cancelling, succeeded, failed, cancelled or expired. Poll until it is one of the last four. queued means the job is waiting for a renderer and occupies no slot. active means a renderer is working on it. Only succeeded is charged. If the job fails, is cancelled, or expires, nothing is charged.

To cancel a queued or running job, POST /v1/jobs/{id}/cancel with an empty JSON object. A cancelled job is not charged.

4. Download the finished MP4

When status is succeeded, request the public output link:

curl -sS "$API/v1/jobs/$JOB_ID/output" \
  -H "Authorization: Bearer $PENNY_API_KEY" \
  -H "Accept: application/json"
Enter fullscreen mode Exit fullscreen mode

The response is {"url": "https://..."}. Fetch that URL with a plain GET; it needs no API key and takes byte ranges. The file is kept for 3 days after the render finishes; after that the link answers 404. If you call this endpoint before the job has succeeded, the API returns output_not_ready.

Optional: upload the video and the captions first

Any public https link works in a job input without an upload. If the files are only on your machine, POST /v1/assets prepares a single-file upload: you send the file's SHA-256 and content type, PUT the bytes to the returned upload_url, and use the returned input_url in the job. Those PUTs need no API key. Uploaded files stop being served 24 hours after their PUT, so submit the job while both links are still readable. Use video/mp4 for the video and text/plain for the subtitle file, as the guide describes.

If something goes wrong

  • 402 insufficient_balance: the prepaid balance does not cover this job. Add funds in the dashboard and submit again with a new idempotency key, or reuse the same key only if you are retrying the same body after a lost response.
  • 409 no_capacity: no renderer can take this service now, or its queue is full; submit again later.
  • expired with failure_code no_capacity: the job waited max_wait_seconds without starting and was not charged. Send it once with a longer wait if you can accept one, instead of resending a short wait in a loop.

OpenAPI: https://api.pennycompute.com/openapi.json. Docs: https://pennycompute.com/docs. Pricing: https://pennycompute.com/pricing. Billing terms: https://pennycompute.com/billing-terms.

Top comments (0)