Skip to content

Commit

Permalink
Tweek media chunk size and improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
phlmn committed Jul 26, 2023
1 parent 03d9724 commit ad1a3dc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions backend/transcribee_backend/media_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ def is_safe_path(basedir: Path, path: Path):
return basedir == Path(os.path.commonpath((basedir, matchpath)))


# good for server memory, good for player performance on slow connections
MAX_CHUNK_SIZE = 1024 * 1024
# 512 KB seems to be not too small and makes the player start playing pretty quickly
# even on slow connections
MAX_CHUNK_SIZE = 512 * 1024


def serve_media(
Expand All @@ -145,6 +146,9 @@ def serve_media(
filesize = path.stat().st_size
start = int(start)
end = min(int(end), filesize - 1) if end else filesize - 1

# prevent loading large files to server memory and prevent the player from
# waiting for the entire file to download before starting to play
end = min(int(end), start + MAX_CHUNK_SIZE)

with open(path, "rb") as f:
Expand Down

0 comments on commit ad1a3dc

Please sign in to comment.