Okay, so I am attempting to compress an image file as much as possible for storage (NOTE, before being able to view the file I would un-compress it, the compressed file does not need to be usable, it just needs to be able to be un-compressed) I would like to do this in python, and I have the code as follows:
import bz2
from shutil import copyfileobj
x = 0
while True:
while x == 0:
with open("START.JPG", 'rb') as input:
with bz2.BZ2File("END.JPG", 'wb', compresslevel=9) as output:
copyfileobj(input, output)
print ("STAGE ONE COMPLETE")
x = 1
while x == 1:
with open("END.JPG", 'rb') as input:
with bz2.BZ2File("FINAL.JPG", 'wb', compresslevel=9) as output1:
copyfileobj(input, output1)
print ("STAGE TWO COMPLETE")
x = 2
So far it does compress the image down, but only by about 1/3 of a MB, I thought by compressing the compressed file I could possibly compress it farther, however when I do this the FINAL.JPG file is larger than my first compressed file. So my question is: What is the best way to compress a file (I know different file types need slightly different compression, and my end goal is to be compressing MP3 audio files), and why is it that my compressed file becomes larger when I compress it a second time?, Also how small could I make one of these files before it becomes un-able to un-compress?
Thank you in advance for all the help I'm sure I will get!