ORB-HD / deface

Video anonymization by face detection
MIT License
619 stars 86 forks source link

File size increase #15

Open Tralapo opened 3 years ago

Tralapo commented 3 years ago

I've been experimenting with this tool, it works amazing. I'm testing deface to run on jpg images downloaded from a webcam.

I noticed quite a file size increase on these jpg's: Original: 435kb Deface: 610kb - without any faces in the picture

Although it doesn't look like much, I'm planning on using this on quite a scale, which makes the total increased data storage quite large and I would like to avoid that where possible.

Any ideas what might increase the file size, even without faces on them?

mdraw commented 3 years ago

To save the resulting image it has to be completely re-encoded, so both size changes and a slight drop in image quality can be expected.

The relevant code line for saving anonymization results to new images is here: https://github.com/ORB-HD/deface/blob/f668068b1ac4598f91dc9ceacfbf86d2a2f1d40e/deface/deface.py#L183

imsave() is an alias to imwrite, which is documented at https://imageio.readthedocs.io/en/stable/userapi.html#imageio.imwrite. Here you see that you can pass image format-specific options through the **kwargs, e.g. for .jpg see here: https://imageio.readthedocs.io/en/stable/format_jpeg-pil.html#parameters-for-saving

For decreasing the output file sizes, I would try lowering the quality setting to something lower than 75.

Can you change the line referenced above to something like

imageio.imwrite(opath, frame, optimize=True, quality=50)

and report if it works?

We can also make this configurable through a command line flag similar to the --ffmpeg-config option, which already exists to control video output codec options.

Tralapo commented 3 years ago

Sorry, I see I forgot to reply. For now I decided not to go ahead with this package. Although it would be great to make it more easily configurable, as the file size difference is quite big.

frankenstein91 commented 1 year ago

@mdraw maybe a option to run the images through https://github.com/tjko/jpegoptim or http://optipng.sourceforge.net/ would be great.