is an option for Export and CreateArchive that specifies the amount of compression to use when compressing data.
CompressionLevel
is an option for Export and CreateArchive that specifies the amount of compression to use when compressing data.
Details
- Typical settings for CompressionLevel include:
-
Automatic automatically chosen val a number between 0 (less compression) and 1 (more compression) - Using CompressionLevelAutomatic, typically a balance between speed and data size is chosen.
Examples
open all close allBasic Examples (1)
Export an audio object to an MP3 file with default compression:
audio = AudioGenerator["Sin"]FileSize@Export["file.mp3", audio]FileSize@Export["file.mp3", audio, CompressionLevel -> 1]FileSize@Export["file.mp3", audio, CompressionLevel -> 0]Scope (5)
Image Compression (2)
Export an image object to a JPEG file with default compression:
image = ExampleData[{"TestImage", "Apples"}];FileSize@Export["file.jpeg", image]FileSize@Export["file.jpeg", image, CompressionLevel -> 1]FileSize@Export["file.jpeg", image, CompressionLevel -> 0]Check file size before compression:
FileByteCount[file = FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ExampleData", "coneflower.jpg"}]]Some compression is performed by default:
FileByteCount[archive = CreateArchive[file]]Delete the resulting archives:
DeleteFile[archive]Specify to use no compression:
FileByteCount[archive = CreateArchive[file, CompressionLevel -> 0]]Delete the resulting archives:
DeleteFile[archive]Specify to use maximal compression:
FileByteCount[archive = CreateArchive[file, CompressionLevel -> 1]]Delete the resulting archives:
DeleteFile[archive]Audio Compression (1)
Export an audio object to an MP3 file with default compression:
audio = AudioGenerator["Sin"]FileSize@Export["file.mp3", audio]FileSize@Export["file.mp3", audio, CompressionLevel -> 1]FileSize@Export["file.mp3", audio, CompressionLevel -> 0]Video Compression (2)
Use the CompressionLevel option to control the file size of a video operation:
v = VideoGenerator[ResourceData["Sample Image: White Dog on a Beach"], 5];a = ExampleData[{"Audio", "PianoScale"}];i = ResourceData["Sample Image: White Dog on a Beach"];
videos = Table[VideoCombine[{v, a}, CompressionLevel -> c], {c, 0, 1, .2}]Compare file sizes using different compression levels:
FileSize[Information[#, "ResourcePath"]]& /@ videosGenerate a video using default compression:
v = Video["ExampleData/Caminandes.mp4"];FileSize[FindFile[Information[v, "ResourcePath"]]]FileSize[FindFile[Information[VideoTrim[v, 10], "ResourcePath"]]]FileSize[Information[VideoTrim[v, 10, CompressionLevel -> 1], "ResourcePath"]]The choice of encoders affects the amount by which a file can be compressed:
Information[v, "VideoTracks"]FileSize[Information[VideoTrim[v, 10, VideoEncoding -> "LIBVPX-VP9"], "ResourcePath"]]FileSize[Information[VideoTrim[v, 10, VideoEncoding -> "LIBVPX-VP9", CompressionLevel -> 1], "ResourcePath"]]Related Guides
History
Text
Wolfram Research (2020), CompressionLevel, Wolfram Language function, https://reference.wolfram.com/language/ref/CompressionLevel.html.
CMS
Wolfram Language. 2020. "CompressionLevel." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CompressionLevel.html.
APA
Wolfram Language. (2020). CompressionLevel. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CompressionLevel.html
BibTeX
@misc{reference.wolfram_2026_compressionlevel, author="Wolfram Research", title="{CompressionLevel}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/CompressionLevel.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_compressionlevel, organization={Wolfram Research}, title={CompressionLevel}, year={2020}, url={https://reference.wolfram.com/language/ref/CompressionLevel.html}, note=[Accessed: 15-June-2026]}