Docs · Compress a video
Guides · Compress a video

Compress a video

Re-encode the video with a higher -crf and a slower -preset. The response gives the new file’s size, so you can see what you saved.

The request

Request
curl https://media.logicboostkit.com/ffmpeg/process \
  -H "Authorization: Basic $MEDIA_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "task": {
      "inputs": [
        {
          "file_path": "dir_pi23jgy1yxlmigi873bz/source.mp4"
        }
      ],
      "outputs": [
        {
          "file": "compressed.mp4",
          "options": [
            "-c:v",
            "libx264",
            "-preset",
            "slow",
            "-crf",
            "28",
            "-c:a",
            "aac",
            "-b:a",
            "96k",
            "-movflags",
            "+faststart"
          ]
        }
      ]
    }
  }'
Response
HTTP/1.1 200 OK
X-Request-Id: job_0mv6hnzdy93wuugau1rys4cn

{
  "ok": true,
  "result": [
    {
      "file_name": "compressed.mp4",
      "size_bytes": 375809638,
      "download_url": "https://…"
    }
  ],
  "usage": {
    "time_sec": 42,
    "input_size_gb": 1.2,
    "output_size_gb": 0.35,
    "gb_sec": 65.099999992
  },
  "request_id": "job_0mv6hnzdy93wuugau1rys4cn",
  "amount_usd": 0.867132
}

The input is a file you uploaded (POST /file). The full reference is POST /ffmpeg/process.

The options, explained

What each option does
-c:v libx264Encode the video as H.264.
-preset slowSpend more time looking for savings: a smaller file at the same quality than the default preset.
-crf 28Constant quality, at a higher value than the default 23: a smaller file, a little softer. Each step of 6 roughly halves or doubles the size.
-c:a aac -b:a 96kAAC audio at 96 kbit/s, plenty for speech.
-movflags +faststartPlayback can begin before the download ends.

Variations

Smaller still: lower the resolution

Scaling 1080p down to 720p cuts the size further.

In the output: "options": ["-vf", "scale=-2:720", "-c:v", "libx264", "-preset", "slow", "-crf", "28", "-c:a", "aac", "-b:a", "96k"]

A target bitrate instead of a quality

For a size you can predict: bitrate × duration.

In the output: "options": ["-c:v", "libx264", "-b:v", "1500k", "-maxrate", "1500k", "-bufsize", "3000k", "-c:a", "aac", "-b:a", "96k"]

H.265

About half the size of H.264 at the same quality, at the cost of a longer job.

In the output: "options": ["-c:v", "libx265", "-crf", "30", "-tag:v", "hvc1", "-c:a", "aac", "-b:a", "96k"]

What it costs

A 1.2 GB talk recording compressed to 0.35 GB in 42 seconds: (1.2 GB + 0.35 GB) × 42 s = 65.100 GB-seconds, which is USD 0.8671 at USD 0.01332 per GB-second.

The seconds are an example; every response reports the job’s own. Failed jobs are not charged. See Pricing.