Python check: is this MP4 over TikTok's 516 kbps? Size and duration
A short Python function turns file bytes and duration_seconds into average kbps and tests TikTok's 516 kbps floor, 500 MB cap and 10-minute limit.

The average bitrate of a file is its size in bytes x 8 / its length in seconds / 1,000. Sume returns duration_seconds in every trim, filter and timeline result and does not expose a bitrate field or accept crf or codec keys, so you compute it yourself. The function below checks the three numbers from TikTok's non-Spark video ad page (read 2026-10-08): at least 516 kbps, at most 500 MB and at most 10 minutes.
The function
It is plain Python with no network call. Pass the byte size of the downloaded file and the duration_seconds from the job result. The 500 MB cap is tested in decimal megabytes; if you want to be careful, test 500 x 1,024 x 1,024 bytes as well.
FLOOR_KBPS = 516
CAP_BYTES = 500 * 1000 * 1000
MAX_SECONDS = 600
def tiktok_check(size_bytes: int, seconds: float) -> dict:
if size_bytes <= 0 or seconds <= 0:
raise ValueError("size and seconds must be positive")
kbps = size_bytes * 8 / seconds / 1000
return {
"kbps": round(kbps, 1),
"bitrate_ok": kbps >= FLOOR_KBPS,
"size_ok": size_bytes <= CAP_BYTES,
"length_ok": seconds <= MAX_SECONDS,
}
print(tiktok_check(1_200_000, 15))
print(tiktok_check(900_000, 15))What it prints
The first call is 1,200,000 x 8 / 15 / 1,000 = 640 kbps, above the floor. The second is 900,000 x 8 / 15 / 1,000 = 480 kbps, below it.
| Length | Formula | Smallest file |
|---|---|---|
| 6 s | 516 x 6 / 8 | 387 kB |
| 15 s | 516 x 15 / 8 | 967.5 kB |
| 30 s | 516 x 30 / 8 | 1.935 MB |
| 60 s | 516 x 60 / 8 | 3.87 MB |
| 600 s | 516 x 600 / 8 | 38.7 MB |
Where the inputs come from
Every Sume job that writes an MP4 gives you the length in its result: duration_seconds for trim, filter and timeline. For the size, download the video_url and read the byte count, or send a HEAD request and read Content-Length. Do not use the size of the source file for a trimmed clip, since a trim creates a new artifact. If you chain trim and then filter, test the last file, because each step produces a new MP4 and the bitrate can differ between them.
Limits of this check
A file's size includes the audio track and the container, so the number is an average for the whole file and not the bitrate of the video stream alone. Treat a result within a few percent of 516 as a fail. The check does not look at the frame size, and TikTok asks for 540x960 at minimum for 9:16, so probe the frame size separately (video inspect returns probe facts).
If a file fails, there is no bitrate switch to turn. Options on Sume are: cut with precision: keyframe so the source encoding is kept, start from a source with more detail, or render a shorter file. Check again after each change.
- Size comes from the download (or a HEAD request), not from Sume's result.
- Length comes from
duration_secondsin the result. - Re-run the check on the final upload file, not on an earlier step.
Sources
Related posts
More in Developers
- Python fallback chain for Sume video models: 404 and 503 only
After the Sora API shutdown, a model chain must not retry everything. This Python function moves on at 404 and 503 and stops on 429, 402, 400, 409.
- Python: find Sume image models that list a ratio like 8:1 or 4:5
A 15-line Python script reads GET /v1/images/models and prints every Sume image model that lists a given aspect ratio, so you stop guessing before a 400.
- Python match on a Sume /v1/videos poll: five statuses, one handler
Python 3.10 structural matching on the poll dict: wait on pending and in_progress, return on completed, raise on failed or cancelled. Runs under asyncio.run.
- Parse Retry-After as seconds or HTTP-date before retrying a Sume 429
A 21-line Python helper that reads retry-after as integer seconds or an HTTP-date, caps the wait, and falls back to exponential delay when the header is absent.
Written by Sume