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.

5 min readSume
All posts

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.

Smallest file that clears 516 kbps, by length (arithmetic as of 2026-10-08)
LengthFormulaSmallest file
6 s516 x 6 / 8387 kB
15 s516 x 15 / 8967.5 kB
30 s516 x 30 / 81.935 MB
60 s516 x 60 / 83.87 MB
600 s516 x 600 / 838.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_seconds in the result.
  • Re-run the check on the final upload file, not on an earlier step.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume