Skip to content

Instantly share code, notes, and snippets.

@Rudxain
Last active February 25, 2023 02:59
Show Gist options
  • Save Rudxain/af48d29203141b7c45e2794a1148ddb2 to your computer and use it in GitHub Desktop.
Save Rudxain/af48d29203141b7c45e2794a1148ddb2 to your computer and use it in GitHub Desktop.
Calculates the byte-size of a video as if it wasn't compressed by a codec
from typing import Final
BYTES_PER_PIXEL: Final = 3 # 24bit color, 8 per channel
def decoded_video_size(*, w: Final[int], h: Final[int], s: Final[float], fps: Final[float]):
pixels_per_frame: Final = w * h # px/px^2 = 1/px = px^-1
total_frames: Final = fps * s # px^2/s * s = px^2
total_pixels: Final = pixels_per_frame * total_frames # px^-1 * px^2 = px^2 / px^1 = px
total_bytes: Final = total_pixels * BYTES_PER_PIXEL # px * B/px = B
return total_bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment