TD;DR: To make your project smaller, we use lossy compression to compress specific audio and visual portions.
Have you ever experienced a sluggish scratch project load while playing? Too often it is because of massive project assets. We reduce project size by lossy compression to streamline the loading process for your project.
Example
==>
What is included in the scratch project?
A typical scratch project includes files like these:
We classify these files into two categories:
- Code: all in
project.json
- Assets: the rest, excluding
project.json
, e.g audio, images
Usually, the size of the assets dwarfs that of the code file and contains more information than is needed. We merely compress assets by lossy compression to decrease project size.
What is lossy compression?
Lossy compression algorithms are techniques that reduce file size by discarding the less important information. Please refer to Lossy compression for more details.
Audio
The amount of audio data is described by the bitrate. A higher bitrate generally means better audio quality and a bigger file size that contains more information than the ears can distinguish. Variable bitrate and constant bitrate are the two most popular methods for encoding audio.
Variable Bitrate (VBR)
Variable bitrate refers to data being transmitted at a variable rate. It allows the bitrate of an audio file to dynamically increase or decrease within a target range. Please refer to variable bitrate for more details.
Constant Bitrate (CBR)
Constant bitrate, which is commonly abbreviated as “CBR,” refers to transmitting data at a constant rate. For encoding, this refers to an encoder outputting data at a constant rate. Please refer to constant bitrate for more details.
Conclusion
VBR
- Smaller file sizes.
- More efficient use of storage space.
- Minimal reduction in quality.
CBR
- Fixed quality.
- Guaranteed higher quality files.
- Quicker encoding.
- Wider compatibility.
In order to reduce file size, we encode audio by VBR.
Image
We use two techniques to compress images.
Chroma subsampling
Chroma subsampling is a type of compression that reduces the color information in a signal in favor of luminance data in order to reduce storage without significantly affecting image quality. Please refer to chroma subsampling for more details.
Fast Fourier Transform
A fast Fourier transform algorithm quickly computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IDFT). It deconstructs an image to its frequency domain. With that, we can remove insignificant frequencies and then reconstruct the image with fewer frequencies. Please refer to fast fourier transform for more details.
Usage
In the Discord channel named compression
, the syntax for running Compression is as follows:
/compress [path]
All supported paths are:
- Shared scratch path, e.g
/compress
https://scratch.mit.edu/projects/
123456789